modernizr.custom.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* Modernizr 2.6.2 (Custom Build) | MIT & BSD
  2. * Build: http://modernizr.com/download/#-input-addtest-teststyles
  3. */
  4. ;
  5. window.Modernizr = (function( window, document, undefined ) {
  6. var version = '2.6.2',
  7. Modernizr = {},
  8. docElement = document.documentElement,
  9. mod = 'modernizr',
  10. modElem = document.createElement(mod),
  11. mStyle = modElem.style,
  12. inputElem = document.createElement('input') ,
  13. toString = {}.toString, tests = {},
  14. inputs = {},
  15. attrs = {},
  16. classes = [],
  17. slice = classes.slice,
  18. featureName,
  19. injectElementWithStyles = function( rule, callback, nodes, testnames ) {
  20. var style, ret, node, docOverflow,
  21. div = document.createElement('div'),
  22. body = document.body,
  23. fakeBody = body || document.createElement('body');
  24. if ( parseInt(nodes, 10) ) {
  25. while ( nodes-- ) {
  26. node = document.createElement('div');
  27. node.id = testnames ? testnames[nodes] : mod + (nodes + 1);
  28. div.appendChild(node);
  29. }
  30. }
  31. style = ['&#173;','<style id="s', mod, '">', rule, '</style>'].join('');
  32. div.id = mod;
  33. (body ? div : fakeBody).innerHTML += style;
  34. fakeBody.appendChild(div);
  35. if ( !body ) {
  36. fakeBody.style.background = '';
  37. fakeBody.style.overflow = 'hidden';
  38. docOverflow = docElement.style.overflow;
  39. docElement.style.overflow = 'hidden';
  40. docElement.appendChild(fakeBody);
  41. }
  42. ret = callback(div, rule);
  43. if ( !body ) {
  44. fakeBody.parentNode.removeChild(fakeBody);
  45. docElement.style.overflow = docOverflow;
  46. } else {
  47. div.parentNode.removeChild(div);
  48. }
  49. return !!ret;
  50. },
  51. _hasOwnProperty = ({}).hasOwnProperty, hasOwnProp;
  52. if ( !is(_hasOwnProperty, 'undefined') && !is(_hasOwnProperty.call, 'undefined') ) {
  53. hasOwnProp = function (object, property) {
  54. return _hasOwnProperty.call(object, property);
  55. };
  56. }
  57. else {
  58. hasOwnProp = function (object, property) {
  59. return ((property in object) && is(object.constructor.prototype[property], 'undefined'));
  60. };
  61. }
  62. if (!Function.prototype.bind) {
  63. Function.prototype.bind = function bind(that) {
  64. var target = this;
  65. if (typeof target != "function") {
  66. throw new TypeError();
  67. }
  68. var args = slice.call(arguments, 1),
  69. bound = function () {
  70. if (this instanceof bound) {
  71. var F = function(){};
  72. F.prototype = target.prototype;
  73. var self = new F();
  74. var result = target.apply(
  75. self,
  76. args.concat(slice.call(arguments))
  77. );
  78. if (Object(result) === result) {
  79. return result;
  80. }
  81. return self;
  82. } else {
  83. return target.apply(
  84. that,
  85. args.concat(slice.call(arguments))
  86. );
  87. }
  88. };
  89. return bound;
  90. };
  91. }
  92. function setCss( str ) {
  93. mStyle.cssText = str;
  94. }
  95. function setCssAll( str1, str2 ) {
  96. return setCss(prefixes.join(str1 + ';') + ( str2 || '' ));
  97. }
  98. function is( obj, type ) {
  99. return typeof obj === type;
  100. }
  101. function contains( str, substr ) {
  102. return !!~('' + str).indexOf(substr);
  103. }
  104. function testDOMProps( props, obj, elem ) {
  105. for ( var i in props ) {
  106. var item = obj[props[i]];
  107. if ( item !== undefined) {
  108. if (elem === false) return props[i];
  109. if (is(item, 'function')){
  110. return item.bind(elem || obj);
  111. }
  112. return item;
  113. }
  114. }
  115. return false;
  116. }
  117. function webforms() {
  118. Modernizr['input'] = (function( props ) {
  119. for ( var i = 0, len = props.length; i < len; i++ ) {
  120. attrs[ props[i] ] = !!(props[i] in inputElem);
  121. }
  122. if (attrs.list){
  123. attrs.list = !!(document.createElement('datalist') && window.HTMLDataListElement);
  124. }
  125. return attrs;
  126. })('autocomplete autofocus list placeholder max min multiple pattern required step'.split(' '));
  127. }
  128. for ( var feature in tests ) {
  129. if ( hasOwnProp(tests, feature) ) {
  130. featureName = feature.toLowerCase();
  131. Modernizr[featureName] = tests[feature]();
  132. classes.push((Modernizr[featureName] ? '' : 'no-') + featureName);
  133. }
  134. }
  135. Modernizr.input || webforms();
  136. Modernizr.addTest = function ( feature, test ) {
  137. if ( typeof feature == 'object' ) {
  138. for ( var key in feature ) {
  139. if ( hasOwnProp( feature, key ) ) {
  140. Modernizr.addTest( key, feature[ key ] );
  141. }
  142. }
  143. } else {
  144. feature = feature.toLowerCase();
  145. if ( Modernizr[feature] !== undefined ) {
  146. return Modernizr;
  147. }
  148. test = typeof test == 'function' ? test() : test;
  149. if (typeof enableClasses !== "undefined" && enableClasses) {
  150. docElement.className += ' ' + (test ? '' : 'no-') + feature;
  151. }
  152. Modernizr[feature] = test;
  153. }
  154. return Modernizr;
  155. };
  156. setCss('');
  157. modElem = inputElem = null;
  158. Modernizr._version = version;
  159. Modernizr.testStyles = injectElementWithStyles;
  160. return Modernizr;
  161. })(this, this.document);
  162. ;