Skip to content

Commit

Permalink
Resolve issue #4 on multiple event handlers per element
Browse files Browse the repository at this point in the history
  • Loading branch information
smcmurray committed Mar 27, 2018
1 parent 2e846ba commit 02f04d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/kata.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function(s, ...expr){
if (q && strings[0]){
strings[0] = strings[0].replace(quote[q], '')
}
return ` ${ehs}="${i}"`
return ` ${ehs}-${event}="${i}"`
})
}
else {
Expand All @@ -37,11 +37,13 @@ export default function(s, ...expr){
}
predoc+=strings.shift()
let doc = document.createRange().createContextualFragment(predoc.trim())
doc.querySelectorAll(`*[${ehs}]`).forEach(e=>{
let h = handlers[e.getAttribute(ehs)]
e.addEventListener(h.event, h.handler)
e.removeAttribute(ehs)
})
for (let e of new Set(handlers.map(h=>h.event))){
for (let el of Array.from(doc.querySelectorAll(`*[${ehs}-${e}]`))){
let h = handlers[el.getAttribute(`${ehs}-${e}`)]
el.addEventListener(h.event, h.handler)
el.removeAttribute(`${ehs}-${e}`)
}
}
let m,n,walker = document.createNodeIterator(doc, NodeFilter.SHOW_COMMENT, { acceptNode: function(n){if (m = n.textContent.match(cf)) return NodeFilter.FILTER_ACCEPT} })
while (n=walker.nextNode()) n.replaceWith(embeds[m[1]])
return 1==doc.childNodes.length ? doc.firstChild : doc
Expand Down

0 comments on commit 02f04d8

Please sign in to comment.