diff --git a/platform.js b/platform.js index 2571789..52e9e16 100644 --- a/platform.js +++ b/platform.js @@ -1,62 +1,71 @@ -/* +/* * Copyright 2013 The Polymer Authors. All rights reserved. * Use of this source code is governed by a BSD-style * license that can be found in the LICENSE file. */ (function() { - + var thisFile = 'platform.js'; var scopeName = 'Platform'; -// module dependencies +function processFlags(flags) { + if (flags.build) { + // use the minified build + this.modules = ['platform.min.js']; + } else { + // truthy value for any of these flags or failure to detect native + // shadowDOM results in polyfill + flags.shadow = (flags.shadowdom || flags.shadow || flags.polyfill || + !HTMLElement.prototype.webkitCreateShadowRoot) && 'polyfill'; -var ShadowDOMNative = [ - 'src/patches-shadowdom-native.js' -]; + var ShadowDOMNative = [ + 'src/patches-shadowdom-native.js' + ]; -var ShadowDOMPolyfill = [ - '../ShadowDOM/shadowdom.js', - 'src/patches-shadowdom-polyfill.js', - 'src/ShadowCSS.js' -]; + var ShadowDOMPolyfill = [ + '../ShadowDOM/shadowdom.js', + 'src/patches-shadowdom-polyfill.js', + 'src/ShadowCSS.js' + ]; -var Lib = [ - 'src/lang.js', - 'src/dom.js', - 'src/template.js', - 'src/inspector.js', -]; + var Lib = [ + 'src/lang.js', + 'src/dom.js', + 'src/template.js', + 'src/inspector.js', + ]; -var MDV = [ - '../mdv/mdv.js', - 'src/patches-mdv.js' -]; + var MDV = [ + '../mdv/mdv.js', + 'src/patches-mdv.js' + ]; -var Pointer = [ - '../PointerGestures/pointergestures.js' -]; + var Pointer = [ + '../PointerGestures/pointergestures.js' + ]; -var WebElements = [ - '../HTMLImports/html-imports.js', - '../CustomElements/custom-elements.js', - 'src/patches-custom-elements.js' -]; + var WebElements = [ + '../HTMLImports/html-imports.js', + '../CustomElements/custom-elements.js', + 'src/patches-custom-elements.js' + ]; -function processFlags(flags) { - flags.shadow = (flags.shadowdom || flags.shadow || flags.polyfill || - !HTMLElement.prototype.webkitCreateShadowRoot) && 'polyfill'; - var ShadowDOM = flags.shadow ? ShadowDOMPolyfill : ShadowDOMNative; - this.modules = [].concat( - ShadowDOM, - Lib, - WebElements, - Pointer, - MDV - ); + // select ShadowDOM impl + var ShadowDOM = flags.shadow ? ShadowDOMPolyfill : ShadowDOMNative; + + // construct active dependency list + this.modules = [].concat( + ShadowDOM, + Lib, + WebElements, + Pointer, + MDV + ); + } } -// export +// export window[scopeName] = { entryPointName: thisFile, @@ -72,7 +81,7 @@ var basePath = src.slice(0, src.indexOf(thisFile)); if (!window.Loader) { var path = basePath + 'tools/loader/loader.js'; document.write(''); -} +} document.write(''); - + })(); diff --git a/src/ShadowCSS.js b/src/ShadowCSS.js index bb59b6e..28e49df 100644 --- a/src/ShadowCSS.js +++ b/src/ShadowCSS.js @@ -57,7 +57,7 @@ becomes: - Alternatively, if Polymer.strictPolyfillStyling is set to true then + Alternatively, if Platform.ShadowCSS.strictStyling is set to true then selectors are scoped by adding an attribute selector suffix to each simple selector that contains the host element tag name. Each element in the element's ShadowDOM template is also given the scope attribute. diff --git a/src/patches-mdv.js b/src/patches-mdv.js index 78167df..a7eb599 100644 --- a/src/patches-mdv.js +++ b/src/patches-mdv.js @@ -11,18 +11,9 @@ style.textContent = 'template {display: none !important;} /* injected by platfor var head = document.querySelector('head'); head.insertBefore(style, head.firstChild); -// MDV hook for processing created dom before bindings are made. We upgrade -// so custom elements get a chance to deal with bindings mdv is about to make. -HTMLTemplateElement.__instanceCreated = function(inNode) { - // TODO(sorvell): workaround for - // https://code.google.com/p/chromium/issues/detail?id=229125 - document.adoptNode(inNode); - CustomElements.upgradeAll(inNode); -}; - // dirtyCheck (with logging) function dirtyCheck() { - logFlags.data && console.group("Model.dirtyCheck()"); + logFlags.data && console.group("Platform.performMicrotaskCheckpoint()"); check(); logFlags.data && console.groupEnd(); }; @@ -45,7 +36,7 @@ window.addEventListener('WebComponentsReady', function() { // dirty check periodically if platform does not have object observe. if (!Observer.hasObjectObserve) { - setInterval(check, dirtyCheckPollInterval); + scope.dirtyPoll = setInterval(check, dirtyCheckPollInterval); } }); diff --git a/src/patches-shadowdom-native.js b/src/patches-shadowdom-native.js index 5518bba..bf01ae2 100644 --- a/src/patches-shadowdom-native.js +++ b/src/patches-shadowdom-native.js @@ -15,6 +15,16 @@ window.wrap = window.unwrap = function(n){ return n; } + + var originalCreateShadowRoot = HTMLElement.prototype.webkitCreateShadowRoot; + HTMLElement.prototype.webkitCreateShadowRoot = function() { + var elderRoot = this.webkitShadowRoot; + var root = originalCreateShadowRoot.call(this); + root.olderShadowRoot = elderRoot; + root.host = this; + CustomElements.watchShadow(this); + return root; + } Object.defineProperties(HTMLElement.prototype, { shadowRoot: { diff --git a/src/patches-shadowdom-polyfill.js b/src/patches-shadowdom-polyfill.js index 89d2379..52d5029 100644 --- a/src/patches-shadowdom-polyfill.js +++ b/src/patches-shadowdom-polyfill.js @@ -43,6 +43,14 @@ } } }); + + // include .host reference + var originalCreateShadowRoot = HTMLElement.prototype.createShadowRoot; + HTMLElement.prototype.createShadowRoot = function() { + var root = originalCreateShadowRoot.call(this); + root.host = this; + return root; + } //TODO(sjmiles): review method alias with Arv HTMLElement.prototype.webkitCreateShadowRoot =