dispatcher.js 21.9 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';
P
Phil Hughes 已提交
3 4
import NotificationsForm from './notifications_form';
import notificationsDropdown from './notifications_dropdown';
P
Phil Hughes 已提交
5 6 7
import LineHighlighter from './line_highlighter';
import MergeRequest from './merge_request';
import Sidebar from './right_sidebar';
8
import Flash from './flash';
9
import SecretValues from './behaviors/secret_values';
M
Mike Greiling 已提交
10
import UserCallout from './user_callout';
D
Douwe Maan 已提交
11
import BlobViewer from './blob/viewer/index';
12
import GfmAutoComplete from './gfm_auto_complete';
13
import Star from './star';
14
import TreeView from './tree';
15
import ZenMode from './zen_mode';
16
import initSettingsPanels from './settings_panels';
17
import PerformanceBar from './performance_bar';
P
Phil Hughes 已提交
18 19
import initNotes from './init_notes';
import initIssuableSidebar from './init_issuable_sidebar';
20
import { ajaxGet, convertPermissionToBoolean } from './lib/utils/common_utils';
21 22
import GlFieldErrors from './gl_field_errors';
import GLForm from './gl_form';
23 24 25
import Shortcuts from './shortcuts';
import ShortcutsNavigation from './shortcuts_navigation';
import ShortcutsIssuable from './shortcuts_issuable';
F
Filipa Lacerda 已提交
26
import U2FAuthenticate from './u2f/authenticate';
27
import Diff from './diff';
F
Filipa Lacerda 已提交
28
import SearchAutocomplete from './search_autocomplete';
29
import Activities from './activities';
30

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

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

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

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

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

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

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

275 276
          initIssuableSidebar();
          initNotes();
277

278 279 280 281
          const mrShowNode = document.querySelector('.merge-request');
          window.mergeRequest = new MergeRequest({
            action: mrShowNode.dataset.mrAction,
          });
282
          shortcut_handler = new ShortcutsIssuable(true);
F
Fatih Acet 已提交
283 284
          break;
        case 'dashboard:activity':
