Skip to content

Commit

Permalink
Small fix for TodoList plugin (ColorlibHQ#3013)
Browse files Browse the repository at this point in the history
Properly attach the event listener to the correct selector and fix on the options passed on in the JQuery API. However, a new bug comes from this fix when both data-widget and Jquery API is set where the event listener will be triggered twice
  • Loading branch information
mineminemine authored Sep 11, 2020
1 parent 16b4d30 commit 48743c7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions build/js/TodoList.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class TodoList {
// Private

_init() {
const $toggleSelector = $(SELECTOR_DATA_TOGGLE)
const $toggleSelector = this._element

$toggleSelector.find('input:checkbox:checked').parents('li').toggleClass(CLASS_NAME_TODO_LIST_DONE)
$toggleSelector.on('change', 'input:checkbox', event => {
Expand All @@ -77,15 +77,18 @@ class TodoList {
static _jQueryInterface(config) {
return this.each(function () {
let data = $(this).data(DATA_KEY)
const _options = $.extend({}, Default, $(this).data())

if (!data) {
data = new TodoList($(this), _options)
$(this).data(DATA_KEY, data)
data = $(this).data()
}

const _options = $.extend({}, Default, typeof config === 'object' ? config : data)
const plugin = new TodoList($(this), _options)

$(this).data(DATA_KEY, typeof config === 'object' ? config : data)

if (config === 'init') {
data[config]()
plugin[config]()
}
})
}
Expand Down

0 comments on commit 48743c7

Please sign in to comment.