2016-03-27 11:04:51 -04:00
|
|
|
class @Sidebar
|
|
|
|
constructor: (currentUser) ->
|
2016-04-20 18:04:40 -04:00
|
|
|
@sidebar = $('aside')
|
|
|
|
|
2016-03-27 11:04:51 -04:00
|
|
|
@addEventListeners()
|
|
|
|
|
|
|
|
addEventListeners: ->
|
2016-04-21 13:33:47 -04:00
|
|
|
@sidebar.on('click', '.sidebar-collapsed-icon', @, @sidebarCollapseClicked)
|
|
|
|
$('.dropdown').on('hidden.gl.dropdown', @, @onSidebarDropdownHidden)
|
2016-03-27 11:04:51 -04:00
|
|
|
$('.dropdown').on('loading.gl.dropdown', @sidebarDropdownLoading)
|
|
|
|
$('.dropdown').on('loaded.gl.dropdown', @sidebarDropdownLoaded)
|
|
|
|
|
2016-05-11 17:37:40 -04:00
|
|
|
|
|
|
|
$(document)
|
|
|
|
.off 'click', '.js-sidebar-toggle'
|
|
|
|
.on 'click', '.js-sidebar-toggle', (e, triggered) ->
|
|
|
|
e.preventDefault()
|
|
|
|
$this = $(this)
|
|
|
|
$thisIcon = $this.find 'i'
|
|
|
|
$allGutterToggleIcons = $('.js-sidebar-toggle i')
|
|
|
|
if $thisIcon.hasClass('fa-angle-double-right')
|
|
|
|
$allGutterToggleIcons
|
|
|
|
.removeClass('fa-angle-double-right')
|
|
|
|
.addClass('fa-angle-double-left')
|
|
|
|
$('aside.right-sidebar')
|
|
|
|
.removeClass('right-sidebar-expanded')
|
|
|
|
.addClass('right-sidebar-collapsed')
|
|
|
|
$('.page-with-sidebar')
|
|
|
|
.removeClass('right-sidebar-expanded')
|
|
|
|
.addClass('right-sidebar-collapsed')
|
|
|
|
else
|
|
|
|
$allGutterToggleIcons
|
|
|
|
.removeClass('fa-angle-double-left')
|
|
|
|
.addClass('fa-angle-double-right')
|
|
|
|
$('aside.right-sidebar')
|
|
|
|
.removeClass('right-sidebar-collapsed')
|
|
|
|
.addClass('right-sidebar-expanded')
|
|
|
|
$('.page-with-sidebar')
|
|
|
|
.removeClass('right-sidebar-collapsed')
|
|
|
|
.addClass('right-sidebar-expanded')
|
|
|
|
if not triggered
|
|
|
|
$.cookie("collapsed_gutter",
|
|
|
|
$('.right-sidebar')
|
|
|
|
.hasClass('right-sidebar-collapsed'), { path: '/' })
|
|
|
|
|
|
|
|
|
2016-03-27 11:04:51 -04:00
|
|
|
sidebarDropdownLoading: (e) ->
|
|
|
|
$sidebarCollapsedIcon = $(@).closest('.block').find('.sidebar-collapsed-icon')
|
|
|
|
img = $sidebarCollapsedIcon.find('img')
|
|
|
|
i = $sidebarCollapsedIcon.find('i')
|
|
|
|
$loading = $('<i class="fa fa-spinner fa-spin"></i>')
|
|
|
|
if img.length
|
|
|
|
img.before($loading)
|
|
|
|
img.hide()
|
|
|
|
else if i.length
|
|
|
|
i.before($loading)
|
|
|
|
i.hide()
|
|
|
|
|
|
|
|
sidebarDropdownLoaded: (e) ->
|
|
|
|
$sidebarCollapsedIcon = $(@).closest('.block').find('.sidebar-collapsed-icon')
|
|
|
|
img = $sidebarCollapsedIcon.find('img')
|
|
|
|
$sidebarCollapsedIcon.find('i.fa-spin').remove()
|
|
|
|
i = $sidebarCollapsedIcon.find('i')
|
|
|
|
if img.length
|
|
|
|
img.show()
|
|
|
|
else
|
|
|
|
i.show()
|
|
|
|
|
2016-04-21 13:33:47 -04:00
|
|
|
sidebarCollapseClicked: (e) ->
|
|
|
|
sidebar = e.data
|
|
|
|
e.preventDefault()
|
|
|
|
$block = $(@).closest('.block')
|
|
|
|
sidebar.openDropdown($block);
|
|
|
|
|
2016-04-20 18:04:40 -04:00
|
|
|
openDropdown: (blockOrName) ->
|
|
|
|
$block = if _.isString(blockOrName) then @getBlock(blockOrName) else blockOrName
|
2016-03-27 11:04:51 -04:00
|
|
|
|
2016-04-20 18:04:40 -04:00
|
|
|
$block.find('.edit-link').trigger('click')
|
2016-03-29 08:28:04 -04:00
|
|
|
|
2016-04-20 18:04:40 -04:00
|
|
|
if not @isOpen()
|
|
|
|
@setCollapseAfterUpdate($block)
|
|
|
|
@toggleSidebar('open')
|
2016-03-27 11:04:51 -04:00
|
|
|
|
2016-04-20 18:04:40 -04:00
|
|
|
setCollapseAfterUpdate: ($block) ->
|
|
|
|
$block.addClass('collapse-after-update')
|
|
|
|
$('.page-with-sidebar').addClass('with-overlay')
|
2016-03-27 11:04:51 -04:00
|
|
|
|
2016-04-21 13:33:47 -04:00
|
|
|
onSidebarDropdownHidden: (e) ->
|
|
|
|
sidebar = e.data
|
|
|
|
e.preventDefault()
|
|
|
|
$block = $(@).closest('.block')
|
|
|
|
sidebar.sidebarDropdownHidden($block)
|
|
|
|
|
2016-04-20 18:04:40 -04:00
|
|
|
sidebarDropdownHidden: ($block) ->
|
2016-03-27 11:04:51 -04:00
|
|
|
if $block.hasClass('collapse-after-update')
|
|
|
|
$block.removeClass('collapse-after-update')
|
2016-03-29 08:28:04 -04:00
|
|
|
$('.page-with-sidebar').removeClass('with-overlay')
|
2016-04-20 18:04:40 -04:00
|
|
|
@toggleSidebar('hide')
|
|
|
|
|
|
|
|
triggerOpenSidebar: ->
|
|
|
|
@sidebar
|
|
|
|
.find('.js-sidebar-toggle')
|
|
|
|
.trigger('click')
|
|
|
|
|
|
|
|
toggleSidebar: (action = 'toggle') ->
|
|
|
|
if action is 'toggle'
|
|
|
|
@triggerOpenSidebar()
|
|
|
|
|
|
|
|
if action is 'open'
|
|
|
|
@triggerOpenSidebar() if not @isOpen()
|
|
|
|
|
|
|
|
if action is 'hide'
|
2016-05-11 07:55:04 -04:00
|
|
|
@triggerOpenSidebar() if @isOpen()
|
2016-04-20 18:04:40 -04:00
|
|
|
|
|
|
|
isOpen: ->
|
|
|
|
@sidebar.is('.right-sidebar-expanded')
|
|
|
|
|
|
|
|
getBlock: (name) ->
|
|
|
|
@sidebar.find(".block.#{name}")
|
|
|
|
|
|
|
|
|