dispatcher.js 21.6 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 */
F
Filipa Lacerda 已提交
2
import Milestone from './milestone';
3
import IssuableForm from './issuable_form';
4
import LabelsSelect from './labels_select';
C
Constance Okoghenun 已提交
5
import MilestoneSelect from './milestone_select';
P
Phil Hughes 已提交
6 7
import NotificationsForm from './notifications_form';
import notificationsDropdown from './notifications_dropdown';
P
Phil Hughes 已提交
8 9 10
import LineHighlighter from './line_highlighter';
import MergeRequest from './merge_request';
import Sidebar from './right_sidebar';
11
import IssuableTemplateSelectors from './templates/issuable_template_selectors';
12
import Flash from './flash';
13
import SecretValues from './behaviors/secret_values';
M
Mike Greiling 已提交
14
import UserCallout from './user_callout';
D
Douwe Maan 已提交
15
import BlobViewer from './blob/viewer/index';
16
import GfmAutoComplete from './gfm_auto_complete';
17
import Star from './star';
18
import ZenMode from './zen_mode';
19
import PerformanceBar from './performance_bar';
P
Phil Hughes 已提交
20 21
import initNotes from './init_notes';
import initIssuableSidebar from './init_issuable_sidebar';
22 23
import GlFieldErrors from './gl_field_errors';
import GLForm from './gl_form';
24 25 26
import Shortcuts from './shortcuts';
import ShortcutsNavigation from './shortcuts_navigation';
import ShortcutsIssuable from './shortcuts_issuable';
F
Filipa Lacerda 已提交
27
import U2FAuthenticate from './u2f/authenticate';
28
import Diff from './diff';
F
Filipa Lacerda 已提交
29
import SearchAutocomplete from './search_autocomplete';
30
import Activities from './activities';
31

