cleanup global references

This commit is contained in:
AJ Ortega
2015-06-17 17:30:35 -07:00
parent 1e997327a0
commit 88240ba9ef
9 changed files with 24 additions and 24 deletions

View File

@@ -34,6 +34,6 @@ scope.hasNative = Boolean(document.registerElement);
// NOTE: For consistent timing, use native custom elements only when not
// polyfilling other key related web components features.
scope.useNative = !flags.register && scope.hasNative &&
!window.ShadowDOMPolyfill && (!window.HTMLImports || HTMLImports.useNative);
!window.ShadowDOMPolyfill && (!window.HTMLImports || window.HTMLImports.useNative);
})(window.CustomElements);

View File

@@ -48,8 +48,8 @@ var upgradeDocumentTree = scope.upgradeDocumentTree;
// cannot be wrapped so we help the polyfill by wrapping some elements.
if (!window.wrap) {
if (window.ShadowDOMPolyfill) {
window.wrap = ShadowDOMPolyfill.wrapIfNeeded;
window.unwrap = ShadowDOMPolyfill.unwrapIfNeeded;
window.wrap = window.ShadowDOMPolyfill.wrapIfNeeded;
window.unwrap = window.ShadowDOMPolyfill.unwrapIfNeeded;
} else {
window.wrap = window.unwrap = function(node) {
return node;
@@ -61,25 +61,25 @@ if (!window.wrap) {
// bootstrap parsing
function bootstrap() {
// parse document
upgradeDocumentTree(wrap(document));
upgradeDocumentTree(window.wrap(document));
// install upgrade hook if HTMLImports are available
if (window.HTMLImports) {
HTMLImports.__importsParsingHook = function(elt) {
window.HTMLImports.__importsParsingHook = function(elt) {
upgradeDocumentTree(wrap(elt.import));
//CustomElements.parser.parse(elt.import);
};
}
// set internal 'ready' flag, now document.registerElement will trigger
// synchronous upgrades
CustomElements.ready = true;
window.CustomElements.ready = true;
// async to ensure *native* custom elements upgrade prior to this
// DOMContentLoaded can fire before elements upgrade (e.g. when there's
// an external script)
setTimeout(function() {
// capture blunt profiling data
CustomElements.readyTime = Date.now();
window.CustomElements.readyTime = Date.now();
if (window.HTMLImports) {
CustomElements.elapsed = CustomElements.readyTime - HTMLImports.readyTime;
window.CustomElements.elapsed = window.CustomElements.readyTime - window.HTMLImports.readyTime;
}
// notify the system that we are bootstrapped
document.dispatchEvent(
@@ -123,7 +123,7 @@ if (document.readyState === 'complete' || scope.flags.eager) {
// When loading at other readyStates, wait for the appropriate DOM event to
// bootstrap.
} else {
var loadEvent = window.HTMLImports && !HTMLImports.ready ?
var loadEvent = window.HTMLImports && !window.HTMLImports.ready ?
'HTMLImportsLoaded' : 'DOMContentLoaded';
window.addEventListener(loadEvent, bootstrap);
}

View File

@@ -239,10 +239,10 @@ function handler(mutations) {
pending upgrades and attached/detached callbacks synchronously.
*/
function takeRecords(node) {
node = wrap(node);
node = window.wrap(node);
// If the optional node is not supplied, assume we mean the whole document.
if (!node) {
node = wrap(document);
node = window.wrap(document);
}
// Find the root of the tree, which will be an Document or ShadowRoot.
while (node.parentNode) {
@@ -272,7 +272,7 @@ function observe(inRoot) {
// upgrade an entire document and observe it for elements changes.
function upgradeDocument(doc) {
doc = wrap(doc);
doc = window.wrap(doc);
flags.dom && console.group('upgradeDocument: ', (doc.baseURI).split('/').pop());
addedNode(doc);
observe(doc);
@@ -295,7 +295,7 @@ var originalCreateShadowRoot = Element.prototype.createShadowRoot;
if (originalCreateShadowRoot) {
Element.prototype.createShadowRoot = function() {
var root = originalCreateShadowRoot.call(this);
CustomElements.watchShadow(this);
window.CustomElements.watchShadow(this);
return root;
};
}

View File

@@ -12,7 +12,7 @@
window.CustomElements.addModule(function(scope){
// imports
var IMPORT_LINK_TYPE = window.HTMLImports ? HTMLImports.IMPORT_LINK_TYPE : 'none';
var IMPORT_LINK_TYPE = window.HTMLImports ? window.HTMLImports.IMPORT_LINK_TYPE : 'none';
// walk the subtree rooted at node, including descent into shadow-roots,
// applying 'cb' to each element
@@ -64,7 +64,7 @@ function forDocumentTree(doc, cb) {
function _forDocumentTree(doc, cb, processingDocuments) {
doc = wrap(doc);
doc = window.wrap(doc);
if (processingDocuments.indexOf(doc) >= 0) {
return;
}

View File

@@ -38,13 +38,13 @@ var useNative = Boolean(IMPORT_LINK_TYPE in document.createElement('link'));
// NOTE: ShadowDOMPolyfill intrusion.
var hasShadowDOMPolyfill = Boolean(window.ShadowDOMPolyfill);
var wrap = function(node) {
return hasShadowDOMPolyfill ? ShadowDOMPolyfill.wrapIfNeeded(node) : node;
return hasShadowDOMPolyfill ? window.ShadowDOMPolyfill.wrapIfNeeded(node) : node;
};
var rootDocument = wrap(document);
var currentScriptDescriptor = {
get: function() {
var script = HTMLImports.currentScript || document.currentScript ||
var script = window.HTMLImports.currentScript || document.currentScript ||
// NOTE: only works when called in synchronously executing code.
// readyState should check if `loading` but IE10 is
// interactive when scripts run so we cheat.
@@ -223,8 +223,8 @@ if (useNative) {
// behavior of native imports. A main document script that needs to be sure
// imports have loaded should wait for this event.
whenReady(function(detail) {
HTMLImports.ready = true;
HTMLImports.readyTime = new Date().getTime();
window.HTMLImports.ready = true;
window.HTMLImports.readyTime = new Date().getTime();
var evt = rootDocument.createEvent("CustomEvent");
evt.initCustomEvent("HTMLImportsLoaded", true, true, detail);
rootDocument.dispatchEvent(evt);

View File

@@ -61,7 +61,7 @@ var rootDocument = scope.rootDocument;
Bootstrap the imports machine.
*/
function bootstrap() {
HTMLImports.importer.bootDocument(rootDocument);
window.HTMLImports.importer.bootDocument(rootDocument);
}
// TODO(sorvell): SD polyfill does *not* generate mutations for nodes added

View File

@@ -110,8 +110,8 @@ var importParser = {
// TODO(sorvell): consider if there's a better way to do this;
// expose an imports parsing hook; this is needed, for example, by the
// CustomElements polyfill.
if (HTMLImports.__importsParsingHook) {
HTMLImports.__importsParsingHook(elt);
if (window.HTMLImports.__importsParsingHook) {
window.HTMLImports.__importsParsingHook(elt);
}
if (elt.import) {
elt.import.__importParsed = true;

View File

@@ -46,7 +46,7 @@ if (typeof HTMLTemplateElement === 'undefined') {
};
// auto-bootstrapping for main document
addEventListener('DOMContentLoaded', function() {
window.addEventListener('DOMContentLoaded', function() {
HTMLTemplateElement.bootstrap(document);
});

View File

@@ -92,7 +92,7 @@
if (HTMLImports.useNative) {
installPolymerWarning();
} else {
addEventListener('DOMContentLoaded', installPolymerWarning);
window.addEventListener('DOMContentLoaded', installPolymerWarning);
}
})(window.WebComponents);