diff --git a/README.md b/README.md index 0a0893a..8948428 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,15 @@ An iframe based Shadow DOM poorlyfill * the `` element (under consideration) * if you `shadowRoot.innerHTML = "

"` DOM Level 0 events won't ever propagate (inconsistent with real Shadow DOM, just don't do that or simply use [hyperHTML](https://github.com/WebReflection/hyperHTML) instead that will use `addEventListener`) +```js +hyperHTML(el.shadowRoot) + `

console.log('🎉')}>

`; +``` + ### What this is not * this is not a Custom Elements or an HTMLTemplateElement polyfill. This is only the `attachShadow` method. - * this is not, and never could be, a 100% reliable polyfill for Shadow DOM, for the simple reason that Shadow DOM cannot be polyfilled (this is _a poorlyfill_ indeed, with its caveats and compromises) + * this is not, and never could be, a 100% fully standard Shadow DOM polyfill, for the simple reason that Shadow DOM cannot be polyfilled (this is _a poorlyfill_ indeed, with its caveats and compromises) * not yet a battle tested solution. If you have any experience with _iframe_ shenanigans please help making this poorlyfill less poor, thank you! ### CDN diff --git a/index.js b/index.js index 9cc3f74..7b65dc2 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,8 @@ // ensure unique id var counter = 0; + var defineProperties = Object.defineProperties; + // add the shadowReset rules to the current document headOf(document).insertBefore( document.createElement('style'), @@ -46,7 +48,8 @@ // create a shadowRoot via the appended iframe var shadowRoot = new ShadowContent(this.appendChild(iframe), options); // and attach it if mode is open - if (options.mode === 'open') this.shadowRoot = shadowRoot; + if (options.mode === 'open') + defineProperties(this, {shadowRoot: {value: shadowRoot}}); return shadowRoot; }; @@ -163,7 +166,7 @@ descriptors.textContent = indirectAccessor(viaBody, 'textContent'); // attaching all delegates to the returned instance - Object.defineProperties(this, descriptors); + defineProperties(this, descriptors); // attach to the iframe some information used on onload var id = uid(); diff --git a/min.js b/min.js index e99999a..5dba912 100644 --- a/min.js +++ b/min.js @@ -1,2 +1,2 @@ -/*! (c) Andrea Giammarchi (ISC) */!function(t,e){"use strict";function n(t){return t.head||t.getElementsByTagName("head")[0]}function i(t,e){return{get:function(){return t()[e]},set:function(n){t()[e]=n}}}function o(t,e,n){var i=e.offsetWidth,o=e.offsetHeight;this.width!==i&&(t.width=(this.width=i)+"px"),this.height!==o&&(t.height=(this.height=o)+"px"),n()}function a(){for(var t=0,e=this.length;t-1&&(S.call(this,t,e,i),S.call(n,t,o.d[a],i),o.s.splice(a,1),o.d.splice(a,1))};for(var i,o=0;o min.js", @@ -25,6 +25,6 @@ }, "homepage": "https://github.com/WebReflection/attachshadow#readme", "devDependencies": { - "uglify-js": "^2.8.29" + "uglify-js": "^3.8.0" } } diff --git a/test/index.html b/test/index.html index 49ed7d6..597d951 100644 --- a/test/index.html +++ b/test/index.html @@ -3,7 +3,7 @@ attachShadow: An iframe based Shadow DOM poorlyfill - +