F
Fatih Acet 已提交
32 33 34 35 36 37
(function() {
  var Dispatcher;

  Dispatcher = (function() {
    function Dispatcher() {
      this.initSearch();
38
      this.initFieldErrors();
F
Fatih Acet 已提交
39 40 41 42
      this.initPageScripts();
    }

    Dispatcher.prototype.initPageScripts = function() {
43
      var path, shortcut_handler;
44
      const page = $('body').attr('data-page');
F
Fatih Acet 已提交
45 46 47
      if (!page) {
        return false;
      }
48

49
      const fail = () => Flash('Error loading dynamic module');
50
      const callDefault = m => m.default();
51

F
Fatih Acet 已提交
52 53
      path = page.split(':');
      shortcut_handler = null;
54

F
Filipa Lacerda 已提交
55
      $('.js-gfm-input:not(.js-vue-textarea)').each((i, el) => {
56
        const gfm = new GfmAutoComplete(gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources);
57
        const enableGFM = convertPermissionToBoolean(el.dataset.supportsAutocomplete);
58 59 60 61 62 63 64 65 66
        gfm.setup($(el), {
          emojis: true,
          members: enableGFM,
          issues: enableGFM,
          milestones: enableGFM,
          mergeRequests: enableGFM,
          labels: enableGFM,
        });
      });
67

F
Fatih Acet 已提交
68
      switch (page) {
69
        case 'sessions:new':
C
Clement Ho 已提交
70 71 72
          import('./pages/sessions/new')
            .then(callDefault)
            .catch(fail);
73
          break;
74
        case 'projects:boards:show':
75
        case 'projects:boards:index':
76 77 78 79
          import('./pages/projects/boards/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
80
          break;
81
        case 'projects:merge_requests:index':
82 83 84 85
          import('./pages/projects/merge_requests/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
86
          break;
S
Simon Knox 已提交
87 88 89 90 91 92
        case 'projects:issues:index':
          import('./pages/projects/issues/index')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
          break;
F
Fatih Acet 已提交
93
        case 'projects:issues:show':
S
Simon Knox 已提交
94 95 96 97
          import('./pages/projects/issues/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
98
          break;
P
Phil Hughes 已提交
99
        case 'dashboard:milestones:index':
100 101 102
          import('./pages/dashboard/milestones/index')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
103
          break;
F
Fatih Acet 已提交
104 105 106
        case 'projects:milestones:show':
        case 'groups:milestones:show':
          new Milestone();
107
          new Sidebar();
F
Fatih Acet 已提交
108
          break;
109 110 111 112 113
        case 'dashboard:milestones:show':
          import('./pages/dashboard/milestones/show')
            .then(callDefault)
            .catch(fail);
          break;
114
        case 'dashboard:issues':
C
Clement Ho 已提交
115 116 117
          import('./pages/dashboard/issues')
            .then(callDefault)
            .catch(fail);
C
Clement Ho 已提交
118
          break;
119
        case 'dashboard:merge_requests':
120 121 122
          import('./pages/dashboard/merge_requests')
            .then(callDefault)
            .catch(fail);
123
          break;
124
        case 'groups:issues':
S
Simon Knox 已提交
125 126 127 128
          import('./pages/groups/issues')
            .then(callDefault)
            .catch(fail);
          break;
129
        case 'groups:merge_requests':
S
Simon Knox 已提交
130 131 132
          import('./pages/groups/merge_requests')
            .then(callDefault)
            .catch(fail);
133
          break;
F
Fatih Acet 已提交
134
        case 'dashboard:todos:index':
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':
F
Fatih Acet 已提交
221
        case 'projects:merge_requests:edit':
222
          new Diff();
F
Fatih Acet 已提交
223
          shortcut_handler = new ShortcutsNavigation();
224
          new GLForm($('.merge-request-form'), true);
F
Fatih Acet 已提交
225
          new IssuableForm($('.merge-request-form'));
226 227
          new LabelsSelect();
          new MilestoneSelect();
228
          new IssuableTemplateSelectors();
F
Fatih Acet 已提交
229 230
          break;
        case 'projects:tags:new':
231 232 233
          import('./pages/projects/tags/new')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
234
          break;
235
        case 'projects:snippets:show':
J
Jacob Schatz 已提交
236 237 238
          import('./pages/projects/snippets/show')
            .then(callDefault)
            .catch(fail);
239
          break;
240 241
        case 'projects:snippets:new':
        case 'projects:snippets:create':
C
Clement Ho 已提交
242
          import('./pages/projects/snippets/new')
J
Jacob Schatz 已提交
243 244 245
            .then(callDefault)
            .catch(fail);
          break;
C
Clement Ho 已提交
246
        case 'projects:snippets:edit':
247
        case 'projects:snippets:update':
C
Clement Ho 已提交
248
          import('./pages/projects/snippets/edit')
J
Jacob Schatz 已提交
249 250
            .then(callDefault)
            .catch(fail);
251
          break;
252
        case 'snippets:new':
253 254 255 256
          import('./pages/snippets/new')
            .then(callDefault)
            .catch(fail);
          break;
257
        case 'snippets:edit':
258 259 260 261
          import('./pages/snippets/edit')
            .then(callDefault)
            .catch(fail);
          break;
262
        case 'snippets:create':
C
Clement Ho 已提交
263
          import('./pages/snippets/new')
264 265 266
            .then(callDefault)
            .catch(fail);
          break;
267
        case 'snippets:update':
C
Clement Ho 已提交
268
          import('./pages/snippets/edit')
269 270
            .then(callDefault)
            .catch(fail);
271
          break;
F
Fatih Acet 已提交
272
        case 'projects:releases:edit':
C
Clement Ho 已提交
273
          import('./pages/projects/releases/edit')
J
Jacob Schatz 已提交
274 275
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
276 277
          break;
        case 'projects:merge_requests:show':
278
          new Diff();
F
Fatih Acet 已提交
279
          new ZenMode();
280

281 282
          initIssuableSidebar();
          initNotes();
283

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

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
F
Fatih Acet 已提交
649 650 651
    };

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

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

F
Fatih Acet 已提交
664 665
    return Dispatcher;
  })();
666

667
  $(window).on('load', function() {
668 669
    new Dispatcher();
  });
670
}).call(window);