Created
January 5, 2014 18:41
-
-
Save agaase/8272091 to your computer and use it in GitHub Desktop.
Tests for native support of a browser property in a specific context
This file contains 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
function getPrefix(prop, context) { | |
var vendorPrefixes = ['moz', 'webkit', 'khtml', 'o', 'ms'], | |
upper = prop.charAt(0).toUpperCase() + prop.slice(1), | |
pref, len = vendorPrefixes.length, | |
q = null; | |
while (len--) { | |
q = vendorPrefixes[len]; | |
if (context.toString().indexOf('style')) { | |
q = q.charAt(0).toUpperCase() + q.slice(1); | |
} | |
if ((q + upper) in context) { | |
pref = (q); | |
} | |
} | |
if (prop in context) { | |
pref = prop; | |
} | |
if (pref) { | |
return '-' + pref.toLowerCase() + '-'; | |
} | |
return ''; | |
} | |
//LocalStorage test | |
console.log(getPrefix('localStorage', window)); | |
//Page Visibility API | |
console.log(getPrefix('hidden', document)); | |
//CSS3 transforms | |
console.log(getPrefix('transform', document.createElement('div').style)); | |
//CSS3 transitions | |
console.log(getPrefix('transition', document.createElement('div').style)); | |
//File API test (very basic test, ideally check against 'File' too) | |
console.log(getPrefix('FileReader', window)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment