Skip to content

Instantly share code, notes, and snippets.

@staaky
Created November 14, 2008 13:17
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 staaky/24895 to your computer and use it in GitHub Desktop.
Save staaky/24895 to your computer and use it in GitHub Desktop.
var Feature = (function() {
var tests = {
DOCUMENT_GETELEMENTBYID_CONFUSES_IDS_WITH_NAMES: function() {
// need to feature test all these DOM methods before calling them
var num = Number(new Date()),
name = '__test_' + num,
head = document.getElementsByTagName('head')[0],
isBuggy = false,
el;
try {
el = document.createElement('<input name="'+ name +'">');
} catch(e) {
el = document.createElement('input');
el.name = name;
}
head.appendChild(el);
var testElement = document.getElementById(name);
isBuggy = !!(testElement && (testElement.nodeName.toUpperCase() === 'INPUT'));
head.removeChild(el);
el = null;
return isBuggy;
},
NEWLINES_IGNORED_AS_INNERHTML_OF_PRE_ELEMENT: function(){
var element = document.createElement('pre'),
isIgnored = false;
if (element) {
element.innerHTML = 'a\nb';
isIgnored = (element.innerHTML.charAt(1) !== '\n');
element = null;
}
return isIgnored;
},
STRING_PROTOTYPE_REPLACE_IGNORES_FUNCTIONS: function() {
return 'a'.replace('a', function(){ return '' }).length !== 0;
},
IS_TAGNAME_UPPERCASED: function() {
return /[A-Z]/.test(document.documentElement.tagName);
}
// etc. sections, documentation...
};
// make sure tests run only once
Object.keys(tests)._each(function(test) {
tests[test] = tests[test].wrap(function(proceed) {
var result = proceed();
tests[test] = function() { return result };
return result;
});
});
function test(name) {
return tests[name]();
}
return {
tests: tests, // could leave this out
test: test
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment