dispatcher.js 21.3 KB
Newer Older
1
/* eslint-disable func-names, space-before-function-paren, no-var, prefer-arrow-callback, wrap-iife, no-shadow, consistent-return, one-var, one-var-declaration-per-line, camelcase, default-case, no-new, quotes, no-duplicate-case, no-case-declarations, no-fallthrough, max-len */
P
Phil Hughes 已提交
2
import notificationsDropdown from './notifications_dropdown';
P
Phil Hughes 已提交
3 4
import LineHighlighter from './line_highlighter';
import MergeRequest from './merge_request';
5
import Flash from './flash';
D
Douwe Maan 已提交
6
import BlobViewer from './blob/viewer/index';
7
import GfmAutoComplete from './gfm_auto_complete';
8
import Star from './star';
9
import ZenMode from './zen_mode';
10
import PerformanceBar from './performance_bar';
P
Phil Hughes 已提交
11 12
import initNotes from './init_notes';
import initIssuableSidebar from './init_issuable_sidebar';
C
Clement Ho 已提交
13
import { convertPermissionToBoolean } from './lib/utils/common_utils';
14
import GlFieldErrors from './gl_field_errors';
15 16
import Shortcuts from './shortcuts';
import ShortcutsIssuable from './shortcuts_issuable';
17
import Diff from './diff';
F
Filipa Lacerda 已提交
18
import SearchAutocomplete from './search_autocomplete';
19

