Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
simplify boot, wip.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Jan 14, 2014
1 parent 10934a8 commit fcc8abe
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions src/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,43 @@ if (typeof window.CustomEvent !== 'function') {
};
}

function bootstrap() {
// TODO(sorvell): SD polyfill intrusion
var doc = window.ShadowDOMPolyfill ?
window.ShadowDOMPolyfill.wrapIfNeeded(document) : document;
// preload document resource trees
HTMLImports.importer.load(doc, function() {
HTMLImports.parser.parse(doc, function() {;
HTMLImports.ready = true;
HTMLImports.readyTime = new Date().getTime();
// send HTMLImportsLoaded when finished
//console.warn('firing HTMLImportsLoaded');
doc.dispatchEvent(
new CustomEvent('HTMLImportsLoaded', {bubbles: true})
);
})
});
// TODO(sorvell): SD polyfill intrusion
var doc = window.ShadowDOMPolyfill ?
window.ShadowDOMPolyfill.wrapIfNeeded(document) : document;

function notifyReady() {
HTMLImports.ready = true;
HTMLImports.readyTime = new Date().getTime();
// send HTMLImportsLoaded when finished
//console.warn('firing HTMLImportsLoaded');
// TODO(sorvell): event is not useful if it fires too early.
doc.dispatchEvent(
new CustomEvent('HTMLImportsLoaded', {bubbles: true})
);
}

// Allow for asynchronous loading when minified
// readyState 'interactive' is expected when loaded with 'async' or 'defer' attributes
// note: use interactive state only when not on IE since it can become
// interactive early (see https://github.com/mobify/mobifyjs/issues/136)
if (document.readyState === 'complete' ||
(document.readyState === 'interactive' && !window.attachEvent)) {
bootstrap();
if (HTMLImports.useNative) {
notifyReady();
} else {
window.addEventListener('DOMContentLoaded', bootstrap);
function bootstrap() {
// preload document resource trees
HTMLImports.importer.load(doc, function() {
HTMLImports.parser.parse(doc, function() {;
notifyReady();
})
});
}

// Allow for asynchronous loading when minified
// readyState 'interactive' is expected when loaded with 'async' or 'defer' attributes
// note: use interactive state only when not on IE since it can become
// interactive early (see https://github.com/mobify/mobifyjs/issues/136)
if (document.readyState === 'complete' ||
(document.readyState === 'interactive' && !window.attachEvent)) {
bootstrap();
} else {
window.addEventListener('DOMContentLoaded', bootstrap);
}
}

})();

0 comments on commit fcc8abe

Please sign in to comment.