staaky (owner)

Revisions

gist: 24895 Download_button fork
public
Public Clone URL: git://gist.github.com/24895.git
Embed All Files: show embed
Text only #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
  };
})();