Skip to content

Commit

Permalink
Merge pull request #63 from redaxmedia/master
Browse files Browse the repository at this point in the history
feature(events): adding events `viewport-unit-buggyfill-init` and `viewport-unit-buggyfill-style`
  • Loading branch information
rodneyrehm committed Aug 21, 2015
2 parents 07998fa + 01a18fa commit 811238f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions viewport-units-buggyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@
if (!isBuggyIE) {
isBuggyIE = !!navigator.userAgent.match(/Trident.*rv[ :]*11\./);
}

// Polyfill for creating CustomEvents on IE9/10/11
// from https://github.com/krambuhl/custom-event-polyfill
try {
new CustomEvent('test');
} catch(e) {
var CustomEvent = function(event, params) {
var evt;
params = params || {
bubbles: false,
cancelable: false,
detail: undefined
};

evt = document.createEvent('CustomEvent');
evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
};
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent; // expose definition to window
}

function debounce(func, wait) {
var timeout;
return function() {
Expand Down Expand Up @@ -119,6 +141,9 @@
};
}

// fire a custom event that buggyfill was initialize
window.dispatchEvent(new CustomEvent('viewport-units-buggyfill-init'));

options.hacks && options.hacks.initialize(options);

initialized = true;
Expand Down Expand Up @@ -151,6 +176,8 @@
styleNode.textContent = getReplacedViewportUnits();
// move to the end in case inline <style>s were added dynamically
styleNode.parentNode.appendChild(styleNode);
// fire a custom event that styles were updated
window.dispatchEvent(new CustomEvent('viewport-units-buggyfill-style'));
}

function refresh() {
Expand Down

0 comments on commit 811238f

Please sign in to comment.