| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright 2013 The Polymer Authors. All rights reserved. | |
| 3 * Use of this source code is governed by a BSD-style | |
| 4 * license that can be found in the LICENSE file. | |
| 5 */ | |
| 6 (function() { | |
| 7 var ShadowDOMPolyfill = window.ShadowDOMPolyfill; | |
| 8 var wrap = ShadowDOMPolyfill.wrap; | |
| 9 | |
| 10 // patch in prefixed name | |
| 11 Object.defineProperties(HTMLElement.prototype, { | |
| 12 //TODO(sjmiles): review accessor alias with Arv | |
| 13 webkitShadowRoot: { | |
| 14 get: function() { | |
| 15 return this.shadowRoot; | |
| 16 } | |
| 17 } | |
| 18 }); | |
| 19 | |
| 20 // ShadowCSS needs this: | |
| 21 window.wrap = window.ShadowDOMPolyfill.wrap; | |
| 22 window.unwrap = window.ShadowDOMPolyfill.unwrap; | |
| 23 | |
| 24 //TODO(sjmiles): review method alias with Arv | |
| 25 HTMLElement.prototype.webkitCreateShadowRoot = | |
| 26 HTMLElement.prototype.createShadowRoot; | |
| 27 | |
| 28 // TODO(jmesserly): we need to wrap document somehow (a dart:html hook?) | |
| 29 window.dartExperimentalFixupGetTag = function(originalGetTag) { | |
| 30 var NodeList = ShadowDOMPolyfill.wrappers.NodeList; | |
| 31 var ShadowRoot = ShadowDOMPolyfill.wrappers.ShadowRoot; | |
| 32 var unwrapIfNeeded = ShadowDOMPolyfill.unwrapIfNeeded; | |
| 33 function getTag(obj) { | |
| 34 // TODO(jmesserly): do we still need these? | |
| 35 if (obj instanceof NodeList) return 'NodeList'; | |
| 36 if (obj instanceof ShadowRoot) return 'ShadowRoot'; | |
| 37 if (window.MutationRecord && (obj instanceof MutationRecord)) | |
| 38 return 'MutationRecord'; | |
| 39 if (window.MutationObserver && (obj instanceof MutationObserver)) | |
| 40 return 'MutationObserver'; | |
| 41 | |
| 42 // TODO(jmesserly): this prevents incorrect interaction between ShadowDOM | |
| 43 // and dart:html's <template> polyfill. Essentially, ShadowDOM is | |
| 44 // polyfilling native template, but our Dart polyfill fails to detect this | |
| 45 // because the unwrapped node is an HTMLUnknownElement, leading it to | |
| 46 // think the node has no content. | |
| 47 if (obj instanceof HTMLTemplateElement) return 'HTMLTemplateElement'; | |
| 48 | |
| 49 var unwrapped = unwrapIfNeeded(obj); | |
| 50 if (obj !== unwrapped) { | |
| 51 // Fix up class names for Firefox. | |
| 52 // For some of them (like HTMLFormElement and HTMLInputElement), | |
| 53 // the "constructor" property of the unwrapped nodes points at the | |
| 54 // same constructor as the wrapper. | |
| 55 var ctor = obj.constructor | |
| 56 if (ctor === unwrapped.constructor) { | |
| 57 var name = ctor._ShadowDOMPolyfill$cacheTag_; | |
| 58 if (!name) { | |
| 59 name = Object.prototype.toString.call(unwrapped); | |
| 60 name = name.substring(8, name.length - 1); | |
| 61 ctor._ShadowDOMPolyfill$cacheTag_ = name; | |
| 62 } | |
| 63 return name; | |
| 64 } | |
| 65 | |
| 66 obj = unwrapped; | |
| 67 } | |
| 68 return originalGetTag(obj); | |
| 69 } | |
| 70 | |
| 71 return getTag; | |
| 72 }; | |
| 73 })(); | |
| OLD | NEW |