gitlab-org--gitlab-foss/app/assets/javascripts/dispatcher.js.coffee

117 lines
3.7 KiB
CoffeeScript
Raw Normal View History

$ ->
new Dispatcher()
class Dispatcher
constructor: () ->
@initSearch()
@initHighlight()
@initPageScripts()
initPageScripts: ->
page = $('body').attr('data-page')
2013-05-02 07:36:53 -04:00
project_id = $('body').attr('data-project-id')
unless page
return false
2013-05-02 07:36:53 -04:00
path = page.split(':')
2014-08-21 04:14:31 -04:00
shortcut_handler = null
switch page
when 'projects:issues:index'
2013-05-02 07:36:53 -04:00
Issues.init()
2014-08-21 04:14:31 -04:00
shortcut_handler = new ShortcutsNavigation()
when 'projects:issues:show'
new Issue()
2014-08-21 04:14:31 -04:00
shortcut_handler = new ShortcutsIssueable()
2014-09-11 12:19:49 -04:00
new ZenMode()
when 'projects:milestones:show'
new Milestone()
2014-10-01 03:10:13 -04:00
when 'projects:milestones:new'
new ZenMode()
2014-09-11 12:19:49 -04:00
when 'projects:issues:new','projects:issues:edit'
GitLab.GfmAutoComplete.setup()
2014-08-21 04:14:31 -04:00
shortcut_handler = new ShortcutsNavigation()
2014-09-11 12:19:49 -04:00
new ZenMode()
when 'projects:merge_requests:new', 'projects:merge_requests:edit'
2014-08-02 11:12:01 -04:00
GitLab.GfmAutoComplete.setup()
new Diff()
2014-08-21 04:14:31 -04:00
shortcut_handler = new ShortcutsNavigation()
2014-09-11 12:19:49 -04:00
new ZenMode()
2014-08-02 11:12:01 -04:00
when 'projects:merge_requests:show'
new Diff()
2014-08-21 04:14:31 -04:00
shortcut_handler = new ShortcutsIssueable()
2014-09-11 12:19:49 -04:00
new ZenMode()
2014-08-02 11:12:01 -04:00
when "projects:merge_requests:diffs"
new Diff()
2014-08-21 04:14:31 -04:00
when 'projects:merge_requests:index'
shortcut_handler = new ShortcutsNavigation()
2013-05-02 07:36:53 -04:00
when 'dashboard:show'
new Dashboard()
new Activities()
when 'projects:commit:show'
2013-05-02 07:36:53 -04:00
new Commit()
2014-08-02 11:12:01 -04:00
new Diff()
2014-08-21 04:14:31 -04:00
shortcut_handler = new ShortcutsNavigation()
when 'projects:commits:show'
shortcut_handler = new ShortcutsNavigation()
when 'groups:show', 'projects:show'
new Activities()
2014-08-21 04:14:31 -04:00
shortcut_handler = new ShortcutsNavigation()
when 'projects:new'
2013-05-02 07:36:53 -04:00
new Project()
2014-08-21 04:14:31 -04:00
when 'projects:edit'
new Project()
shortcut_handler = new ShortcutsNavigation()
when 'projects:teams:members:index'
2013-05-30 03:57:10 -04:00
new TeamMembers()
2013-07-12 12:01:39 -04:00
when 'groups:members'
new GroupMembers()
when 'projects:tree:show'
new TreeView()
2014-08-21 04:14:31 -04:00
shortcut_handler = new ShortcutsNavigation()
when 'projects:blob:show'
new BlobView()
2014-08-21 04:14:31 -04:00
shortcut_handler = new ShortcutsNavigation()
when 'projects:labels:new', 'projects:labels:edit'
new Labels()
2014-08-21 04:14:31 -04:00
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
2013-05-02 07:36:53 -04:00
switch path.first()
when 'admin' then new Admin()
2014-08-21 04:14:31 -04:00
when 'dashboard'
shortcut_handler = new ShortcutsDashboardNavigation()
2013-08-08 04:40:42 -04:00
when 'projects'
2014-08-21 04:14:31 -04:00
switch path[1]
when 'wikis'
new Wikis()
shortcut_handler = new ShortcutsNavigation()
2014-10-01 03:10:13 -04:00
new ZenMode()
2014-08-21 04:14:31 -04:00
when 'snippets', 'labels', 'graphs'
shortcut_handler = new ShortcutsNavigation()
when 'team_members', 'deploy_keys', 'hooks', 'services', 'protected_branches'
shortcut_handler = new ShortcutsNavigation()
2013-08-08 04:40:42 -04:00
2014-08-21 04:14:31 -04:00
# If we haven't installed a custom shortcut handler, install the default one
if not shortcut_handler
new Shortcuts()
2013-05-02 07:36:53 -04:00
initSearch: ->
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)
initHighlight: ->
$('.highlight pre code').each (i, e) ->
$(e).html($.map($(e).html().split("\n"), (line, i) ->
"<span class='line' id='LC" + (i + 1) + "'>" + line + "</span>"
).join("\n"))
hljs.highlightBlock(e)