Skip to content

Instantly share code, notes, and snippets.

@Dagothig
Last active April 4, 2016 20:35
Show Gist options
  • Save Dagothig/f92275ad66cfcfae845b0bc40a8f4a2c to your computer and use it in GitHub Desktop.
Save Dagothig/f92275ad66cfcfae845b0bc40a8f4a2c to your computer and use it in GitHub Desktop.
For those times where prefixing is not your cup of tea
// Note that unprefixing elements that aren't initially defined will break them
// (which is why it conditionnally unprefixes pointerLockElement)
function unprefix(element:any, prop:string, prefixes:string[]) {
let capitalized = prop[0].toUpperCase() + prop.substring(1);
let props = prefixes.map(prefix => prefix + capitalized);
if (!element[prop]) return Object.defineProperty(element, prop, {
get: function() {
for (let prop of props) {
var val = this[prop];
if (val) return val;
}
},
set: function(val) {
props.forEach(prop => this[prop] = val);
}
});
return false;
}
if (unprefix(Element.prototype, 'requestPointerLock', ['moz', 'webkit']))
unprefix(document, 'pointerLockElement', ['moz', 'webkit']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment