Skip to content

Commit 320d5f8

Browse files
committed
fix: Event listeners for Sidebar and AsideMenu plugins persist in jQuery instance
2 parents d71296e + 13186de commit 320d5f8

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

js/src/ajax-load.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const AjaxLoad = (($) => {
5858
} else {
5959
this.setUpUrl(this._config.defaultPage)
6060
}
61+
this._removeEventListeners()
6162
this._addEventListeners()
6263
}
6364

@@ -167,6 +168,10 @@ const AjaxLoad = (($) => {
167168
})
168169
}
169170

171+
_removeEventListeners() {
172+
$(document).off(Event.CLICK, `${Selector.NAV_LINK}[href!="#"]`)
173+
}
174+
170175
// Static
171176

172177
static _jQueryInterface(config) {

js/src/aside-menu.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ const AsideMenu = (($) => {
5151
class AsideMenu {
5252
constructor(element) {
5353
this._element = element
54+
this._removeEventListeners()
5455
this._addEventListeners()
5556
}
5657

@@ -71,6 +72,10 @@ const AsideMenu = (($) => {
7172
})
7273
}
7374

75+
_removeEventListeners() {
76+
$(document).off(Event.CLICK, Selector.ASIDE_MENU_TOGGLER)
77+
}
78+
7479
// Static
7580

7681
static _jQueryInterface() {
@@ -92,7 +97,7 @@ const AsideMenu = (($) => {
9297
* ------------------------------------------------------------------------
9398
*/
9499

95-
$(window).on(Event.LOAD_DATA_API, () => {
100+
$(window).one(Event.LOAD_DATA_API, () => {
96101
const asideMenu = $(Selector.ASIDE_MENU)
97102
AsideMenu._jQueryInterface.call(asideMenu)
98103
})

js/src/sidebar.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ const Sidebar = (($) => {
8787
this.setActiveLink()
8888
this._breakpointTest = this._breakpointTest.bind(this)
8989
this._clickOutListener = this._clickOutListener.bind(this)
90+
this._removeEventListeners()
9091
this._addEventListeners()
9192
this._addMediaQuery()
9293
}
@@ -260,6 +261,14 @@ const Sidebar = (($) => {
260261
})
261262
}
262263

264+
_removeEventListeners() {
265+
$(document).off(Event.CLICK, Selector.BRAND_MINIMIZER)
266+
$(document).off(Event.CLICK, Selector.NAV_DROPDOWN_TOGGLE)
267+
$(document).off(Event.CLICK, Selector.SIDEBAR_MINIMIZER)
268+
$(document).off(Event.CLICK, Selector.SIDEBAR_TOGGLER)
269+
$(`${Selector.NAVIGATION} > ${Selector.NAV_ITEM} ${Selector.NAV_LINK}:not(${Selector.NAV_DROPDOWN_TOGGLE})`).off(Event.CLICK)
270+
}
271+
263272
// Static
264273

265274
static _jQueryInterface() {
@@ -281,7 +290,7 @@ const Sidebar = (($) => {
281290
* ------------------------------------------------------------------------
282291
*/
283292

284-
$(window).on(Event.LOAD_DATA_API, () => {
293+
$(window).one(Event.LOAD_DATA_API, () => {
285294
const sidebar = $(Selector.SIDEBAR)
286295
Sidebar._jQueryInterface.call(sidebar)
287296
})

0 commit comments

Comments
 (0)