Skip to content

Instantly share code, notes, and snippets.

@THEtheChad
Last active December 16, 2015 13:48
Show Gist options
  • Save THEtheChad/5443812 to your computer and use it in GitHub Desktop.
Save THEtheChad/5443812 to your computer and use it in GitHub Desktop.
Cross browser method for detecting prefix.
(function(window){
var styles = window.getComputedStyle(document.documentElement, '')
, pre = (Array.prototype.slice
.call(styles)
.join('')
.match(/-(moz|webkit|ms)-/) || (styles.OLink === '' && ['', 'o'])
)[1]
, dom = ('WebKit|Moz|MS|O').match(new RegExp('(' + pre + ')', 'i'))[1]
, capitalize = function(str){ return str.charAt(0).toUpperCase() + str.substring(1) }
;//var
if(pre)
window.prefix = function(prop){ return pre + capitalize(prop) }
else
window.prefix = function(prop){ return prop }
window.prefix.dom = dom;
window.prefix.lowercase = pre;
window.prefix.css = '-' + pre + '-';
window.prefix.js = capitalize(pre);
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment