From cfdf602e0f5d9ce5a58b79bdd865bbdd1daedbf8 Mon Sep 17 00:00:00 2001 From: Gabriel Loeb Date: Wed, 19 Jul 2017 21:34:51 -0400 Subject: [PATCH 1/2] Adds option to customize stylesheet attachment. --- Readme.md | 4 ++++ index.html | 6 ++++-- viewport-units-buggyfill.js | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Readme.md b/Readme.md index 532b03a..40ea201 100755 --- a/Readme.md +++ b/Readme.md @@ -99,6 +99,10 @@ viewportUnitsBuggyfill.init({refreshDebounceWait: 250}); // viewportUnitsBuggyfill.init({hacks: window.viewportUnitsBuggyfillHacks}); +// customize the DOM element the patched stylesheet is appended to +// takes a '.selector' string // default: 'head' +viewportUnitsBuggyfill.init({append: 'body'}); + // update internal declarations cache and recalculate pixel styles // this is handy when you add styles after .init() was run viewportUnitsBuggyfill.refresh(); diff --git a/index.html b/index.html index 42f618b..9cf6b25 100755 --- a/index.html +++ b/index.html @@ -23,7 +23,7 @@ - +

Note: this script will only work with browsers that have buggy implementations of viewport units and will not polyfill viewport units in older browsers (e.g. IE <= 8)

@@ -33,7 +33,9 @@ // milliseconds to delay between updates of viewport-units // caused by orientationchange, pageshow, resize events refreshDebounceWait: 250, - hacks: window.viewportUnitsBuggyfillHacks + hacks: window.viewportUnitsBuggyfillHacks, + // append to arbitrary selector + append: 'body' }); diff --git a/viewport-units-buggyfill.js b/viewport-units-buggyfill.js index f437c25..67c2d39 100755 --- a/viewport-units-buggyfill.js +++ b/viewport-units-buggyfill.js @@ -161,7 +161,7 @@ initialized = true; styleNode = document.createElement('style'); styleNode.id = 'patched-viewport'; - document.head.appendChild(styleNode); + document.querySelector(options.append ? options.append : 'head').appendChild(styleNode); // Issue #6: Cross Origin Stylesheets are not accessible through CSSOM, // therefore download and inject them as