Skip to content

Commit

Permalink
Fixed DOMContentLoaded failing to fire
Browse files Browse the repository at this point in the history
  • Loading branch information
lski committed Mar 27, 2016
1 parent 42b42f8 commit 20be7c9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dist/addeventlistener-with-dispatch.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "addeventlistener-with-dispatch",
"version": "1.0.1",
"version": "1.0.2",
"description": "addEventListener, removeEventListener, dispatchEvent and DOMContentLoaded polyfill for IE8",
"main": "./dist/addeventlistener-with-dispatch.js",
"scripts": {
Expand Down
10 changes: 3 additions & 7 deletions src/addeventlistener-with-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,28 +116,24 @@
// So we wrap the already wrapper listener to check it is the complete state before calling the wrapped listener
var documentCompleteWrapper = function documentCompleteWrapper(e) {

// Using interactive, although there is an issue in IE9/10 that means interactive fires too early, this isnt an issue in IE8
// As we are not shimming above 8 because this is an addEventListener polyfill thats already present in IE9 we dont need to worry
if (document.readyState === "interactive") {
// Check if the the change was to say the document is in a useable state
if (/loaded|complete/.test(document.readyState)) {
wrapper(e);
}
};

// Test at the latest possible moment its loaded
if (!/interactive|complete|loaded/.test(document.readyState)) {
if (!/loaded|complete/.test(document.readyState)) {
document.attachEvent("onreadystatechange", documentCompleteWrapper);
eventListeners.push({ object: _thisElement, type: type, listener: listener, wrapper: documentCompleteWrapper });
}

}
else {
_thisElement.attachEvent("on" + type, wrapper);
eventListeners.push({ object: _thisElement, type: type, listener: listener, wrapper: wrapper });
}
};



var removeEventListener = function removeEventListener(type, listener /*, useCapture (will be ignored) */) {

var counter = 0;
Expand Down

0 comments on commit 20be7c9

Please sign in to comment.