Commit c9f11db2 authored by Alfredo Sumaran's avatar Alfredo Sumaran

Make shortcuts work when sidebar is collapsed

parent a4592434
class @Sidebar class @Sidebar
constructor: (currentUser) -> constructor: (currentUser) ->
@sidebar = $('aside')
@addEventListeners() @addEventListeners()
addEventListeners: -> addEventListeners: ->
$('aside').on('click', '.sidebar-collapsed-icon', @sidebarCollapseClicked) _this = @
$('.dropdown').on('hidden.gl.dropdown', @sidebarDropdownHidden) @sidebar.on 'click', '.sidebar-collapsed-icon', (e) ->
e.preventDefault()
$block = $(@).closest('.block')
_this.openDropdown($block);
$('.dropdown').on 'hidden.gl.dropdown', (e) ->
e.preventDefault()
$block = $(@).closest('.block')
_this.sidebarDropdownHidden($block)
$('.dropdown').on('loading.gl.dropdown', @sidebarDropdownLoading) $('.dropdown').on('loading.gl.dropdown', @sidebarDropdownLoading)
$('.dropdown').on('loaded.gl.dropdown', @sidebarDropdownLoaded) $('.dropdown').on('loaded.gl.dropdown', @sidebarDropdownLoaded)
...@@ -30,26 +40,44 @@ class @Sidebar ...@@ -30,26 +40,44 @@ class @Sidebar
else else
i.show() i.show()
openDropdown: (blockOrName) ->
$block = if _.isString(blockOrName) then @getBlock(blockOrName) else blockOrName
sidebarCollapseClicked: (e) -> $block.find('.edit-link').trigger('click')
e.preventDefault()
$block = $(@).closest('.block')
$('aside') if not @isOpen()
.find('.gutter-toggle') @setCollapseAfterUpdate($block)
.trigger('click') @toggleSidebar('open')
$editLink = $block.find('.edit-link')
if $editLink.length setCollapseAfterUpdate: ($block) ->
$editLink.trigger('click')
$block.addClass('collapse-after-update') $block.addClass('collapse-after-update')
$('.page-with-sidebar').addClass('with-overlay') $('.page-with-sidebar').addClass('with-overlay')
sidebarDropdownHidden: (e) -> sidebarDropdownHidden: ($block) ->
$block = $(@).closest('.block')
if $block.hasClass('collapse-after-update') if $block.hasClass('collapse-after-update')
$block.removeClass('collapse-after-update') $block.removeClass('collapse-after-update')
$('.page-with-sidebar').removeClass('with-overlay') $('.page-with-sidebar').removeClass('with-overlay')
$('aside') @toggleSidebar('hide')
.find('.gutter-toggle')
triggerOpenSidebar: ->
@sidebar
.find('.js-sidebar-toggle')
.trigger('click') .trigger('click')
toggleSidebar: (action = 'toggle') ->
if action is 'toggle'
@triggerOpenSidebar()
if action is 'open'
@triggerOpenSidebar() if not @isOpen()
if action is 'hide'
@triggerOpenSidebar() is @isOpen()
isOpen: ->
@sidebar.is('.right-sidebar-expanded')
getBlock: (name) ->
@sidebar.find(".block.#{name}")
...@@ -4,18 +4,8 @@ ...@@ -4,18 +4,8 @@
class @ShortcutsIssuable extends ShortcutsNavigation class @ShortcutsIssuable extends ShortcutsNavigation
constructor: (isMergeRequest) -> constructor: (isMergeRequest) ->
super() super()
Mousetrap.bind('a', -> Mousetrap.bind('a', @openSidebarDropdown.bind(@, 'assignee'))
$('.block.assignee .edit-link').trigger('click') Mousetrap.bind('m', @openSidebarDropdown.bind(@, 'milestone'))
return false
)
Mousetrap.bind('m', ->
$('.block.milestone .edit-link').trigger('click')
return false
)
Mousetrap.bind('r', =>
@replyWithSelectedText()
return false
)
Mousetrap.bind('j', => Mousetrap.bind('j', =>
@prevIssue() @prevIssue()
return false return false
...@@ -28,10 +18,7 @@ class @ShortcutsIssuable extends ShortcutsNavigation ...@@ -28,10 +18,7 @@ class @ShortcutsIssuable extends ShortcutsNavigation
@editIssue() @editIssue()
return false return false
) )
Mousetrap.bind('l', => Mousetrap.bind('l', @openSidebarDropdown.bind(@, 'labels'))
$('.block.labels .edit-link').trigger('click')
return false
)
if isMergeRequest if isMergeRequest
@enabledHelp.push('.hidden-shortcut.merge_requests') @enabledHelp.push('.hidden-shortcut.merge_requests')
...@@ -74,3 +61,7 @@ class @ShortcutsIssuable extends ShortcutsNavigation ...@@ -74,3 +61,7 @@ class @ShortcutsIssuable extends ShortcutsNavigation
editIssue: -> editIssue: ->
$editBtn = $('.issuable-edit') $editBtn = $('.issuable-edit')
Turbolinks.visit($editBtn.attr('href')) Turbolinks.visit($editBtn.attr('href'))
openSidebarDropdown: (name) ->
sidebar.openDropdown(name)
return false
...@@ -153,4 +153,4 @@ ...@@ -153,4 +153,4 @@
new LabelsSelect(); new LabelsSelect();
new IssuableContext('#{escape_javascript(current_user.to_json(only: [:username, :id, :name]))}'); new IssuableContext('#{escape_javascript(current_user.to_json(only: [:username, :id, :name]))}');
new Subscription('.subscription') new Subscription('.subscription')
new Sidebar(); sidebar = new Sidebar();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment