dispatcher.js.coffee 3.78 KB
Newer Older
1 2
$ ->
  new Dispatcher()
3

4 5
class Dispatcher
  constructor: () ->
6
    @initSearch()
7
    @initHighlight()
8 9 10
    @initPageScripts()

  initPageScripts: ->
11
    page = $('body').attr('data-page')
12
    project_id = $('body').attr('data-project-id')
13

14 15 16
    unless page
      return false

17
    path = page.split(':')
18
    shortcut_handler = null
19 20

    switch page
21
      when 'projects:issues:index'
22
        Issues.init()
23
        shortcut_handler = new ShortcutsNavigation()
24 25
      when 'projects:issues:show'
        new Issue()
26
        shortcut_handler = new ShortcutsIssueable()
27
        new ZenMode()
28 29
      when 'projects:milestones:show'
        new Milestone()
30 31
      when 'projects:milestones:new'
        new ZenMode()
32
      when 'projects:issues:new','projects:issues:edit'
33
        GitLab.GfmAutoComplete.setup()
34
        shortcut_handler = new ShortcutsNavigation()
35 36
        new ZenMode()
      when 'projects:merge_requests:new', 'projects:merge_requests:edit'
skv's avatar
skv committed
37 38
        GitLab.GfmAutoComplete.setup()
        new Diff()
39
        shortcut_handler = new ShortcutsNavigation()
40
        new ZenMode()
skv's avatar
skv committed
41 42
      when 'projects:merge_requests:show'
        new Diff()
43
        shortcut_handler = new ShortcutsIssueable()
44
        new ZenMode()
skv's avatar
skv committed
45 46
      when "projects:merge_requests:diffs"
        new Diff()
47 48
      when 'projects:merge_requests:index'
        shortcut_handler = new ShortcutsNavigation()
49 50
      when 'dashboard:show'
        new Dashboard()
51
        new Activities()
52
      when 'projects:commit:show'
53
        new Commit()
skv's avatar
skv committed
54
        new Diff()
55 56 57
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:commits:show'
        shortcut_handler = new ShortcutsNavigation()
58
      when 'groups:show', 'projects:show'
59
        new Activities()
60 61
        shortcut_handler = new ShortcutsNavigation()
      when 'projects:new'
62
        new Project()
63 64 65
      when 'projects:edit'
        new Project()
        shortcut_handler = new ShortcutsNavigation()
66
      when 'projects:teams:members:index'
67
        new TeamMembers()
68
      when 'groups:members'
69
        new GroupMembers()
70 71
      when 'groups:new', 'groups:edit', 'admin:groups:edit'
        new GroupAvatar()
72 73
      when 'projects:tree:show'
        new TreeView()
74
        shortcut_handler = new ShortcutsNavigation()
75 76
      when 'projects:blob:show'
        new BlobView()
77
        shortcut_handler = new ShortcutsNavigation()
78
      when 'projects:labels:new', 'projects:labels:edit'
79
        new Labels()
80 81 82 83
      when 'projects:network:show'
        # Ensure we don't create a particular shortcut handler here. This is
        # already created, where the network graph is created.
        shortcut_handler = true
84 85

    switch path.first()
86
      when 'admin' then new Admin()
87 88
      when 'dashboard'
        shortcut_handler = new ShortcutsDashboardNavigation()
89
      when 'projects'
90 91 92 93
        switch path[1]
          when 'wikis'
            new Wikis()
            shortcut_handler = new ShortcutsNavigation()
94
            new ZenMode()
95 96 97 98 99
          when 'snippets', 'labels', 'graphs'
            shortcut_handler = new ShortcutsNavigation()
          when 'team_members', 'deploy_keys', 'hooks', 'services', 'protected_branches'
            shortcut_handler = new ShortcutsNavigation()

100

101 102 103
    # If we haven't installed a custom shortcut handler, install the default one
    if not shortcut_handler
      new Shortcuts()
104

105
  initSearch: ->
106 107 108 109 110 111
    opts = $('.search-autocomplete-opts')
    path = opts.data('autocomplete-path')
    project_id = opts.data('autocomplete-project-id')
    project_ref = opts.data('autocomplete-project-ref')

    new SearchAutocomplete(path, project_id, project_ref)
112 113

  initHighlight: ->
114
    $('.highlight pre code').each (i, e) ->
115
      $(e).html($.map($(e).html().split("\n"), (line, i) ->
Evan Lucas's avatar
Evan Lucas committed
116
        "<span class='line' id='LC" + (i + 1) + "'>" + line + "</span>"
117
      ).join("\n"))
Evan Lucas's avatar
Evan Lucas committed
118
      hljs.highlightBlock(e)