Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom event for style updates #63

Merged
merged 5 commits into from
Aug 21, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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