From 9db02e5ba994d6ba7ebd7954031652c76279c632 Mon Sep 17 00:00:00 2001 From: Alfredo Sumaran Date: Thu, 21 Apr 2016 12:33:47 -0500 Subject: [PATCH] Move event handlers to methods --- .../javascripts/right_sidebar.js.coffee | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/assets/javascripts/right_sidebar.js.coffee b/app/assets/javascripts/right_sidebar.js.coffee index bc66d0f8246..2d084b76cfe 100644 --- a/app/assets/javascripts/right_sidebar.js.coffee +++ b/app/assets/javascripts/right_sidebar.js.coffee @@ -5,16 +5,8 @@ class @Sidebar @addEventListeners() addEventListeners: -> - _this = @ - @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) + @sidebar.on('click', '.sidebar-collapsed-icon', @, @sidebarCollapseClicked) + $('.dropdown').on('hidden.gl.dropdown', @, @onSidebarDropdownHidden) $('.dropdown').on('loading.gl.dropdown', @sidebarDropdownLoading) $('.dropdown').on('loaded.gl.dropdown', @sidebarDropdownLoaded) @@ -40,6 +32,12 @@ class @Sidebar else i.show() + sidebarCollapseClicked: (e) -> + sidebar = e.data + e.preventDefault() + $block = $(@).closest('.block') + sidebar.openDropdown($block); + openDropdown: (blockOrName) -> $block = if _.isString(blockOrName) then @getBlock(blockOrName) else blockOrName @@ -53,6 +51,12 @@ class @Sidebar $block.addClass('collapse-after-update') $('.page-with-sidebar').addClass('with-overlay') + onSidebarDropdownHidden: (e) -> + sidebar = e.data + e.preventDefault() + $block = $(@).closest('.block') + sidebar.sidebarDropdownHidden($block) + sidebarDropdownHidden: ($block) -> if $block.hasClass('collapse-after-update') $block.removeClass('collapse-after-update')