Skip to content

Commit

Permalink
fixing double initialization and call of reresh() without being initi…
Browse files Browse the repository at this point in the history
…alized - closes #3
  • Loading branch information
rodneyrehm committed Mar 10, 2014
1 parent ac96ef2 commit b6c3981
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions viewport-units-buggyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
'use strict';
/*global document, window*/

var initialized = false;
var viewportUnitExpression = /([0-9.-]+)(vh|vw|vmin|vmax)/g;
var forEach = [].forEach;
var join = [].join;
Expand All @@ -29,11 +30,12 @@
var styleNode;

function initialize(force) {
if (!force && !/ip.+mobile.+safari/i.test(window.navigator.userAgent)) {
if (initialized || (!force && !/ip.+mobile.+safari/i.test(window.navigator.userAgent))) {
// this buggyfill only applies to mobile safari
return;
}


initialized = true;
styleNode = document.createElement('style');
styleNode.id = 'patched-viewport';
document.head.appendChild(styleNode);
Expand All @@ -50,6 +52,9 @@
}

function refresh() {
if (!initialized) {
return;
}
findProperties();
updateStyles();
}
Expand Down

0 comments on commit b6c3981

Please sign in to comment.