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

Commit

Permalink
manage import load tracking more carefully
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Jan 21, 2014
1 parent 6522703 commit 3f4ca5c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/HTMLImports.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ if (!useNative) {
}
// don't store import record until we're actually loaded
// store document resource
elt.content = resource = document;
elt.import = elt.content = resource = document;
}
// store generic resource
// TODO(sorvell): fails for nodes inside <template>.content
Expand Down Expand Up @@ -213,7 +213,7 @@ function whenImportsReady(callback, doc) {
}
var imports = doc.querySelectorAll('link[rel=import');
var loaded = 0, l = imports.length;
function checkDone(d) {
function checkDone(d) {
if (loaded == l) {
// go async to ensure parser isn't stuck on a script tag
requestAnimationFrame(callback);
Expand All @@ -230,6 +230,7 @@ function whenImportsReady(callback, doc) {
loadedImport.call(imp);
} else {
imp.addEventListener('load', loadedImport);
imp.addEventListener('error', loadedImport);
}
}
} else {
Expand All @@ -238,7 +239,8 @@ function whenImportsReady(callback, doc) {
}

function isImportLoaded(link) {
return link.import && (link.import.readyState !== 'loading');
return useNative ? (link.import && (link.import.readyState !== 'loading')) :
link.__importParsed;
}

// exports
Expand Down
4 changes: 2 additions & 2 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var path = scope.path;

var IMPORT_LINK_TYPE = 'import';
var isIe = /Trident/.test(navigator.userAgent)

// highlander object for parsing a document tree

var importParser = {
Expand Down Expand Up @@ -63,14 +64,13 @@ var importParser = {
this.trackElement(linkElt);
if (linkElt.__resource) {
importParser.parse(linkElt.__resource, function() {
// import is now ready so make available
linkElt.import = linkElt.__resource;
// fire load event
linkElt.dispatchEvent(new CustomEvent('load', {bubbles: false}));
});
} else {
linkElt.dispatchEvent(new CustomEvent('error', {bubbles: false}));
}
linkElt.__importParsed = true;
} else {
// make href relative to main document
if (needsMainDocumentContext(linkElt)) {
Expand Down

0 comments on commit 3f4ca5c

Please sign in to comment.