Implemented forum likes
This commit is contained in:
@ -182,23 +182,36 @@ export class AnimeNotifier {
|
||||
|
||||
assignActions() {
|
||||
for(let element of findAll("action")) {
|
||||
if(element["action assigned"]) {
|
||||
continue
|
||||
}
|
||||
|
||||
let actionTrigger = element.dataset.trigger
|
||||
let actionName = element.dataset.action
|
||||
|
||||
element.addEventListener(element.dataset.trigger, e => {
|
||||
let oldAction = element["action assigned"]
|
||||
|
||||
if(oldAction) {
|
||||
if(oldAction.trigger === actionTrigger && oldAction.action === actionName) {
|
||||
continue
|
||||
}
|
||||
|
||||
element.removeEventListener(oldAction.trigger, oldAction.handler)
|
||||
}
|
||||
|
||||
let actionHandler = e => {
|
||||
actions[actionName](this, element, e)
|
||||
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
})
|
||||
}
|
||||
|
||||
element.addEventListener(actionTrigger, actionHandler)
|
||||
|
||||
// Use "action assigned" flag instead of removing the class.
|
||||
// This will make sure that DOM diffs which restore the class name
|
||||
// will not assign the action multiple times to the same element.
|
||||
element["action assigned"] = true
|
||||
element["action assigned"] = {
|
||||
trigger: actionTrigger,
|
||||
action: actionName,
|
||||
handler: actionHandler
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user