Skip to content

Commit

Permalink
Add support for loading before DOMContentLoaded
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenvachon committed Aug 8, 2017
1 parent db336d9 commit c84bdc7
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions date-input-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ const addPickers = () => {
}
};

// Run the above code on any <input type="date"> in the document, also on dynamically created ones.
addPickers();

document.addEventListener(`DOMContentLoaded`, () => {
const init = () => {
// Run the above code on any <input type="date"> in the document, also on dynamically created ones.
addPickers();
});
// This is also on mousedown event so it will capture new inputs that might
// be added to the DOM dynamically.
document.querySelector(`body`).addEventListener(`mousedown`, () => {
addPickers();
});
};

// This is also on mousedown event so it will capture new inputs that might
// be added to the DOM dynamically.
document.querySelector(`body`).addEventListener(`mousedown`, () => {
addPickers();
});
if (document.readyState !== `loading`) {
init();
} else {
document.addEventListener(`DOMContentLoaded`, () => {
init();
});
}

0 comments on commit c84bdc7

Please sign in to comment.