C
Clement Ho 已提交
285 286 287
          import('./pages/dashboard/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
288 289
          break;
        case 'projects:commit:show':
290 291 292 293
          import('./pages/projects/commit/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
294
          break;
295
        case 'projects:commit:pipelines':
296 297 298
          import('./pages/projects/commit/pipelines')
            .then(callDefault)
            .catch(fail);
299
          break;
300
        case 'projects:activity':
301
          import('./pages/projects/activity')
302 303
            .then(callDefault)
            .catch(fail);
304
          shortcut_handler = true;
305
          break;
306
        case 'projects:commits:show':
307 308 309 310
          import('./pages/projects/commits/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
311 312 313 314
          break;
        case 'projects:show':
          shortcut_handler = new ShortcutsNavigation();
          new NotificationsForm();
F
Filipa Lacerda 已提交
315 316 317 318
          new UserCallout({
            setCalloutPerProject: true,
            className: 'js-autodevops-banner',
          });
319 320

          if ($('#tree-slider').length) new TreeView();
321
          if ($('.blob-viewer').length) new BlobViewer();
322
          if ($('.project-show-activity').length) new Activities();
323
          $('#tree-slider').waitForImages(function() {
F
Filipa Lacerda 已提交
324
            ajaxGet(document.querySelector('.js-tree-content').dataset.logsPath);
325
          });
F
Fatih Acet 已提交
326
          break;
327
        case 'projects:edit':
S
Simon Knox 已提交
328 329 330
          import('./pages/projects/edit')
            .then(callDefault)
            .catch(fail);
331
          break;
332
        case 'projects:imports:show':
S
Simon Knox 已提交
333 334 335
          import('./pages/projects/imports/show')
            .then(callDefault)
            .catch(fail);
336
          break;
337
        case 'projects:pipelines:new':
338
        case 'projects:pipelines:create':
339 340 341
          import('./pages/projects/pipelines/new')
            .then(callDefault)
            .catch(fail);
342
          break;
F
Filipa Lacerda 已提交
343
        case 'projects:pipelines:builds':
344
        case 'projects:pipelines:failures':
L
Luke Bennett 已提交
345
        case 'projects:pipelines:show':
346 347 348
          import('./pages/projects/pipelines/builds')
            .then(callDefault)
            .catch(fail);
L
Luke Bennett 已提交
349
          break;
F
Fatih Acet 已提交
350
        case 'groups:activity':
S
Simon Knox 已提交
351 352 353
          import('./pages/groups/activity')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
354 355
          break;
        case 'groups:show':
S
Simon Knox 已提交
356 357 358 359
          import('./pages/groups/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
360 361
          break;
        case 'groups:group_members:index':
S
Simon Knox 已提交
362 363 364
          import('./pages/groups/group_members/index')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
365
          break;
366
        case 'projects:project_members:index':
367 368 369
          import('./pages/projects/project_members/')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
370
          break;
371
        case 'groups:create':
S
Simon Knox 已提交
372 373 374 375 376 377 378 379 380
        case 'groups:new':
          import('./pages/groups/new')
            .then(callDefault)
            .catch(fail);
          break;
        case 'groups:edit':
          import('./pages/groups/edit')
            .then(callDefault)
            .catch(fail);
381
          break;
P
Phil Hughes 已提交
382 383
        case 'admin:groups:create':
        case 'admin:groups:new':
P
Phil Hughes 已提交
384 385 386
          import('./pages/admin/groups/new')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
387
          break;
F
Fatih Acet 已提交
388
        case 'admin:groups:edit':
P
Phil Hughes 已提交
389 390 391
          import('./pages/admin/groups/edit')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
392
          break;
393
        case 'projects:tree:show':
394
          import('./pages/projects/tree/show')
395
            .then(callDefault)
396
            .catch(fail);
397
          shortcut_handler = true;
398
          break;
F
Fatih Acet 已提交
399
        case 'projects:find_file:show':
S
Simon Knox 已提交
400 401 402
          import('./pages/projects/find_file/show')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
403 404
          shortcut_handler = true;
          break;
405
        case 'projects:blob:show':
406 407 408 409
          import('./pages/projects/blob/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
410
          break;
F
Fatih Acet 已提交
411
        case 'projects:blame:show':
412 413 414 415
          import('./pages/projects/blame/show')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
416
          break;
417
        case 'groups:labels:new':
S
Simon Knox 已提交
418 419 420 421
          import('./pages/groups/labels/new')
            .then(callDefault)
            .catch(fail);
          break;
422
        case 'groups:labels:edit':
S
Simon Knox 已提交
423 424 425
          import('./pages/groups/labels/edit')
            .then(callDefault)
            .catch(fail);
C
Clement Ho 已提交
426
          break;
F
Fatih Acet 已提交
427
        case 'projects:labels:new':
J
Jacob Schatz 已提交
428 429 430 431
          import('./pages/projects/labels/new')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
432
        case 'projects:labels:edit':
C
Clement Ho 已提交
433
          import('./pages/projects/labels/edit')
J
Jacob Schatz 已提交
434 435
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
436
          break;
S
Simon Knox 已提交
437 438 439 440 441
        case 'groups:labels:index':
          import('./pages/groups/labels/index')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
442
        case 'projects:labels:index':
J
Jacob Schatz 已提交
443 444 445 446
          import('./pages/projects/labels/index')
            .then(callDefault)
            .catch(fail);
          break;
F
Fatih Acet 已提交
447
        case 'projects:network:show':
448 449
          // Ensure we don't create a particular shortcut handler here. This is
          // already created, where the network graph is created.
F
Fatih Acet 已提交
450 451 452
          shortcut_handler = true;
          break;
        case 'projects:forks:new':
S
Simon Knox 已提交
453
          import('./pages/projects/forks/new')
J
Jacob Schatz 已提交
454 455
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
456 457
          break;
        case 'projects:artifacts:browse':
458
          import('./pages/projects/artifacts/browse')
459 460
            .then(callDefault)
            .catch(fail);
461
          shortcut_handler = true;
F
Fatih Acet 已提交
462
          break;
463
        case 'projects:artifacts:file':
464
          import('./pages/projects/artifacts/file')
465 466
            .then(callDefault)
            .catch(fail);
467
          shortcut_handler = true;
468
          break;
469
        case 'help:index':
470 471 472
          import('./pages/help')
            .then(callDefault)
            .catch(fail);
473
          break;
F
Fatih Acet 已提交
474
        case 'search:show':
C
Clement Ho 已提交
475 476 477
          import('./pages/search/show')
            .then(callDefault)
            .catch(fail);
478
          break;
D
Douwe Maan 已提交
479
        case 'projects:settings:repository:show':
480 481
          // Initialize expandable settings panels
          initSettingsPanels();
482
          break;
D
Douwe Maan 已提交
483
        case 'projects:settings:ci_cd:show':
484 485
          // Initialize expandable settings panels
          initSettingsPanels();
486 487 488 489 490 491

          const runnerToken = document.querySelector('.js-secret-runner-token');
          if (runnerToken) {
            const runnerTokenSecretValue = new SecretValues(runnerToken);
            runnerTokenSecretValue.init();
          }
S
Shinya Maeda 已提交
492
        case 'groups:settings:ci_cd:show':
S
Simon Knox 已提交
493 494 495
          import('./pages/groups/settings/ci_cd/show')
            .then(callDefault)
            .catch(fail);
S
Stan Hu 已提交
496
          break;
497 498
        case 'ci:lints:create':
        case 'ci:lints:show':
499
          import('./pages/ci/lints').then(m => m.default()).catch(fail);
500
          break;
501
        case 'users:show':
502
          import('./pages/users/show').then(callDefault).catch(fail);
503
          break;
504
        case 'admin:conversational_development_index:show':
505
          import('./pages/admin/conversational_development_index/show').then(m => m.default()).catch(fail);
506
          break;
D
Douwe Maan 已提交
507
        case 'snippets:show':
C
Clement Ho 已提交
508 509 510
          import('./pages/snippets/show')
            .then(callDefault)
            .catch(fail);
D
Douwe Maan 已提交
511
          break;
512
        case 'import:fogbugz:new_user_map':
513
          import('./pages/import/fogbugz/new_user_map').then(m => m.default()).catch(fail);
514
          break;
515
        case 'profiles:personal_access_tokens:index':
516 517 518 519
          import('./pages/profiles/personal_access_tokens')
            .then(callDefault)
            .catch(fail);
          break;
520
        case 'admin:impersonation_tokens:index':
P
Phil Hughes 已提交
521 522 523
          import('./pages/admin/impersonation_tokens')
            .then(callDefault)
            .catch(fail);
P
Phil Hughes 已提交
524
          break;
F
Filipa Lacerda 已提交
525
        case 'projects:clusters:show':
526 527
        case 'projects:clusters:update':
        case 'projects:clusters:destroy':
528 529 530
          import('./pages/projects/clusters/show')
            .then(callDefault)
            .catch(fail);
531 532
          break;
        case 'projects:clusters:index':
533 534 535
          import('./pages/projects/clusters/index')
            .then(callDefault)
            .catch(fail);
F
Filipa Lacerda 已提交
536
          break;
F
Fatih Acet 已提交
537
      }
538
      switch (path[0]) {
539 540 541
        case 'sessions':
        case 'omniauth_callbacks':
          if (!gon.u2f) break;
F
Filipa Lacerda 已提交
542
          const u2fAuthenticate = new U2FAuthenticate(
543 544 545 546 547 548
            $('#js-authenticate-u2f'),
            '#js-login-u2f-form',
            gon.u2f,
            document.querySelector('#js-login-2fa-device'),
            document.querySelector('.js-2fa-form'),
          );
F
Filipa Lacerda 已提交
549 550 551
          u2fAuthenticate.start();
          // needed in rspec
          gl.u2fAuthenticate = u2fAuthenticate;
F
Fatih Acet 已提交
552
        case 'admin':
P
Phil Hughes 已提交
553 554 555
          import('./pages/admin')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
556
          switch (path[1]) {
M
Mike Greiling 已提交
557
            case 'broadcast_messages':
P
Phil Hughes 已提交
558 559 560
              import('./pages/admin/broadcast_messages')
                .then(callDefault)
                .catch(fail);
M
Mike Greiling 已提交
561
              break;
S
Sean McGivern 已提交
562
            case 'cohorts':
P
Phil Hughes 已提交
563 564 565
              import('./pages/admin/cohorts')
                .then(callDefault)
                .catch(fail);
566
              break;
F
Fatih Acet 已提交
567
            case 'groups':
P
Phil Hughes 已提交
568 569
              switch (path[2]) {
                case 'show':
P
Phil Hughes 已提交
570 571 572
                  import('./pages/admin/groups/show')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
573 574
                  break;
              }
F
Fatih Acet 已提交
575 576
              break;
            case 'projects':
P
Phil Hughes 已提交
577 578 579
              import('./pages/admin/projects')
                .then(callDefault)
                .catch(fail);
580 581
              break;
            case 'labels':
582
              switch (path[2]) {
583
                case 'new':
P
Phil Hughes 已提交
584 585 586
                  import('./pages/admin/labels/new')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
587
                  break;
588
                case 'edit':
P
Phil Hughes 已提交
589 590 591
                  import('./pages/admin/labels/edit')
                    .then(callDefault)
                    .catch(fail);
P
Phil Hughes 已提交
592
                  break;
593
              }
594
            case 'abuse_reports':
P
Phil Hughes 已提交
595 596 597
              import('./pages/admin/abuse_reports')
                .then(callDefault)
                .catch(fail);
598
              break;
F
Fatih Acet 已提交
599 600 601 602
          }
          break;
        case 'dashboard':
        case 'root':
603
          new UserCallout();
F
Fatih Acet 已提交
604 605
          break;
        case 'profiles':
606 607 608
          import('./pages/profiles/index/')
            .then(callDefault)
            .catch(fail);
F
Fatih Acet 已提交
609 610
          break;
        case 'projects':
611 612 613 614
          import('./pages/projects')
            .then(callDefault)
            .catch(fail);
          shortcut_handler = true;
F
Fatih Acet 已提交
615 616
          switch (path[1]) {
            case 'compare':
617 618 619
              import('./pages/projects/compare')
                .then(callDefault)
                .catch(fail);
F
Fatih Acet 已提交
620
              break;
621 622 623
            case 'create':
            case 'new':
              import('./pages/projects/new')
J
Jacob Schatz 已提交
624 625
                .then(callDefault)
                .catch(fail);
F
Fatih Acet 已提交
626 627
              break;
            case 'show':
628
              new Star();
P
Phil Hughes 已提交
629
              notificationsDropdown();
F
Fatih Acet 已提交
630 631
              break;
            case 'wikis':
632 633 634 635
              import('./pages/projects/wikis')
                .then(callDefault)
                .catch(fail);
              shortcut_handler = true;
F
Fatih Acet 已提交
636 637 638 639
              break;
            case 'snippets':
              if (path[2] === 'show') {
                new ZenMode();
D
Douwe Maan 已提交
640 641
                new LineHighlighter();
                new BlobViewer();
F
Fatih Acet 已提交
642 643 644
              }
              break;
          }
645
          break;
F
Fatih Acet 已提交
646
      }
647
      // If we haven't installed a custom shortcut handler, install the default one
F
Fatih Acet 已提交
648
      if (!shortcut_handler) {
649
        new Shortcuts();
F
Fatih Acet 已提交
650
      }
651 652 653 654

      if (document.querySelector('#peek')) {
        new PerformanceBar({ container: '#peek' });
      }
F
Fatih Acet 已提交
655 656 657
    };

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

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

F
Fatih Acet 已提交
670 671
    return Dispatcher;
  })();
672

673
  $(window).on('load', function() {
674 675
    new Dispatcher();
  });
676
}).call(window);