F
Fatih Acet 已提交
20 21 22 23 24 25
(function() {
  var Dispatcher;

  Dispatcher = (function() {
    function Dispatcher() {
      this.initSearch();
26
      this.initFieldErrors();
F
Fatih Acet 已提交
27 28 29 30
      this.initPageScripts();
    }

    Dispatcher.prototype.initPageScripts = function() {
31
      var path, shortcut_handler;
32
      const page = $('body').attr('data-page');
F
Fatih Acet 已提交
33 34 35
      if (!page) {
        return false;
      }
36

37
      const fail = () => Flash('Error loading dynamic module');
38
      const callDefault = m => m.default();
39

F
Fatih Acet 已提交
40 41
      path = page.split(':');
      shortcut_handler = null;
42

F
Filipa Lacerda 已提交
43
      $('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => {
44
        const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
45
        const enableGFM = convertPermissionToBoolean(el.dataset.supportsAutocomplete);
46 47 48 49 50 51 52 53 54
        gfm.setup($(el), {
          emojis: true,
          members: enableGFM,
          issues: enableGFM,
          milestones: enableGFM,
          mergeRequests: enableGFM,
          labels: enableGFM,
        });
      });
55

F
Fatih Acet 已提交
56
      switch (page) {
57
        case 'sessions:new':
C
Clement Ho 已提交
58 59 60
          import('./pages/sessions/new')
            .then(callDefault)
            .catch(fail);
61
          break;
62
        case 'projects:boards:show':
63
        case 'projects:boards:index':
64 65 66 67
          import('./pages/projects/boards/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
68
          break;
69 70 71 72 73
        case 'projects:environments:metrics':
          import('./pages/projects/environments/metrics')
            .then(callDefault)
            .catch(fail);
          break;
74
        case 'projects:merge_requests:index':
75 76 77 78
          import('./pages/projects/merge_requests/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
79
          break;
S
Simon Knox 已提交
80 81 82 83 84 85
        case 'projects:issues:index':
          import('./pages/projects/issues/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
          break;
F
Fatih Acet 已提交
86
        case 'projects:issues:show':
S
Simon Knox 已提交
87 88 89 90
          import('./pages/projects/issues/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
91
          break;
P
Phil Hughes 已提交
92
        case 'dashboard:milestones:index':
93 94 95
          import('./pages/dashboard/milestones/index')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
96
          break;
F
Fatih Acet 已提交
97
        case 'projects:milestones:show':
98 99 100 101
          import('./pages/projects/milestones/show')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
102
        case 'groups:milestones:show':
103 104 105
          import('./pages/groups/milestones/show')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
106
          break;
107 108 109 110 111
        case 'dashboard:milestones:show':
          import('./pages/dashboard/milestones/show')
            .then(callDefault)
            .catch(fail);
          break;
112
        case 'dashboard:issues':
C
Clement Ho 已提交
113 114 115
          import('./pages/dashboard/issues')
            .then(callDefault)
            .catch(fail);
C
Clement Ho 已提交
116
          break;
117
        case 'dashboard:merge_requests':
118 119 120
          import('./pages/dashboard/merge_requests')
            .then(callDefault)
            .catch(fail);
121
          break;
122
        case 'groups:issues':
S
Simon Knox 已提交
123 124 125 126
          import('./pages/groups/issues')
            .then(callDefault)
            .catch(fail);
          break;
127
        case 'groups:merge_requests':
S
Simon Knox 已提交
128 129 130
          import('./pages/groups/merge_requests')
            .then(callDefault)
            .catch(fail);
131
          break;
F
Fatih Acet 已提交
132
        case 'dashboard:todos:index':
C
Clement Ho 已提交
133 134 135
          import('./pages/dashboard/todos/index')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
136
          break;
137 138 139 140 141
        case 'admin:jobs:index':
          import('./pages/admin/jobs/index')
            .then(callDefault)
            .catch(fail);
          break;
142 143
        case 'dashboard:projects:index':
        case 'dashboard:projects:starred':
C
Clement Ho 已提交
144 145 146
          import('./pages/dashboard/projects')
            .then(callDefault)
            .catch(fail);
147
          break;
148 149 150
        case 'explore:projects:index':
        case 'explore:projects:trending':
        case 'explore:projects:starred':
151
          import('./pages/explore/projects')
J
Jacob Schatz 已提交
152
            .then(callDefault)
J
Jacob Schatz 已提交
153 154
            .catch(fail);
          break;
F
Filipa Lacerda 已提交
155
        case 'explore:groups:index':
156
          import('./pages/explore/groups')
J
Jacob Schatz 已提交
157
            .then(callDefault)
J
Jacob Schatz 已提交
158
            .catch(fail);
F
Filipa Lacerda 已提交
159
          break;
F
Fatih Acet 已提交
160
        case 'projects:milestones:new':
161 162 163 164 165
        case 'projects:milestones:create':
          import('./pages/projects/milestones/new')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
166
        case 'projects:milestones:edit':
167
        case 'projects:milestones:update':
168 169 170
          import('./pages/projects/milestones/edit')
            .then(callDefault)
            .catch(fail);
171
          break;
172
        case 'groups:milestones:new':
173 174 175 176 177
        case 'groups:milestones:create':
          import('./pages/groups/milestones/new')
            .then(callDefault)
            .catch(fail);
          break;
178 179
        case 'groups:milestones:edit':
        case 'groups:milestones:update':
180 181 182
          import('./pages/groups/milestones/edit')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
183 184
          break;
        case 'projects:compare:show':
185 186 187
          import('./pages/projects/compare/show')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
188
          break;
189
        case 'projects:branches:new':
190 191 192 193
          import('./pages/projects/branches/new')
            .then(callDefault)
            .catch(fail);
          break;
194
        case 'projects:branches:create':
195 196 197
          import('./pages/projects/branches/new')
            .then(callDefault)
            .catch(fail);
198
          break;
199
        case 'projects:branches:index':
200 201 202
          import('./pages/projects/branches/index')
            .then(callDefault)
            .catch(fail);
203
          break;
F
Fatih Acet 已提交
204
        case 'projects:issues:new':
S
Simon Knox 已提交
205 206 207 208 209
          import('./pages/projects/issues/new')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
          break;
F
Fatih Acet 已提交
210
        case 'projects:issues:edit':
S
Simon Knox 已提交
211 212 213 214
          import('./pages/projects/issues/edit')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
215
          break;
D
Douwe Maan 已提交
216
        case 'projects:merge_requests:creations:new':
217 218 219
          import('./pages/projects/merge_requests/creations/new')
            .then(callDefault)
            .catch(fail);
D
Douwe Maan 已提交
220
        case 'projects:merge_requests:creations:diffs':
221 222 223 224 225
          import('./pages/projects/merge_requests/creations/diffs')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
          break;
F
Fatih Acet 已提交
226
        case 'projects:merge_requests:edit':
227 228 229 230
          import('./pages/projects/merge_requests/edit')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
231 232
          break;
        case 'projects:tags:new':
233 234 235
          import('./pages/projects/tags/new')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
236
          break;
237
        case 'projects:snippets:show':
J
Jacob Schatz 已提交
238 239 240
          import('./pages/projects/snippets/show')
            .then(callDefault)
            .catch(fail);
241
          break;
242 243
        case 'projects:snippets:new':
        case 'projects:snippets:create':
C
Clement Ho 已提交
244
          import('./pages/projects/snippets/new')
J
Jacob Schatz 已提交
245 246 247
            .then(callDefault)
            .catch(fail);
          break;
C
Clement Ho 已提交
248
        case 'projects:snippets:edit':
249
        case 'projects:snippets:update':
C
Clement Ho 已提交
250
          import('./pages/projects/snippets/edit')
J
Jacob Schatz 已提交
251 252
            .then(callDefault)
            .catch(fail);
253
          break;
254
        case 'snippets:new':
255 256 257 258
          import('./pages/snippets/new')
            .then(callDefault)
            .catch(fail);
          break;
259
        case 'snippets:edit':
260 261 262 263
          import('./pages/snippets/edit')
            .then(callDefault)
            .catch(fail);
          break;
264
        case 'snippets:create':
C
Clement Ho 已提交
265
          import('./pages/snippets/new')
266 267 268
            .then(callDefault)
            .catch(fail);
          break;
269
        case 'snippets:update':
C
Clement Ho 已提交
270
          import('./pages/snippets/edit')
271 272
            .then(callDefault)
            .catch(fail);
273
          break;
F
Fatih Acet 已提交
274
        case 'projects:releases:edit':
C
Clement Ho 已提交
275
          import('./pages/projects/releases/edit')
J
Jacob Schatz 已提交
276 277
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
278 279
          break;
        case 'projects:merge_requests:show':
280
          new Diff();
F
Fatih Acet 已提交
281
          new ZenMode();
282

283 284
          initIssuableSidebar();
          initNotes();
285

286 287 288 289
          const mrShowNode = document.querySelector('.merge-request');
          window.mergeRequest = new MergeRequest({
            action: mrShowNode.dataset.mrAction,
          });
290
          shortcut_handler = new ShortcutsIssuable(true);
F
Fatih Acet 已提交
291 292
          break;
        case 'dashboard:activity':
C
Clement Ho 已提交
293 294 295
          import('./pages/dashboard/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
296 297
          break;
        case 'projects:commit:show':
298 299 300 301
          import('./pages/projects/commit/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
302
          break;
303
        case 'projects:commit:pipelines':
304 305 306
          import('./pages/projects/commit/pipelines')
            .then(callDefault)
            .catch(fail);
307
          break;
308
        case 'projects:activity':
309
          import('./pages/projects/activity')
310 311
            .then(callDefault)
            .catch(fail);
312
          shortcut_handler = true;
313
          break;
314
        case 'projects:commits:show':
315 316 317 318
          import('./pages/projects/commits/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
319 320
          break;
        case 'projects:show':
321 322 323
          import('./pages/projects/show')
            .then(callDefault)
            .catch(fail);
C
Clement Ho 已提交
324
          shortcut_handler = true;
F
Fatih Acet 已提交
325
          break;
326
        case 'projects:edit':
S
Simon Knox 已提交
327 328 329
          import('./pages/projects/edit')
            .then(callDefault)
            .catch(fail);
330
          break;
331
        case 'projects:imports:show':
S
Simon Knox 已提交
332 333 334
          import('./pages/projects/imports/show')
            .then(callDefault)
            .catch(fail);
335
          break;
336
        case 'projects:pipelines:new':
337
        case 'projects:pipelines:create':
338 339 340
          import('./pages/projects/pipelines/new')
            .then(callDefault)
            .catch(fail);
341
          break;
F
Filipa Lacerda 已提交
342
        case 'projects:pipelines:builds':
343
        case 'projects:pipelines:failures':
L
Luke Bennett 已提交
344
        case 'projects:pipelines:show':
345 346 347
          import('./pages/projects/pipelines/builds')
            .then(callDefault)
            .catch(fail);
L
Luke Bennett 已提交
348
          break;
F
Fatih Acet 已提交
349
        case 'groups:activity':
S
Simon Knox 已提交
350 351 352
          import('./pages/groups/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
353 354
          break;
        case 'groups:show':
S
Simon Knox 已提交
355 356 357 358
          import('./pages/groups/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
359 360
          break;
        case 'groups:group_members:index':
S
Simon Knox 已提交
361 362 363
          import('./pages/groups/group_members/index')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
364
          break;
365
        case 'projects:project_members:index':
366 367 368
          import('./pages/projects/project_members/')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
369
          break;
370
        case 'groups:create':
S
Simon Knox 已提交
371 372 373 374 375 376 377 378 379
        case 'groups:new':
          import('./pages/groups/new')
            .then(callDefault)
            .catch(fail);
          break;
        case 'groups:edit':
          import('./pages/groups/edit')
            .then(callDefault)
            .catch(fail);
380
          break;
P
Phil Hughes 已提交
381 382
        case 'admin:groups:create':
        case 'admin:groups:new':
P
Phil Hughes 已提交
383 384 385
          import('./pages/admin/groups/new')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
386
          break;
F
Fatih Acet 已提交
387
        case 'admin:groups:edit':
P
Phil Hughes 已提交
388 389 390
          import('./pages/admin/groups/edit')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
391
          break;
392
        case 'projects:tree:show':
393
          import('./pages/projects/tree/show')
394
            .then(callDefault)
395
            .catch(fail);
396
          shortcut_handler = true;
397
          break;
F
Fatih Acet 已提交
398
        case 'projects:find_file:show':
S
Simon Knox 已提交
399 400 401
          import('./pages/projects/find_file/show')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
402 403
          shortcut_handler = true;
          break;
404
        case 'projects:blob:show':
405 406 407 408
          import('./pages/projects/blob/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
409
          break;
F
Fatih Acet 已提交
410
        case 'projects:blame:show':
411 412 413 414
          import('./pages/projects/blame/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
415
          break;
416
        case 'groups:labels:new':
S
Simon Knox 已提交
417 418 419 420
          import('./pages/groups/labels/new')
            .then(callDefault)
            .catch(fail);
          break;
421
        case 'groups:labels:edit':
S
Simon Knox 已提交
422 423 424
          import('./pages/groups/labels/edit')
            .then(callDefault)
            .catch(fail);
C
Clement Ho 已提交
425
          break;
F
Fatih Acet 已提交
426
        case 'projects:labels:new':
J
Jacob Schatz 已提交
427 428 429 430
          import('./pages/projects/labels/new')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
431
        case 'projects:labels:edit':
C
Clement Ho 已提交
432
          import('./pages/projects/labels/edit')
J
Jacob Schatz 已提交
433 434
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
435
          break;
S
Simon Knox 已提交
436 437 438 439 440
        case 'groups:labels:index':
          import('./pages/groups/labels/index')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
441
        case 'projects:labels:index':
J
Jacob Schatz 已提交
442 443 444 445
          import('./pages/projects/labels/index')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
446
        case 'projects:network:show':
447 448
          // Ensure we don't create a particular shortcut handler here. This is
          // already created, where the network graph is created.
F
Fatih Acet 已提交
449 450 451
          shortcut_handler = true;
          break;
        case 'projects:forks:new':
S
Simon Knox 已提交
452
          import('./pages/projects/forks/new')
J
Jacob Schatz 已提交
453 454
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
455 456
          break;
        case 'projects:artifacts:browse':
457
          import('./pages/projects/artifacts/browse')
458 459
            .then(callDefault)
            .catch(fail);
460
          shortcut_handler = true;
F
Fatih Acet 已提交
461
          break;
462
        case 'projects:artifacts:file':
463
          import('./pages/projects/artifacts/file')
464 465
            .then(callDefault)
            .catch(fail);
466
          shortcut_handler = true;
467
          break;
468
        case 'help:index':
469 470 471
          import('./pages/help')
            .then(callDefault)
            .catch(fail);
472
          break;
F
Fatih Acet 已提交
473
        case 'search:show':
C
Clement Ho 已提交
474 475 476
          import('./pages/search/show')
            .then(callDefault)
            .catch(fail);
477
          break;
D
Douwe Maan 已提交
478
        case 'projects:settings:repository:show':
479 480 481
          import('./pages/projects/settings/repository/show')
            .then(callDefault)
            .catch(fail);
482
          break;
D
Douwe Maan 已提交
483
        case 'projects:settings:ci_cd:show':
484 485 486 487
          import('./pages/projects/settings/ci_cd/show')
            .then(callDefault)
            .catch(fail);
          break;
S
Shinya Maeda 已提交
488
        case 'groups:settings:ci_cd:show':
S
Simon Knox 已提交
489 490 491
          import('./pages/groups/settings/ci_cd/show')
            .then(callDefault)
            .catch(fail);
S
Stan Hu 已提交
492
          break;
493 494
        case 'ci:lints:create':
        case 'ci:lints:show':
C
Clement Ho 已提交
495 496 497
          import('./pages/ci/lints')
            .then(callDefault)
            .catch(fail);
498
          break;
499
        case 'users:show':
C
Clement Ho 已提交
500 501 502
          import('./pages/users/show')
            .then(callDefault)
            .catch(fail);
503
          break;
504
        case 'admin:conversational_development_index:show':
C
Clement Ho 已提交
505 506 507
          import('./pages/admin/conversational_development_index/show')
            .then(callDefault)
            .catch(fail);
508
          break;
D
Douwe Maan 已提交
509
        case 'snippets:show':
C
Clement Ho 已提交
510 511 512
          import('./pages/snippets/show')
            .then(callDefault)
            .catch(fail);
D
Douwe Maan 已提交
513
          break;
514
        case 'import:fogbugz:new_user_map':
C
Clement Ho 已提交
515 516 517
          import('./pages/import/fogbugz/new_user_map')
            .then(callDefault)
            .catch(fail);
518
          break;
519
        case 'profiles:personal_access_tokens:index':
520 521 522 523
          import('./pages/profiles/personal_access_tokens')
            .then(callDefault)
            .catch(fail);
          break;
524
        case 'admin:impersonation_tokens:index':
P
Phil Hughes 已提交
525 526 527
          import('./pages/admin/impersonation_tokens')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
528
          break;
F
Filipa Lacerda 已提交
529
        case 'projects:clusters:show':
530 531
        case 'projects:clusters:update':
        case 'projects:clusters:destroy':
532 533 534
          import('./pages/projects/clusters/show')
            .then(callDefault)
            .catch(fail);
535 536
          break;
        case 'projects:clusters:index':
537 538 539
          import('./pages/projects/clusters/index')
            .then(callDefault)
            .catch(fail);
F
Filipa Lacerda 已提交
540
          break;
F
Fatih Acet 已提交
541
      }
542
      switch (path[0]) {
543
        case 'sessions':
544 545 546 547
          import('./pages/sessions')
            .then(callDefault)
            .catch(fail);
          break;
548
        case 'omniauth_callbacks':
549 550 551 552
          import('./pages/omniauth_callbacks')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
553
        case 'admin':
P
Phil Hughes 已提交
554 555 556
          import('./pages/admin')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
557
          switch (path[1]) {
M
Mike Greiling 已提交
558
            case 'broadcast_messages':
P
Phil Hughes 已提交
559 560 561
              import('./pages/admin/broadcast_messages')
                .then(callDefault)
                .catch(fail);
M
Mike Greiling 已提交
562
              break;
S
Sean McGivern 已提交
563
            case 'cohorts':
P
Phil Hughes 已提交
564 565 566
              import('./pages/admin/cohorts')
                .then(callDefault)
                .catch(fail);
567
              break;
F
Fatih Acet 已提交
568
            case 'groups':
P
Phil Hughes 已提交
569 570
              switch (path[2]) {
                case 'show':
P
Phil Hughes 已提交
571 572 573
                  import('./pages/admin/groups/show')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
574 575
                  break;
              }
F
Fatih Acet 已提交
576 577
              break;
            case 'projects':
P
Phil Hughes 已提交
578 579 580
              import('./pages/admin/projects')
                .then(callDefault)
                .catch(fail);
581 582
              break;
            case 'labels':
583
              switch (path[2]) {
584
                case 'new':
P
Phil Hughes 已提交
585 586 587
                  import('./pages/admin/labels/new')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
588
                  break;
589
                case 'edit':
P
Phil Hughes 已提交
590 591 592
                  import('./pages/admin/labels/edit')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
593
                  break;
594
              }
595
            case 'abuse_reports':
P
Phil Hughes 已提交
596 597 598
              import('./pages/admin/abuse_reports')
                .then(callDefault)
                .catch(fail);
599
              break;
F
Fatih Acet 已提交
600 601 602
          }
          break;
        case 'profiles':
603 604 605
          import('./pages/profiles/index/')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
606 607
          break;
        case 'projects':
608 609 610 611
          import('./pages/projects')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
612 613
          switch (path[1]) {
            case 'compare':
614 615 616
              import('./pages/projects/compare')
                .then(callDefault)
                .catch(fail);
F
Fatih Acet 已提交
617
              break;
618 619 620
            case 'create':
            case 'new':
              import('./pages/projects/new')
J
Jacob Schatz 已提交
621 622
                .then(callDefault)
                .catch(fail);
F
Fatih Acet 已提交
623 624
              break;
            case 'show':
625
              new Star();
P
Phil Hughes 已提交
626
              notificationsDropdown();
F
Fatih Acet 已提交
627 628
              break;
            case 'wikis':
629 630 631 632
              import('./pages/projects/wikis')
                .then(callDefault)
                .catch(fail);
              shortcut_handler = true;
F
Fatih Acet 已提交
633 634 635 636
              break;
            case 'snippets':
              if (path[2] === 'show') {
                new ZenMode();
D
Douwe Maan 已提交
637 638
                new LineHighlighter();
                new BlobViewer();
F
Fatih Acet 已提交
639 640 641
              }
              break;
          }
642
          break;
F
Fatih Acet 已提交
643
      }
644
      // If we haven't installed a custom shortcut handler, install the default one
F
Fatih Acet 已提交
645
      if (!shortcut_handler) {
646
        new Shortcuts();
F
Fatih Acet 已提交
647
      }
648 649 650 651

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
F
Fatih Acet 已提交
652 653 654
    };

    Dispatcher.prototype.initSearch = function() {
655
      // Only when search form is present
F
Fatih Acet 已提交
656
      if ($('.search').length) {
F
Filipa Lacerda 已提交
657
        return new SearchAutocomplete();
F
Fatih Acet 已提交
658 659 660
      }
    };

661
    Dispatcher.prototype.initFieldErrors = function() {
662
      $('.gl-show-field-errors').each((i, form) => {
663
        new GlFieldErrors(form);
664
      });
665 666
    };

F
Fatih Acet 已提交
667 668
    return Dispatcher;
  })();
669

670
  $(window).on('load', function() {
671 672
    new Dispatcher();
  });
673
}).call(window);