mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
Correctly handle DOM Ready states
Previously, if the script was loaded while in `document.readyState` of `interactive`, the `domReady` function is never called. See https://developer.mozilla.org/en-US/docs/Web/API/document.readyState for explanation of the proper detection of `DOMContentLoaded`
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
(function(window, document, ionic) {
|
||||
|
||||
var readyCallbacks = [];
|
||||
var isDomReady = false;
|
||||
var isDomReady = document.readyState === 'complete' || document.readyState === 'interactive';
|
||||
|
||||
function domReady() {
|
||||
isDomReady = true;
|
||||
@@ -11,7 +11,10 @@
|
||||
readyCallbacks = [];
|
||||
document.removeEventListener('DOMContentLoaded', domReady);
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', domReady);
|
||||
if (!isDomReady){
|
||||
document.addEventListener('DOMContentLoaded', domReady);
|
||||
}
|
||||
|
||||
|
||||
// From the man himself, Mr. Paul Irish.
|
||||
// The requestAnimationFrame polyfill
|
||||
@@ -110,7 +113,7 @@
|
||||
* @param {function} callback The function to be called.
|
||||
*/
|
||||
ready: function(cb) {
|
||||
if(isDomReady || document.readyState === "complete") {
|
||||
if(isDomReady) {
|
||||
ionic.requestAnimationFrame(cb);
|
||||
} else {
|
||||
readyCallbacks.push(cb);
|
||||
|
||||
Reference in New Issue
Block a user