Created
May 4, 2012 13:05
-
-
Save hongymagic/2594705 to your computer and use it in GitHub Desktop.
Determine the prefix of the browser: o, moz, webkit, ms
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
| /*jslint devel: false, browser: true, sloppy: true, maxerr: 50, indent: 4 */ | |
| // | |
| // `PREFIX` variable will most likely be one of the following: | |
| // [o, moz, ms, webkit] | |
| // | |
| var PREFIX = (function (window, document) { | |
| // Get computed styles from the document to assess names of the CSS properties | |
| var styles = window.getComputedStyle(document.documentElement, null), | |
| i, | |
| l, | |
| style, | |
| prefix, | |
| // A register to keep track of the count of most common prefix | |
| highest = 0, | |
| // The most common prefix | |
| result, | |
| // prefixes = {} works here too | |
| prefixes = Object.create(null); | |
| for (i = 0, l = styles.length; i < l; i += 1) { | |
| // Run through each CSS property and determine its prefix which is assumed to have | |
| // the format: -prefix-css-property | |
| style = styles[i] || ''; | |
| prefix = style.split('-')[1]; | |
| if (prefix) { | |
| if (!prefixes[prefix]) { | |
| prefixes[prefix] = 0; | |
| } | |
| prefixes[prefix] += 1; | |
| if (highest < prefixes[prefix]) { | |
| highest = prefixes[prefix]; | |
| result = prefix; | |
| } | |
| } | |
| } | |
| return result; | |
| }(window, window.document)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment