You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

379 lines
9.8 KiB

  1. /* Modernizr 2.7.1 (Custom Build) | MIT & BSD
  2. * Build: http://modernizr.com/download/#-csstransforms-canvas-canvastext-draganddrop-inlinesvg-svg-svgclippaths-touch-teststyles-testprop-testallprops-hasevent-prefixes-domprefixes-url_data_uri
  3. */
  4. ;
  5. var Modernizr = (function( window, document, undefined ) {
  6. var version = '2.7.1',
  7. Modernizr = {},
  8. docElement = document.documentElement,
  9. mod = 'modernizr',
  10. modElem = document.createElement(mod),
  11. mStyle = modElem.style,
  12. inputElem ,
  13. toString = {}.toString,
  14. prefixes = ' -webkit- -moz- -o- -ms- '.split(' '),
  15. omPrefixes = 'Webkit Moz O ms',
  16. cssomPrefixes = omPrefixes.split(' '),
  17. domPrefixes = omPrefixes.toLowerCase().split(' '),
  18. ns = {'svg': 'http://www.w3.org/2000/svg'},
  19. tests = {},
  20. inputs = {},
  21. attrs = {},
  22. classes = [],
  23. slice = classes.slice,
  24. featureName,
  25. injectElementWithStyles = function( rule, callback, nodes, testnames ) {
  26. var style, ret, node, docOverflow,
  27. div = document.createElement('div'),
  28. body = document.body,
  29. fakeBody = body || document.createElement('body');
  30. if ( parseInt(nodes, 10) ) {
  31. while ( nodes-- ) {
  32. node = document.createElement('div');
  33. node.id = testnames ? testnames[nodes] : mod + (nodes + 1);
  34. div.appendChild(node);
  35. }
  36. }
  37. style = ['&#173;','<style id="s', mod, '">', rule, '</style>'].join('');
  38. div.id = mod;
  39. (body ? div : fakeBody).innerHTML += style;
  40. fakeBody.appendChild(div);
  41. if ( !body ) {
  42. fakeBody.style.background = '';
  43. fakeBody.style.overflow = 'hidden';
  44. docOverflow = docElement.style.overflow;
  45. docElement.style.overflow = 'hidden';
  46. docElement.appendChild(fakeBody);
  47. }
  48. ret = callback(div, rule);
  49. if ( !body ) {
  50. fakeBody.parentNode.removeChild(fakeBody);
  51. docElement.style.overflow = docOverflow;
  52. } else {
  53. div.parentNode.removeChild(div);
  54. }
  55. return !!ret;
  56. },
  57. isEventSupported = (function() {
  58. var TAGNAMES = {
  59. 'select': 'input', 'change': 'input',
  60. 'submit': 'form', 'reset': 'form',
  61. 'error': 'img', 'load': 'img', 'abort': 'img'
  62. };
  63. function isEventSupported( eventName, element ) {
  64. element = element || document.createElement(TAGNAMES[eventName] || 'div');
  65. eventName = 'on' + eventName;
  66. var isSupported = eventName in element;
  67. if ( !isSupported ) {
  68. if ( !element.setAttribute ) {
  69. element = document.createElement('div');
  70. }
  71. if ( element.setAttribute && element.removeAttribute ) {
  72. element.setAttribute(eventName, '');
  73. isSupported = is(element[eventName], 'function');
  74. if ( !is(element[eventName], 'undefined') ) {
  75. element[eventName] = undefined;
  76. }
  77. element.removeAttribute(eventName);
  78. }
  79. }
  80. element = null;
  81. return isSupported;
  82. }
  83. return isEventSupported;
  84. })(),
  85. _hasOwnProperty = ({}).hasOwnProperty, hasOwnProp;
  86. if ( !is(_hasOwnProperty, 'undefined') && !is(_hasOwnProperty.call, 'undefined') ) {
  87. hasOwnProp = function (object, property) {
  88. return _hasOwnProperty.call(object, property);
  89. };
  90. }
  91. else {
  92. hasOwnProp = function (object, property) {
  93. return ((property in object) && is(object.constructor.prototype[property], 'undefined'));
  94. };
  95. }
  96. if (!Function.prototype.bind) {
  97. Function.prototype.bind = function bind(that) {
  98. var target = this;
  99. if (typeof target != "function") {
  100. throw new TypeError();
  101. }
  102. var args = slice.call(arguments, 1),
  103. bound = function () {
  104. if (this instanceof bound) {
  105. var F = function(){};
  106. F.prototype = target.prototype;
  107. var self = new F();
  108. var result = target.apply(
  109. self,
  110. args.concat(slice.call(arguments))
  111. );
  112. if (Object(result) === result) {
  113. return result;
  114. }
  115. return self;
  116. } else {
  117. return target.apply(
  118. that,
  119. args.concat(slice.call(arguments))
  120. );
  121. }
  122. };
  123. return bound;
  124. };
  125. }
  126. function setCss( str ) {
  127. mStyle.cssText = str;
  128. }
  129. function setCssAll( str1, str2 ) {
  130. return setCss(prefixes.join(str1 + ';') + ( str2 || '' ));
  131. }
  132. function is( obj, type ) {
  133. return typeof obj === type;
  134. }
  135. function contains( str, substr ) {
  136. return !!~('' + str).indexOf(substr);
  137. }
  138. function testProps( props, prefixed ) {
  139. for ( var i in props ) {
  140. var prop = props[i];
  141. if ( !contains(prop, "-") && mStyle[prop] !== undefined ) {
  142. return prefixed == 'pfx' ? prop : true;
  143. }
  144. }
  145. return false;
  146. }
  147. function testDOMProps( props, obj, elem ) {
  148. for ( var i in props ) {
  149. var item = obj[props[i]];
  150. if ( item !== undefined) {
  151. if (elem === false) return props[i];
  152. if (is(item, 'function')){
  153. return item.bind(elem || obj);
  154. }
  155. return item;
  156. }
  157. }
  158. return false;
  159. }
  160. function testPropsAll( prop, prefixed, elem ) {
  161. var ucProp = prop.charAt(0).toUpperCase() + prop.slice(1),
  162. props = (prop + ' ' + cssomPrefixes.join(ucProp + ' ') + ucProp).split(' ');
  163. if(is(prefixed, "string") || is(prefixed, "undefined")) {
  164. return testProps(props, prefixed);
  165. } else {
  166. props = (prop + ' ' + (domPrefixes).join(ucProp + ' ') + ucProp).split(' ');
  167. return testDOMProps(props, prefixed, elem);
  168. }
  169. }
  170. tests['canvas'] = function() {
  171. var elem = document.createElement('canvas');
  172. return !!(elem.getContext && elem.getContext('2d'));
  173. };
  174. tests['canvastext'] = function() {
  175. return !!(Modernizr['canvas'] && is(document.createElement('canvas').getContext('2d').fillText, 'function'));
  176. };
  177. tests['touch'] = function() {
  178. var bool;
  179. if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
  180. bool = true;
  181. } else {
  182. injectElementWithStyles(['@media (',prefixes.join('touch-enabled),('),mod,')','{#modernizr{top:9px;position:absolute}}'].join(''), function( node ) {
  183. bool = node.offsetTop === 9;
  184. });
  185. }
  186. return bool;
  187. };
  188. tests['draganddrop'] = function() {
  189. var div = document.createElement('div');
  190. return ('draggable' in div) || ('ondragstart' in div && 'ondrop' in div);
  191. };
  192. tests['csstransforms'] = function() {
  193. return !!testPropsAll('transform');
  194. };
  195. tests['svg'] = function() {
  196. return !!document.createElementNS && !!document.createElementNS(ns.svg, 'svg').createSVGRect;
  197. };
  198. tests['inlinesvg'] = function() {
  199. var div = document.createElement('div');
  200. div.innerHTML = '<svg/>';
  201. return (div.firstChild && div.firstChild.namespaceURI) == ns.svg;
  202. };
  203. tests['svgclippaths'] = function() {
  204. return !!document.createElementNS && /SVGClipPath/.test(toString.call(document.createElementNS(ns.svg, 'clipPath')));
  205. };
  206. for ( var feature in tests ) {
  207. if ( hasOwnProp(tests, feature) ) {
  208. featureName = feature.toLowerCase();
  209. Modernizr[featureName] = tests[feature]();
  210. classes.push((Modernizr[featureName] ? '' : 'no-') + featureName);
  211. }
  212. }
  213. Modernizr.addTest = function ( feature, test ) {
  214. if ( typeof feature == 'object' ) {
  215. for ( var key in feature ) {
  216. if ( hasOwnProp( feature, key ) ) {
  217. Modernizr.addTest( key, feature[ key ] );
  218. }
  219. }
  220. } else {
  221. feature = feature.toLowerCase();
  222. if ( Modernizr[feature] !== undefined ) {
  223. return Modernizr;
  224. }
  225. test = typeof test == 'function' ? test() : test;
  226. if (typeof enableClasses !== "undefined" && enableClasses) {
  227. docElement.className += ' ' + (test ? '' : 'no-') + feature;
  228. }
  229. Modernizr[feature] = test;
  230. }
  231. return Modernizr;
  232. };
  233. setCss('');
  234. modElem = inputElem = null;
  235. Modernizr._version = version;
  236. Modernizr._prefixes = prefixes;
  237. Modernizr._domPrefixes = domPrefixes;
  238. Modernizr._cssomPrefixes = cssomPrefixes;
  239. Modernizr.hasEvent = isEventSupported;
  240. Modernizr.testProp = function(prop){
  241. return testProps([prop]);
  242. };
  243. Modernizr.testAllProps = testPropsAll;
  244. Modernizr.testStyles = injectElementWithStyles;
  245. return Modernizr;
  246. })(window, window.document);
  247. // data uri test.
  248. // https://github.com/Modernizr/Modernizr/issues/14
  249. // This test is asynchronous. Watch out.
  250. // in IE7 in HTTPS this can cause a Mixed Content security popup.
  251. // github.com/Modernizr/Modernizr/issues/362
  252. // To avoid that you can create a new iframe and inject this.. perhaps..
  253. (function(){
  254. var datauri = new Image();
  255. datauri.onerror = function() {
  256. Modernizr.addTest('datauri', function () { return false; });
  257. };
  258. datauri.onload = function() {
  259. Modernizr.addTest('datauri', function () { return (datauri.width == 1 && datauri.height == 1); });
  260. };
  261. datauri.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
  262. })();
  263. ;