Skip to content

Instantly share code, notes, and snippets.

@zerosignalproductions
Created July 23, 2013 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerosignalproductions/6063449 to your computer and use it in GitHub Desktop.
Save zerosignalproductions/6063449 to your computer and use it in GitHub Desktop.
Detect the vendor prefix and return it as an object. Source: http://davidwalsh.name/vendor-prefix
var prefix = (function () {
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];
return {
dom: dom,
lowercase: pre,
css: '-' + pre + '-',
js: pre[0].toUpperCase() + pre.substr(1)
};
})();
var prefix = (function () {
var styles = window.getComputedStyle(document.documentElement, ''),
pre = (Array.prototype.slice
.call(styles)
.join('')
.match(/-(moz|webkit|ms)-/) || (styles.OLink === '' && ['', 'o'])
)[1],
return '-' + pre + '-';
};
})();
@toddpress
Copy link

This is great, man. You should just remove closing curly on line 9, and replace the comma after pre's definition (i.e. '[1];'). Other than that, worked beautifully. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment