Fix dispatchEvent for IE9/10/11

dispatchEvent doesn't work if element is not in the dom
This is not the silverbullet since an element can have a parent that is
not in the dom too, but to avoid dom update all the time, it should be
enough for very particular use cases (eg in my case unit test).
Maybe this should be moved into the test directly to be sure there is a
parent, we will see that later.
This commit is contained in:
Maxime Thirouin
2014-05-05 08:24:46 +02:00
parent 13b3485111
commit 8c05692004

View File

@@ -10,7 +10,17 @@ module.exports = function(els, events) {
event.eventName = e
forEachEls(els, function(el) {
var domFix = false
if (!el.parentNode) {
// THANKS YOU IE (9/10//11 concerned)
// dispatchEvent doesn't work if element is not in the dom
domFix = true
document.body.appendChild(el)
}
el.dispatchEvent(event)
if (domFix) {
el.parentNode.removeChild(el)
}
})
})
}