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

Commit

Permalink
provide _currentScript on document and SD polyfill document. Fixes #45.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Jan 29, 2014
1 parent 1cdcef2 commit 8703f0f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/HTMLImports.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,26 @@ if (!useNative) {
// do nothing if using native imports
}

var wrappedDoc = window.ShadowDOMPolyfill ? wrap(document) : document;


// NOTE: We cannot polyfill document.currentScript because it's not possible
// both to override and maintain the ability to capture the native value;
// therefore we choose to expose _currentScript both when native imports
// and the polyfill are in use.
Object.defineProperty(wrappedDoc, '_currentScript', {
var currentScriptDescriptor = {
get: function() {
return HTMLImports.currentScript || wrappedDoc.currentScript;
return HTMLImports.currentScript || document.currentScript;
},
writeable: true,
configurable: true
});
}

Object.defineProperty(document, '_currentScript', currentScriptDescriptor);
Object.defineProperty(mainDoc, '_currentScript', currentScriptDescriptor);

// TODO(sorvell): multiple calls will install multiple event listeners
// which may not be desireable; calls should resolve in the correct order,
// however.
function whenImportsReady(callback, doc) {
doc = doc || wrappedDoc;
doc = doc || mainDoc;
// if document is loading, wait and try again
var requiredState = HTMLImports.isIE ? 'complete' : 'interactive';
var isReady = (doc.readyState === 'complete' ||
Expand Down

0 comments on commit 8703f0f

Please sign in to comment.