Last active
April 4, 2016 20:35
-
-
Save Dagothig/f92275ad66cfcfae845b0bc40a8f4a2c to your computer and use it in GitHub Desktop.
For those times where prefixing is not your cup of tea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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