modernizr-2.5.3.js 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  1. /*!
  2. * Modernizr v2.5.3
  3. * www.modernizr.com
  4. *
  5. * Copyright (c) Faruk Ates, Paul Irish, Alex Sexton
  6. * Available under the BSD and MIT licenses: www.modernizr.com/license/
  7. */
  8. /*
  9. * Modernizr tests which native CSS3 and HTML5 features are available in
  10. * the current UA and makes the results available to you in two ways:
  11. * as properties on a global Modernizr object, and as classes on the
  12. * <html> element. This information allows you to progressively enhance
  13. * your pages with a granular level of control over the experience.
  14. *
  15. * Modernizr has an optional (not included) conditional resource loader
  16. * called Modernizr.load(), based on Yepnope.js (yepnopejs.com).
  17. * To get a build that includes Modernizr.load(), as well as choosing
  18. * which tests to include, go to www.modernizr.com/download/
  19. *
  20. * Authors Faruk Ates, Paul Irish, Alex Sexton
  21. * Contributors Ryan Seddon, Ben Alman
  22. */
  23. window.Modernizr = (function( window, document, undefined ) {
  24. var version = '2.5.3',
  25. Modernizr = {},
  26. // option for enabling the HTML classes to be added
  27. enableClasses = true,
  28. docElement = document.documentElement,
  29. /**
  30. * Create our "modernizr" element that we do most feature tests on.
  31. */
  32. mod = 'modernizr',
  33. modElem = document.createElement(mod),
  34. mStyle = modElem.style,
  35. /**
  36. * Create the input element for various Web Forms feature tests.
  37. */
  38. inputElem = document.createElement('input'),
  39. smile = ':)',
  40. toString = {}.toString,
  41. // List of property values to set for css tests. See ticket #21
  42. prefixes = ' -webkit- -moz- -o- -ms- '.split(' '),
  43. // Following spec is to expose vendor-specific style properties as:
  44. // elem.style.WebkitBorderRadius
  45. // and the following would be incorrect:
  46. // elem.style.webkitBorderRadius
  47. // Webkit ghosts their properties in lowercase but Opera & Moz do not.
  48. // Microsoft uses a lowercase `ms` instead of the correct `Ms` in IE8+
  49. // erik.eae.net/archives/2008/03/10/21.48.10/
  50. // More here: github.com/Modernizr/Modernizr/issues/issue/21
  51. omPrefixes = 'Webkit Moz O ms',
  52. cssomPrefixes = omPrefixes.split(' '),
  53. domPrefixes = omPrefixes.toLowerCase().split(' '),
  54. ns = {'svg': 'http://www.w3.org/2000/svg'},
  55. tests = {},
  56. inputs = {},
  57. attrs = {},
  58. classes = [],
  59. slice = classes.slice,
  60. featureName, // used in testing loop
  61. // Inject element with style element and some CSS rules
  62. injectElementWithStyles = function( rule, callback, nodes, testnames ) {
  63. var style, ret, node,
  64. div = document.createElement('div'),
  65. // After page load injecting a fake body doesn't work so check if body exists
  66. body = document.body,
  67. // IE6 and 7 won't return offsetWidth or offsetHeight unless it's in the body element, so we fake it.
  68. fakeBody = body ? body : document.createElement('body');
  69. if ( parseInt(nodes, 10) ) {
  70. // In order not to give false positives we create a node for each test
  71. // This also allows the method to scale for unspecified uses
  72. while ( nodes-- ) {
  73. node = document.createElement('div');
  74. node.id = testnames ? testnames[nodes] : mod + (nodes + 1);
  75. div.appendChild(node);
  76. }
  77. }
  78. // <style> elements in IE6-9 are considered 'NoScope' elements and therefore will be removed
  79. // when injected with innerHTML. To get around this you need to prepend the 'NoScope' element
  80. // with a 'scoped' element, in our case the soft-hyphen entity as it won't mess with our measurements.
  81. // msdn.microsoft.com/en-us/library/ms533897%28VS.85%29.aspx
  82. // Documents served as xml will throw if using &shy; so use xml friendly encoded version. See issue #277
  83. style = ['&#173;','<style>', rule, '</style>'].join('');
  84. div.id = mod;
  85. // IE6 will false positive on some tests due to the style element inside the test div somehow interfering offsetHeight, so insert it into body or fakebody.
  86. // Opera will act all quirky when injecting elements in documentElement when page is served as xml, needs fakebody too. #270
  87. fakeBody.innerHTML += style;
  88. fakeBody.appendChild(div);
  89. if(!body){
  90. //avoid crashing IE8, if background image is used
  91. fakeBody.style.background = "";
  92. docElement.appendChild(fakeBody);
  93. }
  94. ret = callback(div, rule);
  95. // If this is done after page load we don't want to remove the body so check if body exists
  96. !body ? fakeBody.parentNode.removeChild(fakeBody) : div.parentNode.removeChild(div);
  97. return !!ret;
  98. },
  99. // adapted from matchMedia polyfill
  100. // by Scott Jehl and Paul Irish
  101. // gist.github.com/786768
  102. testMediaQuery = function( mq ) {
  103. var matchMedia = window.matchMedia || window.msMatchMedia;
  104. if ( matchMedia ) {
  105. return matchMedia(mq).matches;
  106. }
  107. var bool;
  108. injectElementWithStyles('@media ' + mq + ' { #' + mod + ' { position: absolute; } }', function( node ) {
  109. bool = (window.getComputedStyle ?
  110. getComputedStyle(node, null) :
  111. node.currentStyle)['position'] == 'absolute';
  112. });
  113. return bool;
  114. },
  115. /**
  116. * isEventSupported determines if a given element supports the given event
  117. * function from yura.thinkweb2.com/isEventSupported/
  118. */
  119. isEventSupported = (function() {
  120. var TAGNAMES = {
  121. 'select': 'input', 'change': 'input',
  122. 'submit': 'form', 'reset': 'form',
  123. 'error': 'img', 'load': 'img', 'abort': 'img'
  124. };
  125. function isEventSupported( eventName, element ) {
  126. element = element || document.createElement(TAGNAMES[eventName] || 'div');
  127. eventName = 'on' + eventName;
  128. // When using `setAttribute`, IE skips "unload", WebKit skips "unload" and "resize", whereas `in` "catches" those
  129. var isSupported = eventName in element;
  130. if ( !isSupported ) {
  131. // If it has no `setAttribute` (i.e. doesn't implement Node interface), try generic element
  132. if ( !element.setAttribute ) {
  133. element = document.createElement('div');
  134. }
  135. if ( element.setAttribute && element.removeAttribute ) {
  136. element.setAttribute(eventName, '');
  137. isSupported = is(element[eventName], 'function');
  138. // If property was created, "remove it" (by setting value to `undefined`)
  139. if ( !is(element[eventName], 'undefined') ) {
  140. element[eventName] = undefined;
  141. }
  142. element.removeAttribute(eventName);
  143. }
  144. }
  145. element = null;
  146. return isSupported;
  147. }
  148. return isEventSupported;
  149. })();
  150. // hasOwnProperty shim by kangax needed for Safari 2.0 support
  151. var _hasOwnProperty = ({}).hasOwnProperty, hasOwnProperty;
  152. if ( !is(_hasOwnProperty, 'undefined') && !is(_hasOwnProperty.call, 'undefined') ) {
  153. hasOwnProperty = function (object, property) {
  154. return _hasOwnProperty.call(object, property);
  155. };
  156. }
  157. else {
  158. hasOwnProperty = function (object, property) { /* yes, this can give false positives/negatives, but most of the time we don't care about those */
  159. return ((property in object) && is(object.constructor.prototype[property], 'undefined'));
  160. };
  161. }
  162. // Taken from ES5-shim https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js
  163. // ES-5 15.3.4.5
  164. // http://es5.github.com/#x15.3.4.5
  165. if (!Function.prototype.bind) {
  166. Function.prototype.bind = function bind(that) {
  167. var target = this;
  168. if (typeof target != "function") {
  169. throw new TypeError();
  170. }
  171. var args = slice.call(arguments, 1),
  172. bound = function () {
  173. if (this instanceof bound) {
  174. var F = function(){};
  175. F.prototype = target.prototype;
  176. var self = new F;
  177. var result = target.apply(
  178. self,
  179. args.concat(slice.call(arguments))
  180. );
  181. if (Object(result) === result) {
  182. return result;
  183. }
  184. return self;
  185. } else {
  186. return target.apply(
  187. that,
  188. args.concat(slice.call(arguments))
  189. );
  190. }
  191. };
  192. return bound;
  193. };
  194. }
  195. /**
  196. * setCss applies given styles to the Modernizr DOM node.
  197. */
  198. function setCss( str ) {
  199. mStyle.cssText = str;
  200. }
  201. /**
  202. * setCssAll extrapolates all vendor-specific css strings.
  203. */
  204. function setCssAll( str1, str2 ) {
  205. return setCss(prefixes.join(str1 + ';') + ( str2 || '' ));
  206. }
  207. /**
  208. * is returns a boolean for if typeof obj is exactly type.
  209. */
  210. function is( obj, type ) {
  211. return typeof obj === type;
  212. }
  213. /**
  214. * contains returns a boolean for if substr is found within str.
  215. */
  216. function contains( str, substr ) {
  217. return !!~('' + str).indexOf(substr);
  218. }
  219. /**
  220. * testProps is a generic CSS / DOM property test; if a browser supports
  221. * a certain property, it won't return undefined for it.
  222. * A supported CSS property returns empty string when its not yet set.
  223. */
  224. function testProps( props, prefixed ) {
  225. for ( var i in props ) {
  226. if ( mStyle[ props[i] ] !== undefined ) {
  227. return prefixed == 'pfx' ? props[i] : true;
  228. }
  229. }
  230. return false;
  231. }
  232. /**
  233. * testDOMProps is a generic DOM property test; if a browser supports
  234. * a certain property, it won't return undefined for it.
  235. */
  236. function testDOMProps( props, obj, elem ) {
  237. for ( var i in props ) {
  238. var item = obj[props[i]];
  239. if ( item !== undefined) {
  240. // return the property name as a string
  241. if (elem === false) return props[i];
  242. // let's bind a function
  243. if (is(item, 'function')){
  244. // default to autobind unless override
  245. return item.bind(elem || obj);
  246. }
  247. // return the unbound function or obj or value
  248. return item;
  249. }
  250. }
  251. return false;
  252. }
  253. /**
  254. * testPropsAll tests a list of DOM properties we want to check against.
  255. * We specify literally ALL possible (known and/or likely) properties on
  256. * the element including the non-vendor prefixed one, for forward-
  257. * compatibility.
  258. */
  259. function testPropsAll( prop, prefixed, elem ) {
  260. var ucProp = prop.charAt(0).toUpperCase() + prop.substr(1),
  261. props = (prop + ' ' + cssomPrefixes.join(ucProp + ' ') + ucProp).split(' ');
  262. // did they call .prefixed('boxSizing') or are we just testing a prop?
  263. if(is(prefixed, "string") || is(prefixed, "undefined")) {
  264. return testProps(props, prefixed);
  265. // otherwise, they called .prefixed('requestAnimationFrame', window[, elem])
  266. } else {
  267. props = (prop + ' ' + (domPrefixes).join(ucProp + ' ') + ucProp).split(' ');
  268. return testDOMProps(props, prefixed, elem);
  269. }
  270. }
  271. /**
  272. * testBundle tests a list of CSS features that require element and style injection.
  273. * By bundling them together we can reduce the need to touch the DOM multiple times.
  274. */
  275. /*>>testBundle*/
  276. var testBundle = (function( styles, tests ) {
  277. var style = styles.join(''),
  278. len = tests.length;
  279. injectElementWithStyles(style, function( node, rule ) {
  280. var style = document.styleSheets[document.styleSheets.length - 1],
  281. // IE8 will bork if you create a custom build that excludes both fontface and generatedcontent tests.
  282. // So we check for cssRules and that there is a rule available
  283. // More here: github.com/Modernizr/Modernizr/issues/288 & github.com/Modernizr/Modernizr/issues/293
  284. cssText = style ? (style.cssRules && style.cssRules[0] ? style.cssRules[0].cssText : style.cssText || '') : '',
  285. children = node.childNodes, hash = {};
  286. while ( len-- ) {
  287. hash[children[len].id] = children[len];
  288. }
  289. /*>>touch*/ Modernizr['touch'] = ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch || (hash['touch'] && hash['touch'].offsetTop) === 9; /*>>touch*/
  290. /*>>csstransforms3d*/ Modernizr['csstransforms3d'] = (hash['csstransforms3d'] && hash['csstransforms3d'].offsetLeft) === 9 && hash['csstransforms3d'].offsetHeight === 3; /*>>csstransforms3d*/
  291. /*>>generatedcontent*/Modernizr['generatedcontent'] = (hash['generatedcontent'] && hash['generatedcontent'].offsetHeight) >= 1; /*>>generatedcontent*/
  292. /*>>fontface*/ Modernizr['fontface'] = /src/i.test(cssText) &&
  293. cssText.indexOf(rule.split(' ')[0]) === 0; /*>>fontface*/
  294. }, len, tests);
  295. })([
  296. // Pass in styles to be injected into document
  297. /*>>fontface*/ '@font-face {font-family:"font";src:url("https://")}' /*>>fontface*/
  298. /*>>touch*/ ,['@media (',prefixes.join('touch-enabled),('),mod,')',
  299. '{#touch{top:9px;position:absolute}}'].join('') /*>>touch*/
  300. /*>>csstransforms3d*/ ,['@media (',prefixes.join('transform-3d),('),mod,')',
  301. '{#csstransforms3d{left:9px;position:absolute;height:3px;}}'].join('')/*>>csstransforms3d*/
  302. /*>>generatedcontent*/,['#generatedcontent:after{content:"',smile,'";visibility:hidden}'].join('') /*>>generatedcontent*/
  303. ],
  304. [
  305. /*>>fontface*/ 'fontface' /*>>fontface*/
  306. /*>>touch*/ ,'touch' /*>>touch*/
  307. /*>>csstransforms3d*/ ,'csstransforms3d' /*>>csstransforms3d*/
  308. /*>>generatedcontent*/,'generatedcontent' /*>>generatedcontent*/
  309. ]);/*>>testBundle*/
  310. /**
  311. * Tests
  312. * -----
  313. */
  314. // The *new* flexbox
  315. // dev.w3.org/csswg/css3-flexbox
  316. tests['flexbox'] = function() {
  317. return testPropsAll('flexOrder');
  318. };
  319. // The *old* flexbox
  320. // www.w3.org/TR/2009/WD-css3-flexbox-20090723/
  321. tests['flexbox-legacy'] = function() {
  322. return testPropsAll('boxDirection');
  323. };
  324. // On the S60 and BB Storm, getContext exists, but always returns undefined
  325. // so we actually have to call getContext() to verify
  326. // github.com/Modernizr/Modernizr/issues/issue/97/
  327. tests['canvas'] = function() {
  328. var elem = document.createElement('canvas');
  329. return !!(elem.getContext && elem.getContext('2d'));
  330. };
  331. tests['canvastext'] = function() {
  332. return !!(Modernizr['canvas'] && is(document.createElement('canvas').getContext('2d').fillText, 'function'));
  333. };
  334. // this test initiates a new webgl context.
  335. // webk.it/70117 is tracking a legit feature detect proposal
  336. tests['webgl'] = function() {
  337. try {
  338. var canvas = document.createElement('canvas'),
  339. ret;
  340. ret = !!(window.WebGLRenderingContext && (canvas.getContext('experimental-webgl') || canvas.getContext('webgl')));
  341. canvas = undefined;
  342. } catch (e){
  343. ret = false;
  344. }
  345. return ret;
  346. };
  347. /*
  348. * The Modernizr.touch test only indicates if the browser supports
  349. * touch events, which does not necessarily reflect a touchscreen
  350. * device, as evidenced by tablets running Windows 7 or, alas,
  351. * the Palm Pre / WebOS (touch) phones.
  352. *
  353. * Additionally, Chrome (desktop) used to lie about its support on this,
  354. * but that has since been rectified: crbug.com/36415
  355. *
  356. * We also test for Firefox 4 Multitouch Support.
  357. *
  358. * For more info, see: modernizr.github.com/Modernizr/touch.html
  359. */
  360. tests['touch'] = function() {
  361. return Modernizr['touch'];
  362. };
  363. /**
  364. * geolocation tests for the new Geolocation API specification.
  365. * This test is a standards compliant-only test; for more complete
  366. * testing, including a Google Gears fallback, please see:
  367. * code.google.com/p/geo-location-javascript/
  368. * or view a fallback solution using google's geo API:
  369. * gist.github.com/366184
  370. */
  371. tests['geolocation'] = function() {
  372. return !!navigator.geolocation;
  373. };
  374. // Per 1.6:
  375. // This used to be Modernizr.crosswindowmessaging but the longer
  376. // name has been deprecated in favor of a shorter and property-matching one.
  377. // The old API is still available in 1.6, but as of 2.0 will throw a warning,
  378. // and in the first release thereafter disappear entirely.
  379. tests['postmessage'] = function() {
  380. return !!window.postMessage;
  381. };
  382. // Chrome incognito mode used to throw an exception when using openDatabase
  383. // It doesn't anymore.
  384. tests['websqldatabase'] = function() {
  385. return !!window.openDatabase;
  386. };
  387. // Vendors had inconsistent prefixing with the experimental Indexed DB:
  388. // - Webkit's implementation is accessible through webkitIndexedDB
  389. // - Firefox shipped moz_indexedDB before FF4b9, but since then has been mozIndexedDB
  390. // For speed, we don't test the legacy (and beta-only) indexedDB
  391. tests['indexedDB'] = function() {
  392. return !!testPropsAll("indexedDB",window);
  393. };
  394. // documentMode logic from YUI to filter out IE8 Compat Mode
  395. // which false positives.
  396. tests['hashchange'] = function() {
  397. return isEventSupported('hashchange', window) && (document.documentMode === undefined || document.documentMode > 7);
  398. };
  399. // Per 1.6:
  400. // This used to be Modernizr.historymanagement but the longer
  401. // name has been deprecated in favor of a shorter and property-matching one.
  402. // The old API is still available in 1.6, but as of 2.0 will throw a warning,
  403. // and in the first release thereafter disappear entirely.
  404. tests['history'] = function() {
  405. return !!(window.history && history.pushState);
  406. };
  407. tests['draganddrop'] = function() {
  408. var div = document.createElement('div');
  409. return ('draggable' in div) || ('ondragstart' in div && 'ondrop' in div);
  410. };
  411. // FIXME: Once FF10 is sunsetted, we can drop prefixed MozWebSocket
  412. // bugzil.la/695635
  413. tests['websockets'] = function() {
  414. for ( var i = -1, len = cssomPrefixes.length; ++i < len; ){
  415. if ( window[cssomPrefixes[i] + 'WebSocket'] ){
  416. return true;
  417. }
  418. }
  419. return 'WebSocket' in window;
  420. };
  421. // css-tricks.com/rgba-browser-support/
  422. tests['rgba'] = function() {
  423. // Set an rgba() color and check the returned value
  424. setCss('background-color:rgba(150,255,150,.5)');
  425. return contains(mStyle.backgroundColor, 'rgba');
  426. };
  427. tests['hsla'] = function() {
  428. // Same as rgba(), in fact, browsers re-map hsla() to rgba() internally,
  429. // except IE9 who retains it as hsla
  430. setCss('background-color:hsla(120,40%,100%,.5)');
  431. return contains(mStyle.backgroundColor, 'rgba') || contains(mStyle.backgroundColor, 'hsla');
  432. };
  433. tests['multiplebgs'] = function() {
  434. // Setting multiple images AND a color on the background shorthand property
  435. // and then querying the style.background property value for the number of
  436. // occurrences of "url(" is a reliable method for detecting ACTUAL support for this!
  437. setCss('background:url(https://),url(https://),red url(https://)');
  438. // If the UA supports multiple backgrounds, there should be three occurrences
  439. // of the string "url(" in the return value for elemStyle.background
  440. return /(url\s*\(.*?){3}/.test(mStyle.background);
  441. };
  442. // In testing support for a given CSS property, it's legit to test:
  443. // `elem.style[styleName] !== undefined`
  444. // If the property is supported it will return an empty string,
  445. // if unsupported it will return undefined.
  446. // We'll take advantage of this quick test and skip setting a style
  447. // on our modernizr element, but instead just testing undefined vs
  448. // empty string.
  449. tests['backgroundsize'] = function() {
  450. return testPropsAll('backgroundSize');
  451. };
  452. tests['borderimage'] = function() {
  453. return testPropsAll('borderImage');
  454. };
  455. // Super comprehensive table about all the unique implementations of
  456. // border-radius: muddledramblings.com/table-of-css3-border-radius-compliance
  457. tests['borderradius'] = function() {
  458. return testPropsAll('borderRadius');
  459. };
  460. // WebOS unfortunately false positives on this test.
  461. tests['boxshadow'] = function() {
  462. return testPropsAll('boxShadow');
  463. };
  464. // FF3.0 will false positive on this test
  465. tests['textshadow'] = function() {
  466. return document.createElement('div').style.textShadow === '';
  467. };
  468. tests['opacity'] = function() {
  469. // Browsers that actually have CSS Opacity implemented have done so
  470. // according to spec, which means their return values are within the
  471. // range of [0.0,1.0] - including the leading zero.
  472. setCssAll('opacity:.55');
  473. // The non-literal . in this regex is intentional:
  474. // German Chrome returns this value as 0,55
  475. // github.com/Modernizr/Modernizr/issues/#issue/59/comment/516632
  476. return /^0.55$/.test(mStyle.opacity);
  477. };
  478. // Note, Android < 4 will pass this test, but can only animate
  479. // a single property at a time
  480. // daneden.me/2011/12/putting-up-with-androids-bullshit/
  481. tests['cssanimations'] = function() {
  482. return testPropsAll('animationName');
  483. };
  484. tests['csscolumns'] = function() {
  485. return testPropsAll('columnCount');
  486. };
  487. tests['cssgradients'] = function() {
  488. /**
  489. * For CSS Gradients syntax, please see:
  490. * webkit.org/blog/175/introducing-css-gradients/
  491. * developer.mozilla.org/en/CSS/-moz-linear-gradient
  492. * developer.mozilla.org/en/CSS/-moz-radial-gradient
  493. * dev.w3.org/csswg/css3-images/#gradients-
  494. */
  495. var str1 = 'background-image:',
  496. str2 = 'gradient(linear,left top,right bottom,from(#9f9),to(white));',
  497. str3 = 'linear-gradient(left top,#9f9, white);';
  498. setCss(
  499. // legacy webkit syntax (FIXME: remove when syntax not in use anymore)
  500. (str1 + '-webkit- '.split(' ').join(str2 + str1)
  501. // standard syntax // trailing 'background-image:'
  502. + prefixes.join(str3 + str1)).slice(0, -str1.length)
  503. );
  504. return contains(mStyle.backgroundImage, 'gradient');
  505. };
  506. tests['cssreflections'] = function() {
  507. return testPropsAll('boxReflect');
  508. };
  509. tests['csstransforms'] = function() {
  510. return !!testPropsAll('transform');
  511. };
  512. tests['csstransforms3d'] = function() {
  513. var ret = !!testPropsAll('perspective');
  514. // Webkit's 3D transforms are passed off to the browser's own graphics renderer.
  515. // It works fine in Safari on Leopard and Snow Leopard, but not in Chrome in
  516. // some conditions. As a result, Webkit typically recognizes the syntax but
  517. // will sometimes throw a false positive, thus we must do a more thorough check:
  518. if ( ret && 'webkitPerspective' in docElement.style ) {
  519. // Webkit allows this media query to succeed only if the feature is enabled.
  520. // `@media (transform-3d),(-o-transform-3d),(-moz-transform-3d),(-ms-transform-3d),(-webkit-transform-3d),(modernizr){ ... }`
  521. ret = Modernizr['csstransforms3d'];
  522. }
  523. return ret;
  524. };
  525. tests['csstransitions'] = function() {
  526. return testPropsAll('transition');
  527. };
  528. /*>>fontface*/
  529. // @font-face detection routine by Diego Perini
  530. // javascript.nwbox.com/CSSSupport/
  531. // false positives in WebOS: github.com/Modernizr/Modernizr/issues/342
  532. tests['fontface'] = function() {
  533. return Modernizr['fontface'];
  534. };
  535. /*>>fontface*/
  536. // CSS generated content detection
  537. tests['generatedcontent'] = function() {
  538. return Modernizr['generatedcontent'];
  539. };
  540. // These tests evaluate support of the video/audio elements, as well as
  541. // testing what types of content they support.
  542. //
  543. // We're using the Boolean constructor here, so that we can extend the value
  544. // e.g. Modernizr.video // true
  545. // Modernizr.video.ogg // 'probably'
  546. //
  547. // Codec values from : github.com/NielsLeenheer/html5test/blob/9106a8/index.html#L845
  548. // thx to NielsLeenheer and zcorpan
  549. // Note: in some older browsers, "no" was a return value instead of empty string.
  550. // It was live in FF3.5.0 and 3.5.1, but fixed in 3.5.2
  551. // It was also live in Safari 4.0.0 - 4.0.4, but fixed in 4.0.5
  552. tests['video'] = function() {
  553. var elem = document.createElement('video'),
  554. bool = false;
  555. // IE9 Running on Windows Server SKU can cause an exception to be thrown, bug #224
  556. try {
  557. if ( bool = !!elem.canPlayType ) {
  558. bool = new Boolean(bool);
  559. bool.ogg = elem.canPlayType('video/ogg; codecs="theora"') .replace(/^no$/,'');
  560. bool.h264 = elem.canPlayType('video/mp4; codecs="avc1.42E01E"') .replace(/^no$/,'');
  561. bool.webm = elem.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/,'');
  562. }
  563. } catch(e) { }
  564. return bool;
  565. };
  566. tests['audio'] = function() {
  567. var elem = document.createElement('audio'),
  568. bool = false;
  569. try {
  570. if ( bool = !!elem.canPlayType ) {
  571. bool = new Boolean(bool);
  572. bool.ogg = elem.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,'');
  573. bool.mp3 = elem.canPlayType('audio/mpeg;') .replace(/^no$/,'');
  574. // Mimetypes accepted:
  575. // developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
  576. // bit.ly/iphoneoscodecs
  577. bool.wav = elem.canPlayType('audio/wav; codecs="1"') .replace(/^no$/,'');
  578. bool.m4a = ( elem.canPlayType('audio/x-m4a;') ||
  579. elem.canPlayType('audio/aac;')) .replace(/^no$/,'');
  580. }
  581. } catch(e) { }
  582. return bool;
  583. };
  584. // In FF4, if disabled, window.localStorage should === null.
  585. // Normally, we could not test that directly and need to do a
  586. // `('localStorage' in window) && ` test first because otherwise Firefox will
  587. // throw bugzil.la/365772 if cookies are disabled
  588. // Also in iOS5 Private Browsing mode, attepting to use localStorage.setItem
  589. // will throw the exception:
  590. // QUOTA_EXCEEDED_ERRROR DOM Exception 22.
  591. // Peculiarly, getItem and removeItem calls do not throw.
  592. // Because we are forced to try/catch this, we'll go aggressive.
  593. // Just FWIW: IE8 Compat mode supports these features completely:
  594. // www.quirksmode.org/dom/html5.html
  595. // But IE8 doesn't support either with local files
  596. tests['localstorage'] = function() {
  597. try {
  598. localStorage.setItem(mod, mod);
  599. localStorage.removeItem(mod);
  600. return true;
  601. } catch(e) {
  602. return false;
  603. }
  604. };
  605. tests['sessionstorage'] = function() {
  606. try {
  607. sessionStorage.setItem(mod, mod);
  608. sessionStorage.removeItem(mod);
  609. return true;
  610. } catch(e) {
  611. return false;
  612. }
  613. };
  614. tests['webworkers'] = function() {
  615. return !!window.Worker;
  616. };
  617. tests['applicationcache'] = function() {
  618. return !!window.applicationCache;
  619. };
  620. // Thanks to Erik Dahlstrom
  621. tests['svg'] = function() {
  622. return !!document.createElementNS && !!document.createElementNS(ns.svg, 'svg').createSVGRect;
  623. };
  624. // specifically for SVG inline in HTML, not within XHTML
  625. // test page: paulirish.com/demo/inline-svg
  626. tests['inlinesvg'] = function() {
  627. var div = document.createElement('div');
  628. div.innerHTML = '<svg/>';
  629. return (div.firstChild && div.firstChild.namespaceURI) == ns.svg;
  630. };
  631. // SVG SMIL animation
  632. tests['smil'] = function() {
  633. return !!document.createElementNS && /SVGAnimate/.test(toString.call(document.createElementNS(ns.svg, 'animate')));
  634. };
  635. // This test is only for clip paths in SVG proper, not clip paths on HTML content
  636. // demo: srufaculty.sru.edu/david.dailey/svg/newstuff/clipPath4.svg
  637. // However read the comments to dig into applying SVG clippaths to HTML content here:
  638. // github.com/Modernizr/Modernizr/issues/213#issuecomment-1149491
  639. tests['svgclippaths'] = function() {
  640. return !!document.createElementNS && /SVGClipPath/.test(toString.call(document.createElementNS(ns.svg, 'clipPath')));
  641. };
  642. // input features and input types go directly onto the ret object, bypassing the tests loop.
  643. // Hold this guy to execute in a moment.
  644. function webforms() {
  645. // Run through HTML5's new input attributes to see if the UA understands any.
  646. // We're using f which is the <input> element created early on
  647. // Mike Taylr has created a comprehensive resource for testing these attributes
  648. // when applied to all input types:
  649. // miketaylr.com/code/input-type-attr.html
  650. // spec: www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
  651. // Only input placeholder is tested while textarea's placeholder is not.
  652. // Currently Safari 4 and Opera 11 have support only for the input placeholder
  653. // Both tests are available in feature-detects/forms-placeholder.js
  654. Modernizr['input'] = (function( props ) {
  655. for ( var i = 0, len = props.length; i < len; i++ ) {
  656. attrs[ props[i] ] = !!(props[i] in inputElem);
  657. }
  658. if (attrs.list){
  659. // safari false positive's on datalist: webk.it/74252
  660. // see also github.com/Modernizr/Modernizr/issues/146
  661. attrs.list = !!(document.createElement('datalist') && window.HTMLDataListElement);
  662. }
  663. return attrs;
  664. })('autocomplete autofocus list placeholder max min multiple pattern required step'.split(' '));
  665. // Run through HTML5's new input types to see if the UA understands any.
  666. // This is put behind the tests runloop because it doesn't return a
  667. // true/false like all the other tests; instead, it returns an object
  668. // containing each input type with its corresponding true/false value
  669. // Big thanks to @miketaylr for the html5 forms expertise. miketaylr.com/
  670. Modernizr['inputtypes'] = (function(props) {
  671. for ( var i = 0, bool, inputElemType, defaultView, len = props.length; i < len; i++ ) {
  672. inputElem.setAttribute('type', inputElemType = props[i]);
  673. bool = inputElem.type !== 'text';
  674. // We first check to see if the type we give it sticks..
  675. // If the type does, we feed it a textual value, which shouldn't be valid.
  676. // If the value doesn't stick, we know there's input sanitization which infers a custom UI
  677. if ( bool ) {
  678. inputElem.value = smile;
  679. inputElem.style.cssText = 'position:absolute;visibility:hidden;';
  680. if ( /^range$/.test(inputElemType) && inputElem.style.WebkitAppearance !== undefined ) {
  681. docElement.appendChild(inputElem);
  682. defaultView = document.defaultView;
  683. // Safari 2-4 allows the smiley as a value, despite making a slider
  684. bool = defaultView.getComputedStyle &&
  685. defaultView.getComputedStyle(inputElem, null).WebkitAppearance !== 'textfield' &&
  686. // Mobile android web browser has false positive, so must
  687. // check the height to see if the widget is actually there.
  688. (inputElem.offsetHeight !== 0);
  689. docElement.removeChild(inputElem);
  690. } else if ( /^(search|tel)$/.test(inputElemType) ){
  691. // Spec doesnt define any special parsing or detectable UI
  692. // behaviors so we pass these through as true
  693. // Interestingly, opera fails the earlier test, so it doesn't
  694. // even make it here.
  695. } else if ( /^(url|email)$/.test(inputElemType) ) {
  696. // Real url and email support comes with prebaked validation.
  697. bool = inputElem.checkValidity && inputElem.checkValidity() === false;
  698. } else if ( /^color$/.test(inputElemType) ) {
  699. // chuck into DOM and force reflow for Opera bug in 11.00
  700. // github.com/Modernizr/Modernizr/issues#issue/159
  701. docElement.appendChild(inputElem);
  702. docElement.offsetWidth;
  703. bool = inputElem.value != smile;
  704. docElement.removeChild(inputElem);
  705. } else {
  706. // If the upgraded input compontent rejects the :) text, we got a winner
  707. bool = inputElem.value != smile;
  708. }
  709. }
  710. inputs[ props[i] ] = !!bool;
  711. }
  712. return inputs;
  713. })('search tel url email datetime date month week time datetime-local number range color'.split(' '));
  714. }
  715. // End of test definitions
  716. // -----------------------
  717. // Run through all tests and detect their support in the current UA.
  718. // todo: hypothetically we could be doing an array of tests and use a basic loop here.
  719. for ( var feature in tests ) {
  720. if ( hasOwnProperty(tests, feature) ) {
  721. // run the test, throw the return value into the Modernizr,
  722. // then based on that boolean, define an appropriate className
  723. // and push it into an array of classes we'll join later.
  724. featureName = feature.toLowerCase();
  725. Modernizr[featureName] = tests[feature]();
  726. classes.push((Modernizr[featureName] ? '' : 'no-') + featureName);
  727. }
  728. }
  729. // input tests need to run.
  730. Modernizr.input || webforms();
  731. /**
  732. * addTest allows the user to define their own feature tests
  733. * the result will be added onto the Modernizr object,
  734. * as well as an appropriate className set on the html element
  735. *
  736. * @param feature - String naming the feature
  737. * @param test - Function returning true if feature is supported, false if not
  738. */
  739. Modernizr.addTest = function ( feature, test ) {
  740. if ( typeof feature == 'object' ) {
  741. for ( var key in feature ) {
  742. if ( hasOwnProperty( feature, key ) ) {
  743. Modernizr.addTest( key, feature[ key ] );
  744. }
  745. }
  746. } else {
  747. feature = feature.toLowerCase();
  748. if ( Modernizr[feature] !== undefined ) {
  749. // we're going to quit if you're trying to overwrite an existing test
  750. // if we were to allow it, we'd do this:
  751. // var re = new RegExp("\\b(no-)?" + feature + "\\b");
  752. // docElement.className = docElement.className.replace( re, '' );
  753. // but, no rly, stuff 'em.
  754. return Modernizr;
  755. }
  756. test = typeof test == 'function' ? test() : test;
  757. docElement.className += ' ' + (test ? '' : 'no-') + feature;
  758. Modernizr[feature] = test;
  759. }
  760. return Modernizr; // allow chaining.
  761. };
  762. // Reset modElem.cssText to nothing to reduce memory footprint.
  763. setCss('');
  764. modElem = inputElem = null;
  765. //>>BEGIN IEPP
  766. // Enable HTML 5 elements for styling in IE & add HTML5 css
  767. /*! HTML5 Shiv v3.4 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed */
  768. ;(function(window, document) {
  769. /** Preset options */
  770. var options = window.html5 || {};
  771. /** Used to skip problem elements */
  772. var reSkip = /^<|^(?:button|form|map|select|textarea)$/i;
  773. /** Detect whether the browser supports default html5 styles */
  774. var supportsHtml5Styles;
  775. /** Detect whether the browser supports unknown elements */
  776. var supportsUnknownElements;
  777. (function() {
  778. var a = document.createElement('a');
  779. a.innerHTML = '<xyz></xyz>';
  780. //if the hidden property is implemented we can assume, that the browser supports HTML5 Styles
  781. supportsHtml5Styles = ('hidden' in a);
  782. supportsUnknownElements = a.childNodes.length == 1 || (function() {
  783. // assign a false positive if unable to shiv
  784. try {
  785. (document.createElement)('a');
  786. } catch(e) {
  787. return true;
  788. }
  789. var frag = document.createDocumentFragment();
  790. return (
  791. typeof frag.cloneNode == 'undefined' ||
  792. typeof frag.createDocumentFragment == 'undefined' ||
  793. typeof frag.createElement == 'undefined'
  794. );
  795. }());
  796. }());
  797. /*--------------------------------------------------------------------------*/
  798. /**
  799. * Creates a style sheet with the given CSS text and adds it to the document.
  800. * @private
  801. * @param {Document} ownerDocument The document.
  802. * @param {String} cssText The CSS text.
  803. * @returns {StyleSheet} The style element.
  804. */
  805. function addStyleSheet(ownerDocument, cssText) {
  806. var p = ownerDocument.createElement('p'),
  807. parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement;
  808. p.innerHTML = 'x<style>' + cssText + '</style>';
  809. return parent.insertBefore(p.lastChild, parent.firstChild);
  810. }
  811. /**
  812. * Returns the value of `html5.elements` as an array.
  813. * @private
  814. * @returns {Array} An array of shived element node names.
  815. */
  816. function getElements() {
  817. var elements = html5.elements;
  818. return typeof elements == 'string' ? elements.split(' ') : elements;
  819. }
  820. /**
  821. * Shivs the `createElement` and `createDocumentFragment` methods of the document.
  822. * @private
  823. * @param {Document|DocumentFragment} ownerDocument The document.
  824. */
  825. function shivMethods(ownerDocument) {
  826. var cache = {},
  827. docCreateElement = ownerDocument.createElement,
  828. docCreateFragment = ownerDocument.createDocumentFragment,
  829. frag = docCreateFragment();
  830. ownerDocument.createElement = function(nodeName) {
  831. // Avoid adding some elements to fragments in IE < 9 because
  832. // * Attributes like `name` or `type` cannot be set/changed once an element
  833. // is inserted into a document/fragment
  834. // * Link elements with `src` attributes that are inaccessible, as with
  835. // a 403 response, will cause the tab/window to crash
  836. // * Script elements appended to fragments will execute when their `src`
  837. // or `text` property is set
  838. var node = (cache[nodeName] || (cache[nodeName] = docCreateElement(nodeName))).cloneNode();
  839. return html5.shivMethods && node.canHaveChildren && !reSkip.test(nodeName) ? frag.appendChild(node) : node;
  840. };
  841. ownerDocument.createDocumentFragment = Function('h,f', 'return function(){' +
  842. 'var n=f.cloneNode(),c=n.createElement;' +
  843. 'h.shivMethods&&(' +
  844. // unroll the `createElement` calls
  845. getElements().join().replace(/\w+/g, function(nodeName) {
  846. cache[nodeName] = docCreateElement(nodeName);
  847. frag.createElement(nodeName);
  848. return 'c("' + nodeName + '")';
  849. }) +
  850. ');return n}'
  851. )(html5, frag);
  852. }
  853. /*--------------------------------------------------------------------------*/
  854. /**
  855. * Shivs the given document.
  856. * @memberOf html5
  857. * @param {Document} ownerDocument The document to shiv.
  858. * @returns {Document} The shived document.
  859. */
  860. function shivDocument(ownerDocument) {
  861. var shived;
  862. if (ownerDocument.documentShived) {
  863. return ownerDocument;
  864. }
  865. if (html5.shivCSS && !supportsHtml5Styles) {
  866. shived = !!addStyleSheet(ownerDocument,
  867. // corrects block display not defined in IE6/7/8/9
  868. 'article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block}' +
  869. // corrects audio display not defined in IE6/7/8/9
  870. 'audio{display:none}' +
  871. // corrects canvas and video display not defined in IE6/7/8/9
  872. 'canvas,video{display:inline-block;*display:inline;*zoom:1}' +
  873. // corrects 'hidden' attribute and audio[controls] display not present in IE7/8/9
  874. '[hidden]{display:none}audio[controls]{display:inline-block;*display:inline;*zoom:1}' +
  875. // adds styling not present in IE6/7/8/9
  876. 'mark{background:#FF0;color:#000}'
  877. );
  878. }
  879. if (!supportsUnknownElements) {
  880. shived = !shivMethods(ownerDocument);
  881. }
  882. if (shived) {
  883. ownerDocument.documentShived = shived;
  884. }
  885. return ownerDocument;
  886. }
  887. /*--------------------------------------------------------------------------*/
  888. /**
  889. * The `html5` object is exposed so that more elements can be shived and
  890. * existing shiving can be detected on iframes.
  891. * @type Object
  892. * @example
  893. *
  894. * // options can be changed before the script is included
  895. * html5 = { 'elements': 'mark section', 'shivCSS': false, 'shivMethods': false };
  896. */
  897. var html5 = {
  898. /**
  899. * An array or space separated string of node names of the elements to shiv.
  900. * @memberOf html5
  901. * @type Array|String
  902. */
  903. 'elements': options.elements || 'abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video',
  904. /**
  905. * A flag to indicate that the HTML5 style sheet should be inserted.
  906. * @memberOf html5
  907. * @type Boolean
  908. */
  909. 'shivCSS': !(options.shivCSS === false),
  910. /**
  911. * A flag to indicate that the document's `createElement` and `createDocumentFragment`
  912. * methods should be overwritten.
  913. * @memberOf html5
  914. * @type Boolean
  915. */
  916. 'shivMethods': !(options.shivMethods === false),
  917. /**
  918. * A string to describe the type of `html5` object ("default" or "default print").
  919. * @memberOf html5
  920. * @type String
  921. */
  922. 'type': 'default',
  923. // shivs the document according to the specified `html5` object options
  924. 'shivDocument': shivDocument
  925. };
  926. /*--------------------------------------------------------------------------*/
  927. // expose html5
  928. window.html5 = html5;
  929. // shiv the document
  930. shivDocument(document);
  931. }(this, document));
  932. //>>END IEPP
  933. // Assign private properties to the return object with prefix
  934. Modernizr._version = version;
  935. // expose these for the plugin API. Look in the source for how to join() them against your input
  936. Modernizr._prefixes = prefixes;
  937. Modernizr._domPrefixes = domPrefixes;
  938. Modernizr._cssomPrefixes = cssomPrefixes;
  939. // Modernizr.mq tests a given media query, live against the current state of the window
  940. // A few important notes:
  941. // * If a browser does not support media queries at all (eg. oldIE) the mq() will always return false
  942. // * A max-width or orientation query will be evaluated against the current state, which may change later.
  943. // * You must specify values. Eg. If you are testing support for the min-width media query use:
  944. // Modernizr.mq('(min-width:0)')
  945. // usage:
  946. // Modernizr.mq('only screen and (max-width:768)')
  947. Modernizr.mq = testMediaQuery;
  948. // Modernizr.hasEvent() detects support for a given event, with an optional element to test on
  949. // Modernizr.hasEvent('gesturestart', elem)
  950. Modernizr.hasEvent = isEventSupported;
  951. // Modernizr.testProp() investigates whether a given style property is recognized
  952. // Note that the property names must be provided in the camelCase variant.
  953. // Modernizr.testProp('pointerEvents')
  954. Modernizr.testProp = function(prop){
  955. return testProps([prop]);
  956. };
  957. // Modernizr.testAllProps() investigates whether a given style property,
  958. // or any of its vendor-prefixed variants, is recognized
  959. // Note that the property names must be provided in the camelCase variant.
  960. // Modernizr.testAllProps('boxSizing')
  961. Modernizr.testAllProps = testPropsAll;
  962. // Modernizr.testStyles() allows you to add custom styles to the document and test an element afterwards
  963. // Modernizr.testStyles('#modernizr { position:absolute }', function(elem, rule){ ... })
  964. Modernizr.testStyles = injectElementWithStyles;
  965. // Modernizr.prefixed() returns the prefixed or nonprefixed property name variant of your input
  966. // Modernizr.prefixed('boxSizing') // 'MozBoxSizing'
  967. // Properties must be passed as dom-style camelcase, rather than `box-sizing` hypentated style.
  968. // Return values will also be the camelCase variant, if you need to translate that to hypenated style use:
  969. //
  970. // str.replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
  971. // If you're trying to ascertain which transition end event to bind to, you might do something like...
  972. //
  973. // var transEndEventNames = {
  974. // 'WebkitTransition' : 'webkitTransitionEnd',
  975. // 'MozTransition' : 'transitionend',
  976. // 'OTransition' : 'oTransitionEnd',
  977. // 'msTransition' : 'MsTransitionEnd',
  978. // 'transition' : 'transitionend'
  979. // },
  980. // transEndEventName = transEndEventNames[ Modernizr.prefixed('transition') ];
  981. Modernizr.prefixed = function(prop, obj, elem){
  982. if(!obj) {
  983. return testPropsAll(prop, 'pfx');
  984. } else {
  985. // Testing DOM property e.g. Modernizr.prefixed('requestAnimationFrame', window) // 'mozRequestAnimationFrame'
  986. return testPropsAll(prop, obj, elem);
  987. }
  988. };
  989. // Remove "no-js" class from <html> element, if it exists:
  990. docElement.className = docElement.className.replace(/(^|\s)no-js(\s|$)/, '$1$2') +
  991. // Add the new classes to the <html> element.
  992. (enableClasses ? ' js ' + classes.join(' ') : '');
  993. return Modernizr;
  994. })(this, this.document);