dispatcher.js.coffee 1.6 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 19

    switch page
20
      when 'projects:issues:index'
21
        Issues.init()
D
Dmitriy Zaporozhets 已提交
22 23
      when 'projects:issues:new', 'projects:merge_requests:new'
        GitLab.GfmAutoComplete.setup()
24 25
      when 'dashboard:show'
        new Dashboard()
26
        new Activities()
27
      when 'projects:commit:show'
28
        new Commit()
29
      when 'groups:show', 'projects:show'
30
        new Activities()
31
      when 'projects:new', 'projects:edit'
32
        new Project()
33
      when 'projects:walls:show'
34
        new Wall(project_id)
35
      when 'projects:teams:members:index'
D
Dmitriy Zaporozhets 已提交
36
        new TeamMembers()
37
      when 'groups:members'
38
        new GroupMembers()
39 40 41 42
      when 'projects:tree:show'
        new TreeView()
      when 'projects:blob:show'
        new BlobView()
43 44

    switch path.first()
45
      when 'admin' then new Admin()
46 47 48
      when 'projects'
        new Wikis() if path[1] == 'wikis'

49

50
  initSearch: ->
51 52 53 54 55 56
    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)
57 58

  initHighlight: ->
59
    $('.highlight pre code').each (i, e) ->
60 61 62 63
      hljs.highlightBlock(e)
      $(e).html($.map($(e).html().split("\n"), (line, i) ->
        "<div class='line' id='LC" + (i + 1) + "'>" + line + "</div>"
      ).join("\n"))