1 /* NUGET: BEGIN LICENSE TEXT
3 * Microsoft grants you the right to use these script files for the sole
4 * purpose of either: (i) interacting through your browser with the Microsoft
5 * website or online service, subject to the applicable licensing or use
6 * terms; or (ii) using the files as included with a Microsoft product subject
7 * to that product's license terms. Microsoft reserves all other rights to the
8 * files not expressly granted by Microsoft, whether by implication, estoppel
9 * or otherwise. Insofar as a script file is dual licensed under GPL,
10 * Microsoft neither took the code under GPL nor distributes it thereunder but
11 * under the terms set out in this paragraph. All notices and licenses
12 * below are for informational purposes only.
14 * Copyright (c) Faruk Ates, Paul Irish, Alex Sexton; http://www.modernizr.com/license/
16 * Includes matchMedia polyfill; Copyright (c) 2010 Filament Group, Inc; http://opensource.org/licenses/MIT
18 * Includes material adapted from ES5-shim https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js; Copyright 2009-2012 by contributors; http://opensource.org/licenses/MIT
20 * Includes material from css-support; Copyright (c) 2005-2012 Diego Perini; https://github.com/dperini/css-support/blob/master/LICENSE
22 * NUGET: END LICENSE TEXT */
28 * Copyright (c) Faruk Ates, Paul Irish, Alex Sexton
29 * Available under the BSD and MIT licenses: www.modernizr.com/license/
33 * Modernizr tests which native CSS3 and HTML5 features are available in
34 * the current UA and makes the results available to you in two ways:
35 * as properties on a global Modernizr object, and as classes on the
36 * <html> element. This information allows you to progressively enhance
37 * your pages with a granular level of control over the experience.
39 * Modernizr has an optional (not included) conditional resource loader
40 * called Modernizr.load(), based on Yepnope.js (yepnopejs.com).
41 * To get a build that includes Modernizr.load(), as well as choosing
42 * which tests to include, go to www.modernizr.com/download/
44 * Authors Faruk Ates, Paul Irish, Alex Sexton
45 * Contributors Ryan Seddon, Ben Alman
48 window.Modernizr = (function( window, document, undefined ) {
50 var version = '2.6.2',
55 // option for enabling the HTML classes to be added
59 docElement = document.documentElement,
62 * Create our "modernizr" element that we do most feature tests on.
65 modElem = document.createElement(mod),
66 mStyle = modElem.style,
69 * Create the input element for various Web Forms feature tests.
71 inputElem /*>>inputelem*/ = document.createElement('input') /*>>inputelem*/ ,
77 toString = {}.toString,
79 // TODO :: make the prefixes more granular
81 // List of property values to set for css tests. See ticket #21
82 prefixes = ' -webkit- -moz- -o- -ms- '.split(' '),
86 // Following spec is to expose vendor-specific style properties as:
87 // elem.style.WebkitBorderRadius
88 // and the following would be incorrect:
89 // elem.style.webkitBorderRadius
91 // Webkit ghosts their properties in lowercase but Opera & Moz do not.
92 // Microsoft uses a lowercase `ms` instead of the correct `Ms` in IE8+
93 // erik.eae.net/archives/2008/03/10/21.48.10/
95 // More here: github.com/Modernizr/Modernizr/issues/issue/21
96 omPrefixes = 'Webkit Moz O ms',
98 cssomPrefixes = omPrefixes.split(' '),
100 domPrefixes = omPrefixes.toLowerCase().split(' '),
104 ns = {'svg': 'http://www.w3.org/2000/svg'},
113 slice = classes.slice,
115 featureName, // used in testing loop
119 // Inject element with style element and some CSS rules
120 injectElementWithStyles = function( rule, callback, nodes, testnames ) {
122 var style, ret, node, docOverflow,
123 div = document.createElement('div'),
124 // After page load injecting a fake body doesn't work so check if body exists
125 body = document.body,
126 // IE6 and 7 won't return offsetWidth or offsetHeight unless it's in the body element, so we fake it.
127 fakeBody = body || document.createElement('body');
129 if ( parseInt(nodes, 10) ) {
130 // In order not to give false positives we create a node for each test
131 // This also allows the method to scale for unspecified uses
133 node = document.createElement('div');
134 node.id = testnames ? testnames[nodes] : mod + (nodes + 1);
135 div.appendChild(node);
139 // <style> elements in IE6-9 are considered 'NoScope' elements and therefore will be removed
140 // when injected with innerHTML. To get around this you need to prepend the 'NoScope' element
141 // with a 'scoped' element, in our case the soft-hyphen entity as it won't mess with our measurements.
142 // msdn.microsoft.com/en-us/library/ms533897%28VS.85%29.aspx
143 // Documents served as xml will throw if using ­ so use xml friendly encoded version. See issue #277
144 style = ['­','<style id="s', mod, '">', rule, '</style>'].join('');
146 // 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.
147 // Opera will act all quirky when injecting elements in documentElement when page is served as xml, needs fakebody too. #270
148 (body ? div : fakeBody).innerHTML += style;
149 fakeBody.appendChild(div);
151 //avoid crashing IE8, if background image is used
152 fakeBody.style.background = '';
153 //Safari 5.13/5.1.4 OSX stops loading if ::-webkit-scrollbar is used and scrollbars are visible
154 fakeBody.style.overflow = 'hidden';
155 docOverflow = docElement.style.overflow;
156 docElement.style.overflow = 'hidden';
157 docElement.appendChild(fakeBody);
160 ret = callback(div, rule);
161 // If this is done after page load we don't want to remove the body so check if body exists
163 fakeBody.parentNode.removeChild(fakeBody);
164 docElement.style.overflow = docOverflow;
166 div.parentNode.removeChild(div);
175 // adapted from matchMedia polyfill
176 // by Scott Jehl and Paul Irish
177 // gist.github.com/786768
178 testMediaQuery = function( mq ) {
180 var matchMedia = window.matchMedia || window.msMatchMedia;
182 return matchMedia(mq).matches;
187 injectElementWithStyles('@media ' + mq + ' { #' + mod + ' { position: absolute; } }', function( node ) {
188 bool = (window.getComputedStyle ?
189 getComputedStyle(node, null) :
190 node.currentStyle)['position'] == 'absolute';
201 // isEventSupported determines if a given element supports the given event
202 // kangax.github.com/iseventsupported/
204 // The following results are known incorrects:
205 // Modernizr.hasEvent("webkitTransitionEnd", elem) // false negative
206 // Modernizr.hasEvent("textInput") // in Webkit. github.com/Modernizr/Modernizr/issues/333
208 isEventSupported = (function() {
211 'select': 'input', 'change': 'input',
212 'submit': 'form', 'reset': 'form',
213 'error': 'img', 'load': 'img', 'abort': 'img'
216 function isEventSupported( eventName, element ) {
218 element = element || document.createElement(TAGNAMES[eventName] || 'div');
219 eventName = 'on' + eventName;
221 // When using `setAttribute`, IE skips "unload", WebKit skips "unload" and "resize", whereas `in` "catches" those
222 var isSupported = eventName in element;
224 if ( !isSupported ) {
225 // If it has no `setAttribute` (i.e. doesn't implement Node interface), try generic element
226 if ( !element.setAttribute ) {
227 element = document.createElement('div');
229 if ( element.setAttribute && element.removeAttribute ) {
230 element.setAttribute(eventName, '');
231 isSupported = is(element[eventName], 'function');
233 // If property was created, "remove it" (by setting value to `undefined`)
234 if ( !is(element[eventName], 'undefined') ) {
235 element[eventName] = undefined;
237 element.removeAttribute(eventName);
244 return isEventSupported;
248 // TODO :: Add flag for hasownprop ? didn't last time
250 // hasOwnProperty shim by kangax needed for Safari 2.0 support
251 _hasOwnProperty = ({}).hasOwnProperty, hasOwnProp;
253 if ( !is(_hasOwnProperty, 'undefined') && !is(_hasOwnProperty.call, 'undefined') ) {
254 hasOwnProp = function (object, property) {
255 return _hasOwnProperty.call(object, property);
259 hasOwnProp = function (object, property) { /* yes, this can give false positives/negatives, but most of the time we don't care about those */
260 return ((property in object) && is(object.constructor.prototype[property], 'undefined'));
264 // Adapted from ES5-shim https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js
265 // es5.github.com/#x15.3.4.5
267 if (!Function.prototype.bind) {
268 Function.prototype.bind = function bind(that) {
272 if (typeof target != "function") {
273 throw new TypeError();
276 var args = slice.call(arguments, 1),
277 bound = function () {
279 if (this instanceof bound) {
281 var F = function(){};
282 F.prototype = target.prototype;
285 var result = target.apply(
287 args.concat(slice.call(arguments))
289 if (Object(result) === result) {
298 args.concat(slice.call(arguments))
310 * setCss applies given styles to the Modernizr DOM node.
312 function setCss( str ) {
313 mStyle.cssText = str;
317 * setCssAll extrapolates all vendor-specific css strings.
319 function setCssAll( str1, str2 ) {
320 return setCss(prefixes.join(str1 + ';') + ( str2 || '' ));
324 * is returns a boolean for if typeof obj is exactly type.
326 function is( obj, type ) {
327 return typeof obj === type;
331 * contains returns a boolean for if substr is found within str.
333 function contains( str, substr ) {
334 return !!~('' + str).indexOf(substr);
339 // testProps is a generic CSS / DOM property test.
341 // In testing support for a given CSS property, it's legit to test:
342 // `elem.style[styleName] !== undefined`
343 // If the property is supported it will return an empty string,
344 // if unsupported it will return undefined.
346 // We'll take advantage of this quick test and skip setting a style
347 // on our modernizr element, but instead just testing undefined vs
350 // Because the testing of the CSS property names (with "-", as
351 // opposed to the camelCase DOM properties) is non-portable and
352 // non-standard but works in WebKit and IE (but not Gecko or Opera),
353 // we explicitly reject properties with dashes so that authors
354 // developing in WebKit or IE first don't end up with
355 // browser-specific content by accident.
357 function testProps( props, prefixed ) {
358 for ( var i in props ) {
360 if ( !contains(prop, "-") && mStyle[prop] !== undefined ) {
361 return prefixed == 'pfx' ? prop : true;
368 // TODO :: add testDOMProps
370 * testDOMProps is a generic DOM property test; if a browser supports
371 * a certain property, it won't return undefined for it.
373 function testDOMProps( props, obj, elem ) {
374 for ( var i in props ) {
375 var item = obj[props[i]];
376 if ( item !== undefined) {
378 // return the property name as a string
379 if (elem === false) return props[i];
381 // let's bind a function
382 if (is(item, 'function')){
383 // default to autobind unless override
384 return item.bind(elem || obj);
387 // return the unbound function or obj or value
396 * testPropsAll tests a list of DOM properties we want to check against.
397 * We specify literally ALL possible (known and/or likely) properties on
398 * the element including the non-vendor prefixed one, for forward-
401 function testPropsAll( prop, prefixed, elem ) {
403 var ucProp = prop.charAt(0).toUpperCase() + prop.slice(1),
404 props = (prop + ' ' + cssomPrefixes.join(ucProp + ' ') + ucProp).split(' ');
406 // did they call .prefixed('boxSizing') or are we just testing a prop?
407 if(is(prefixed, "string") || is(prefixed, "undefined")) {
408 return testProps(props, prefixed);
410 // otherwise, they called .prefixed('requestAnimationFrame', window[, elem])
412 props = (prop + ' ' + (domPrefixes).join(ucProp + ' ') + ucProp).split(' ');
413 return testDOMProps(props, prefixed, elem);
425 // dev.w3.org/csswg/css3-flexbox
427 tests['flexbox'] = function() {
428 return testPropsAll('flexWrap');
432 // www.w3.org/TR/2009/WD-css3-flexbox-20090723/
434 tests['flexboxlegacy'] = function() {
435 return testPropsAll('boxDirection');
438 // On the S60 and BB Storm, getContext exists, but always returns undefined
439 // so we actually have to call getContext() to verify
440 // github.com/Modernizr/Modernizr/issues/issue/97/
442 tests['canvas'] = function() {
443 var elem = document.createElement('canvas');
444 return !!(elem.getContext && elem.getContext('2d'));
447 tests['canvastext'] = function() {
448 return !!(Modernizr['canvas'] && is(document.createElement('canvas').getContext('2d').fillText, 'function'));
451 // webk.it/70117 is tracking a legit WebGL feature detect proposal
453 // We do a soft detect which may false positive in order to avoid
454 // an expensive context creation: bugzil.la/732441
456 tests['webgl'] = function() {
457 return !!window.WebGLRenderingContext;
461 * The Modernizr.touch test only indicates if the browser supports
462 * touch events, which does not necessarily reflect a touchscreen
463 * device, as evidenced by tablets running Windows 7 or, alas,
464 * the Palm Pre / WebOS (touch) phones.
466 * Additionally, Chrome (desktop) used to lie about its support on this,
467 * but that has since been rectified: crbug.com/36415
469 * We also test for Firefox 4 Multitouch Support.
471 * For more info, see: modernizr.github.com/Modernizr/touch.html
474 tests['touch'] = function() {
477 if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
480 injectElementWithStyles(['@media (',prefixes.join('touch-enabled),('),mod,')','{#modernizr{top:9px;position:absolute}}'].join(''), function( node ) {
481 bool = node.offsetTop === 9;
489 // geolocation is often considered a trivial feature detect...
490 // Turns out, it's quite tricky to get right:
492 // Using !!navigator.geolocation does two things we don't want. It:
493 // 1. Leaks memory in IE9: github.com/Modernizr/Modernizr/issues/513
494 // 2. Disables page caching in WebKit: webk.it/43956
496 // Meanwhile, in Firefox < 8, an about:config setting could expose
497 // a false positive that would throw an exception: bugzil.la/688158
499 tests['geolocation'] = function() {
500 return 'geolocation' in navigator;
504 tests['postmessage'] = function() {
505 return !!window.postMessage;
509 // Chrome incognito mode used to throw an exception when using openDatabase
510 // It doesn't anymore.
511 tests['websqldatabase'] = function() {
512 return !!window.openDatabase;
515 // Vendors had inconsistent prefixing with the experimental Indexed DB:
516 // - Webkit's implementation is accessible through webkitIndexedDB
517 // - Firefox shipped moz_indexedDB before FF4b9, but since then has been mozIndexedDB
518 // For speed, we don't test the legacy (and beta-only) indexedDB
519 tests['indexedDB'] = function() {
520 return !!testPropsAll("indexedDB", window);
523 // documentMode logic from YUI to filter out IE8 Compat Mode
524 // which false positives.
525 tests['hashchange'] = function() {
526 return isEventSupported('hashchange', window) && (document.documentMode === undefined || document.documentMode > 7);
530 // This used to be Modernizr.historymanagement but the longer
531 // name has been deprecated in favor of a shorter and property-matching one.
532 // The old API is still available in 1.6, but as of 2.0 will throw a warning,
533 // and in the first release thereafter disappear entirely.
534 tests['history'] = function() {
535 return !!(window.history && history.pushState);
538 tests['draganddrop'] = function() {
539 var div = document.createElement('div');
540 return ('draggable' in div) || ('ondragstart' in div && 'ondrop' in div);
543 // FF3.6 was EOL'ed on 4/24/12, but the ESR version of FF10
544 // will be supported until FF19 (2/12/13), at which time, ESR becomes FF17.
545 // FF10 still uses prefixes, so check for it until then.
546 // for more ESR info, see: mozilla.org/en-US/firefox/organizations/faq/
547 tests['websockets'] = function() {
548 return 'WebSocket' in window || 'MozWebSocket' in window;
552 // css-tricks.com/rgba-browser-support/
553 tests['rgba'] = function() {
554 // Set an rgba() color and check the returned value
556 setCss('background-color:rgba(150,255,150,.5)');
558 return contains(mStyle.backgroundColor, 'rgba');
561 tests['hsla'] = function() {
562 // Same as rgba(), in fact, browsers re-map hsla() to rgba() internally,
563 // except IE9 who retains it as hsla
565 setCss('background-color:hsla(120,40%,100%,.5)');
567 return contains(mStyle.backgroundColor, 'rgba') || contains(mStyle.backgroundColor, 'hsla');
570 tests['multiplebgs'] = function() {
571 // Setting multiple images AND a color on the background shorthand property
572 // and then querying the style.background property value for the number of
573 // occurrences of "url(" is a reliable method for detecting ACTUAL support for this!
575 setCss('background:url(https://),url(https://),red url(https://)');
577 // If the UA supports multiple backgrounds, there should be three occurrences
578 // of the string "url(" in the return value for elemStyle.background
580 return (/(url\s*\(.*?){3}/).test(mStyle.background);
585 // this will false positive in Opera Mini
586 // github.com/Modernizr/Modernizr/issues/396
588 tests['backgroundsize'] = function() {
589 return testPropsAll('backgroundSize');
592 tests['borderimage'] = function() {
593 return testPropsAll('borderImage');
597 // Super comprehensive table about all the unique implementations of
598 // border-radius: muddledramblings.com/table-of-css3-border-radius-compliance
600 tests['borderradius'] = function() {
601 return testPropsAll('borderRadius');
604 // WebOS unfortunately false positives on this test.
605 tests['boxshadow'] = function() {
606 return testPropsAll('boxShadow');
609 // FF3.0 will false positive on this test
610 tests['textshadow'] = function() {
611 return document.createElement('div').style.textShadow === '';
615 tests['opacity'] = function() {
616 // Browsers that actually have CSS Opacity implemented have done so
617 // according to spec, which means their return values are within the
618 // range of [0.0,1.0] - including the leading zero.
620 setCssAll('opacity:.55');
622 // The non-literal . in this regex is intentional:
623 // German Chrome returns this value as 0,55
624 // github.com/Modernizr/Modernizr/issues/#issue/59/comment/516632
625 return (/^0.55$/).test(mStyle.opacity);
629 // Note, Android < 4 will pass this test, but can only animate
630 // a single property at a time
631 // daneden.me/2011/12/putting-up-with-androids-bullshit/
632 tests['cssanimations'] = function() {
633 return testPropsAll('animationName');
637 tests['csscolumns'] = function() {
638 return testPropsAll('columnCount');
642 tests['cssgradients'] = function() {
644 * For CSS Gradients syntax, please see:
645 * webkit.org/blog/175/introducing-css-gradients/
646 * developer.mozilla.org/en/CSS/-moz-linear-gradient
647 * developer.mozilla.org/en/CSS/-moz-radial-gradient
648 * dev.w3.org/csswg/css3-images/#gradients-
651 var str1 = 'background-image:',
652 str2 = 'gradient(linear,left top,right bottom,from(#9f9),to(white));',
653 str3 = 'linear-gradient(left top,#9f9, white);';
656 // legacy webkit syntax (FIXME: remove when syntax not in use anymore)
657 (str1 + '-webkit- '.split(' ').join(str2 + str1) +
658 // standard syntax // trailing 'background-image:'
659 prefixes.join(str3 + str1)).slice(0, -str1.length)
662 return contains(mStyle.backgroundImage, 'gradient');
666 tests['cssreflections'] = function() {
667 return testPropsAll('boxReflect');
671 tests['csstransforms'] = function() {
672 return !!testPropsAll('transform');
676 tests['csstransforms3d'] = function() {
678 var ret = !!testPropsAll('perspective');
680 // Webkit's 3D transforms are passed off to the browser's own graphics renderer.
681 // It works fine in Safari on Leopard and Snow Leopard, but not in Chrome in
682 // some conditions. As a result, Webkit typically recognizes the syntax but
683 // will sometimes throw a false positive, thus we must do a more thorough check:
684 if ( ret && 'webkitPerspective' in docElement.style ) {
686 // Webkit allows this media query to succeed only if the feature is enabled.
687 // `@media (transform-3d),(-webkit-transform-3d){ ... }`
688 injectElementWithStyles('@media (transform-3d),(-webkit-transform-3d){#modernizr{left:9px;position:absolute;height:3px;}}', function( node, rule ) {
689 ret = node.offsetLeft === 9 && node.offsetHeight === 3;
696 tests['csstransitions'] = function() {
697 return testPropsAll('transition');
702 // @font-face detection routine by Diego Perini
703 // javascript.nwbox.com/CSSSupport/
706 // WebOS github.com/Modernizr/Modernizr/issues/342
707 // WP7 github.com/Modernizr/Modernizr/issues/538
708 tests['fontface'] = function() {
711 injectElementWithStyles('@font-face {font-family:"font";src:url("https://")}', function( node, rule ) {
712 var style = document.getElementById('smodernizr'),
713 sheet = style.sheet || style.styleSheet,
714 cssText = sheet ? (sheet.cssRules && sheet.cssRules[0] ? sheet.cssRules[0].cssText : sheet.cssText || '') : '';
716 bool = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0;
723 // CSS generated content detection
724 tests['generatedcontent'] = function() {
727 injectElementWithStyles(['#',mod,'{font:0/0 a}#',mod,':after{content:"',smile,'";visibility:hidden;font:3px/1 a}'].join(''), function( node ) {
728 bool = node.offsetHeight >= 3;
736 // These tests evaluate support of the video/audio elements, as well as
737 // testing what types of content they support.
739 // We're using the Boolean constructor here, so that we can extend the value
740 // e.g. Modernizr.video // true
741 // Modernizr.video.ogg // 'probably'
743 // Codec values from : github.com/NielsLeenheer/html5test/blob/9106a8/index.html#L845
744 // thx to NielsLeenheer and zcorpan
746 // Note: in some older browsers, "no" was a return value instead of empty string.
747 // It was live in FF3.5.0 and 3.5.1, but fixed in 3.5.2
748 // It was also live in Safari 4.0.0 - 4.0.4, but fixed in 4.0.5
750 tests['video'] = function() {
751 var elem = document.createElement('video'),
754 // IE9 Running on Windows Server SKU can cause an exception to be thrown, bug #224
756 if ( bool = !!elem.canPlayType ) {
757 bool = new Boolean(bool);
758 bool.ogg = elem.canPlayType('video/ogg; codecs="theora"') .replace(/^no$/,'');
760 // Without QuickTime, this value will be `undefined`. github.com/Modernizr/Modernizr/issues/546
761 bool.h264 = elem.canPlayType('video/mp4; codecs="avc1.42E01E"') .replace(/^no$/,'');
763 bool.webm = elem.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/,'');
771 tests['audio'] = function() {
772 var elem = document.createElement('audio'),
776 if ( bool = !!elem.canPlayType ) {
777 bool = new Boolean(bool);
778 bool.ogg = elem.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/,'');
779 bool.mp3 = elem.canPlayType('audio/mpeg;') .replace(/^no$/,'');
781 // Mimetypes accepted:
782 // developer.mozilla.org/En/Media_formats_supported_by_the_audio_and_video_elements
783 // bit.ly/iphoneoscodecs
784 bool.wav = elem.canPlayType('audio/wav; codecs="1"') .replace(/^no$/,'');
785 bool.m4a = ( elem.canPlayType('audio/x-m4a;') ||
786 elem.canPlayType('audio/aac;')) .replace(/^no$/,'');
794 // In FF4, if disabled, window.localStorage should === null.
796 // Normally, we could not test that directly and need to do a
797 // `('localStorage' in window) && ` test first because otherwise Firefox will
798 // throw bugzil.la/365772 if cookies are disabled
800 // Also in iOS5 Private Browsing mode, attempting to use localStorage.setItem
801 // will throw the exception:
802 // QUOTA_EXCEEDED_ERRROR DOM Exception 22.
803 // Peculiarly, getItem and removeItem calls do not throw.
805 // Because we are forced to try/catch this, we'll go aggressive.
807 // Just FWIW: IE8 Compat mode supports these features completely:
808 // www.quirksmode.org/dom/html5.html
809 // But IE8 doesn't support either with local files
811 tests['localstorage'] = function() {
813 localStorage.setItem(mod, mod);
814 localStorage.removeItem(mod);
821 tests['sessionstorage'] = function() {
823 sessionStorage.setItem(mod, mod);
824 sessionStorage.removeItem(mod);
832 tests['webworkers'] = function() {
833 return !!window.Worker;
837 tests['applicationcache'] = function() {
838 return !!window.applicationCache;
842 // Thanks to Erik Dahlstrom
843 tests['svg'] = function() {
844 return !!document.createElementNS && !!document.createElementNS(ns.svg, 'svg').createSVGRect;
847 // specifically for SVG inline in HTML, not within XHTML
848 // test page: paulirish.com/demo/inline-svg
849 tests['inlinesvg'] = function() {
850 var div = document.createElement('div');
851 div.innerHTML = '<svg/>';
852 return (div.firstChild && div.firstChild.namespaceURI) == ns.svg;
855 // SVG SMIL animation
856 tests['smil'] = function() {
857 return !!document.createElementNS && /SVGAnimate/.test(toString.call(document.createElementNS(ns.svg, 'animate')));
860 // This test is only for clip paths in SVG proper, not clip paths on HTML content
861 // demo: srufaculty.sru.edu/david.dailey/svg/newstuff/clipPath4.svg
863 // However read the comments to dig into applying SVG clippaths to HTML content here:
864 // github.com/Modernizr/Modernizr/issues/213#issuecomment-1149491
865 tests['svgclippaths'] = function() {
866 return !!document.createElementNS && /SVGClipPath/.test(toString.call(document.createElementNS(ns.svg, 'clipPath')));
870 // input features and input types go directly onto the ret object, bypassing the tests loop.
871 // Hold this guy to execute in a moment.
872 function webforms() {
874 // Run through HTML5's new input attributes to see if the UA understands any.
875 // We're using f which is the <input> element created early on
876 // Mike Taylr has created a comprehensive resource for testing these attributes
877 // when applied to all input types:
878 // miketaylr.com/code/input-type-attr.html
879 // spec: www.whatwg.org/specs/web-apps/current-work/multipage/the-input-element.html#input-type-attr-summary
881 // Only input placeholder is tested while textarea's placeholder is not.
882 // Currently Safari 4 and Opera 11 have support only for the input placeholder
883 // Both tests are available in feature-detects/forms-placeholder.js
884 Modernizr['input'] = (function( props ) {
885 for ( var i = 0, len = props.length; i < len; i++ ) {
886 attrs[ props[i] ] = !!(props[i] in inputElem);
889 // safari false positive's on datalist: webk.it/74252
890 // see also github.com/Modernizr/Modernizr/issues/146
891 attrs.list = !!(document.createElement('datalist') && window.HTMLDataListElement);
894 })('autocomplete autofocus list placeholder max min multiple pattern required step'.split(' '));
898 // Run through HTML5's new input types to see if the UA understands any.
899 // This is put behind the tests runloop because it doesn't return a
900 // true/false like all the other tests; instead, it returns an object
901 // containing each input type with its corresponding true/false value
903 // Big thanks to @miketaylr for the html5 forms expertise. miketaylr.com/
904 Modernizr['inputtypes'] = (function(props) {
906 for ( var i = 0, bool, inputElemType, defaultView, len = props.length; i < len; i++ ) {
908 inputElem.setAttribute('type', inputElemType = props[i]);
909 bool = inputElem.type !== 'text';
911 // We first check to see if the type we give it sticks..
912 // If the type does, we feed it a textual value, which shouldn't be valid.
913 // If the value doesn't stick, we know there's input sanitization which infers a custom UI
916 inputElem.value = smile;
917 inputElem.style.cssText = 'position:absolute;visibility:hidden;';
919 if ( /^range$/.test(inputElemType) && inputElem.style.WebkitAppearance !== undefined ) {
921 docElement.appendChild(inputElem);
922 defaultView = document.defaultView;
924 // Safari 2-4 allows the smiley as a value, despite making a slider
925 bool = defaultView.getComputedStyle &&
926 defaultView.getComputedStyle(inputElem, null).WebkitAppearance !== 'textfield' &&
927 // Mobile android web browser has false positive, so must
928 // check the height to see if the widget is actually there.
929 (inputElem.offsetHeight !== 0);
931 docElement.removeChild(inputElem);
933 } else if ( /^(search|tel)$/.test(inputElemType) ){
934 // Spec doesn't define any special parsing or detectable UI
935 // behaviors so we pass these through as true
937 // Interestingly, opera fails the earlier test, so it doesn't
938 // even make it here.
940 } else if ( /^(url|email)$/.test(inputElemType) ) {
941 // Real url and email support comes with prebaked validation.
942 bool = inputElem.checkValidity && inputElem.checkValidity() === false;
945 // If the upgraded input compontent rejects the :) text, we got a winner
946 bool = inputElem.value != smile;
950 inputs[ props[i] ] = !!bool;
953 })('search tel url email datetime date month week time datetime-local number range color'.split(' '));
959 // End of test definitions
960 // -----------------------
964 // Run through all tests and detect their support in the current UA.
965 // todo: hypothetically we could be doing an array of tests and use a basic loop here.
966 for ( var feature in tests ) {
967 if ( hasOwnProp(tests, feature) ) {
968 // run the test, throw the return value into the Modernizr,
969 // then based on that boolean, define an appropriate className
970 // and push it into an array of classes we'll join later.
971 featureName = feature.toLowerCase();
972 Modernizr[featureName] = tests[feature]();
974 classes.push((Modernizr[featureName] ? '' : 'no-') + featureName);
979 // input tests need to run.
980 Modernizr.input || webforms();
985 * addTest allows the user to define their own feature tests
986 * the result will be added onto the Modernizr object,
987 * as well as an appropriate className set on the html element
989 * @param feature - String naming the feature
990 * @param test - Function returning true if feature is supported, false if not
992 Modernizr.addTest = function ( feature, test ) {
993 if ( typeof feature == 'object' ) {
994 for ( var key in feature ) {
995 if ( hasOwnProp( feature, key ) ) {
996 Modernizr.addTest( key, feature[ key ] );
1001 feature = feature.toLowerCase();
1003 if ( Modernizr[feature] !== undefined ) {
1004 // we're going to quit if you're trying to overwrite an existing test
1005 // if we were to allow it, we'd do this:
1006 // var re = new RegExp("\\b(no-)?" + feature + "\\b");
1007 // docElement.className = docElement.className.replace( re, '' );
1008 // but, no rly, stuff 'em.
1012 test = typeof test == 'function' ? test() : test;
1014 if (typeof enableClasses !== "undefined" && enableClasses) {
1015 docElement.className += ' ' + (test ? '' : 'no-') + feature;
1017 Modernizr[feature] = test;
1021 return Modernizr; // allow chaining.
1025 // Reset modElem.cssText to nothing to reduce memory footprint.
1027 modElem = inputElem = null;
1030 /*! HTML5 Shiv v3.6.1 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed */
1031 ;(function(window, document) {
1032 /*jshint evil:true */
1033 /** Preset options */
1034 var options = window.html5 || {};
1036 /** Used to skip problem elements */
1037 var reSkip = /^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i;
1039 /** Not all elements can be cloned in IE **/
1040 var saveClones = /^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i;
1042 /** Detect whether the browser supports default html5 styles */
1043 var supportsHtml5Styles;
1045 /** Name of the expando, to work with multiple documents or to re-shiv one document */
1046 var expando = '_html5shiv';
1048 /** The id for the the documents expando */
1051 /** Cached data for each document */
1052 var expandoData = {};
1054 /** Detect whether the browser supports unknown elements */
1055 var supportsUnknownElements;
1059 var a = document.createElement('a');
1060 a.innerHTML = '<xyz></xyz>';
1061 //if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles
1062 supportsHtml5Styles = ('hidden' in a);
1064 supportsUnknownElements = a.childNodes.length == 1 || (function() {
1065 // assign a false positive if unable to shiv
1066 (document.createElement)('a');
1067 var frag = document.createDocumentFragment();
1069 typeof frag.cloneNode == 'undefined' ||
1070 typeof frag.createDocumentFragment == 'undefined' ||
1071 typeof frag.createElement == 'undefined'
1075 supportsHtml5Styles = true;
1076 supportsUnknownElements = true;
1081 /*--------------------------------------------------------------------------*/
1084 * Creates a style sheet with the given CSS text and adds it to the document.
1086 * @param {Document} ownerDocument The document.
1087 * @param {String} cssText The CSS text.
1088 * @returns {StyleSheet} The style element.
1090 function addStyleSheet(ownerDocument, cssText) {
1091 var p = ownerDocument.createElement('p'),
1092 parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement;
1094 p.innerHTML = 'x<style>' + cssText + '</style>';
1095 return parent.insertBefore(p.lastChild, parent.firstChild);
1099 * Returns the value of `html5.elements` as an array.
1101 * @returns {Array} An array of shived element node names.
1103 function getElements() {
1104 var elements = html5.elements;
1105 return typeof elements == 'string' ? elements.split(' ') : elements;
1109 * Returns the data associated to the given document
1111 * @param {Document} ownerDocument The document.
1112 * @returns {Object} An object of data.
1114 function getExpandoData(ownerDocument) {
1115 var data = expandoData[ownerDocument[expando]];
1119 ownerDocument[expando] = expanID;
1120 expandoData[expanID] = data;
1126 * returns a shived element for the given nodeName and document
1128 * @param {String} nodeName name of the element
1129 * @param {Document} ownerDocument The context document.
1130 * @returns {Object} The shived element.
1132 function createElement(nodeName, ownerDocument, data){
1133 if (!ownerDocument) {
1134 ownerDocument = document;
1136 if(supportsUnknownElements){
1137 return ownerDocument.createElement(nodeName);
1140 data = getExpandoData(ownerDocument);
1144 if (data.cache[nodeName]) {
1145 node = data.cache[nodeName].cloneNode();
1146 } else if (saveClones.test(nodeName)) {
1147 node = (data.cache[nodeName] = data.createElem(nodeName)).cloneNode();
1149 node = data.createElem(nodeName);
1152 // Avoid adding some elements to fragments in IE < 9 because
1153 // * Attributes like `name` or `type` cannot be set/changed once an element
1154 // is inserted into a document/fragment
1155 // * Link elements with `src` attributes that are inaccessible, as with
1156 // a 403 response, will cause the tab/window to crash
1157 // * Script elements appended to fragments will execute when their `src`
1158 // or `text` property is set
1159 return node.canHaveChildren && !reSkip.test(nodeName) ? data.frag.appendChild(node) : node;
1163 * returns a shived DocumentFragment for the given document
1165 * @param {Document} ownerDocument The context document.
1166 * @returns {Object} The shived DocumentFragment.
1168 function createDocumentFragment(ownerDocument, data){
1169 if (!ownerDocument) {
1170 ownerDocument = document;
1172 if(supportsUnknownElements){
1173 return ownerDocument.createDocumentFragment();
1175 data = data || getExpandoData(ownerDocument);
1176 var clone = data.frag.cloneNode(),
1178 elems = getElements(),
1181 clone.createElement(elems[i]);
1187 * Shivs the `createElement` and `createDocumentFragment` methods of the document.
1189 * @param {Document|DocumentFragment} ownerDocument The document.
1190 * @param {Object} data of the document.
1192 function shivMethods(ownerDocument, data) {
1195 data.createElem = ownerDocument.createElement;
1196 data.createFrag = ownerDocument.createDocumentFragment;
1197 data.frag = data.createFrag();
1201 ownerDocument.createElement = function(nodeName) {
1203 if (!html5.shivMethods) {
1204 return data.createElem(nodeName);
1206 return createElement(nodeName, ownerDocument, data);
1209 ownerDocument.createDocumentFragment = Function('h,f', 'return function(){' +
1210 'var n=f.cloneNode(),c=n.createElement;' +
1211 'h.shivMethods&&(' +
1212 // unroll the `createElement` calls
1213 getElements().join().replace(/\w+/g, function(nodeName) {
1214 data.createElem(nodeName);
1215 data.frag.createElement(nodeName);
1216 return 'c("' + nodeName + '")';
1219 )(html5, data.frag);
1222 /*--------------------------------------------------------------------------*/
1225 * Shivs the given document.
1227 * @param {Document} ownerDocument The document to shiv.
1228 * @returns {Document} The shived document.
1230 function shivDocument(ownerDocument) {
1231 if (!ownerDocument) {
1232 ownerDocument = document;
1234 var data = getExpandoData(ownerDocument);
1236 if (html5.shivCSS && !supportsHtml5Styles && !data.hasCSS) {
1237 data.hasCSS = !!addStyleSheet(ownerDocument,
1238 // corrects block display not defined in IE6/7/8/9
1239 'article,aside,figcaption,figure,footer,header,hgroup,nav,section{display:block}' +
1240 // adds styling not present in IE6/7/8/9
1241 'mark{background:#FF0;color:#000}'
1244 if (!supportsUnknownElements) {
1245 shivMethods(ownerDocument, data);
1247 return ownerDocument;
1250 /*--------------------------------------------------------------------------*/
1253 * The `html5` object is exposed so that more elements can be shived and
1254 * existing shiving can be detected on iframes.
1258 * // options can be changed before the script is included
1259 * html5 = { 'elements': 'mark section', 'shivCSS': false, 'shivMethods': false };
1264 * An array or space separated string of node names of the elements to shiv.
1266 * @type Array|String
1268 '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',
1271 * A flag to indicate that the HTML5 style sheet should be inserted.
1275 'shivCSS': (options.shivCSS !== false),
1278 * Is equal to true if a browser supports creating unknown/HTML5 elements
1282 'supportsUnknownElements': supportsUnknownElements,
1285 * A flag to indicate that the document's `createElement` and `createDocumentFragment`
1286 * methods should be overwritten.
1290 'shivMethods': (options.shivMethods !== false),
1293 * A string to describe the type of `html5` object ("default" or "default print").
1299 // shivs the document according to the specified `html5` object options
1300 'shivDocument': shivDocument,
1302 //creates a shived element
1303 createElement: createElement,
1305 //creates a shived documentFragment
1306 createDocumentFragment: createDocumentFragment
1309 /*--------------------------------------------------------------------------*/
1312 window.html5 = html5;
1314 // shiv the document
1315 shivDocument(document);
1320 // Assign private properties to the return object with prefix
1321 Modernizr._version = version;
1323 // expose these for the plugin API. Look in the source for how to join() them against your input
1325 Modernizr._prefixes = prefixes;
1328 Modernizr._domPrefixes = domPrefixes;
1329 Modernizr._cssomPrefixes = cssomPrefixes;
1333 // Modernizr.mq tests a given media query, live against the current state of the window
1334 // A few important notes:
1335 // * If a browser does not support media queries at all (eg. oldIE) the mq() will always return false
1336 // * A max-width or orientation query will be evaluated against the current state, which may change later.
1337 // * You must specify values. Eg. If you are testing support for the min-width media query use:
1338 // Modernizr.mq('(min-width:0)')
1340 // Modernizr.mq('only screen and (max-width:768)')
1341 Modernizr.mq = testMediaQuery;
1345 // Modernizr.hasEvent() detects support for a given event, with an optional element to test on
1346 // Modernizr.hasEvent('gesturestart', elem)
1347 Modernizr.hasEvent = isEventSupported;
1351 // Modernizr.testProp() investigates whether a given style property is recognized
1352 // Note that the property names must be provided in the camelCase variant.
1353 // Modernizr.testProp('pointerEvents')
1354 Modernizr.testProp = function(prop){
1355 return testProps([prop]);
1360 // Modernizr.testAllProps() investigates whether a given style property,
1361 // or any of its vendor-prefixed variants, is recognized
1362 // Note that the property names must be provided in the camelCase variant.
1363 // Modernizr.testAllProps('boxSizing')
1364 Modernizr.testAllProps = testPropsAll;
1369 // Modernizr.testStyles() allows you to add custom styles to the document and test an element afterwards
1370 // Modernizr.testStyles('#modernizr { position:absolute }', function(elem, rule){ ... })
1371 Modernizr.testStyles = injectElementWithStyles;
1376 // Modernizr.prefixed() returns the prefixed or nonprefixed property name variant of your input
1377 // Modernizr.prefixed('boxSizing') // 'MozBoxSizing'
1379 // Properties must be passed as dom-style camelcase, rather than `box-sizing` hypentated style.
1380 // Return values will also be the camelCase variant, if you need to translate that to hypenated style use:
1382 // str.replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
1384 // If you're trying to ascertain which transition end event to bind to, you might do something like...
1386 // var transEndEventNames = {
1387 // 'WebkitTransition' : 'webkitTransitionEnd',
1388 // 'MozTransition' : 'transitionend',
1389 // 'OTransition' : 'oTransitionEnd',
1390 // 'msTransition' : 'MSTransitionEnd',
1391 // 'transition' : 'transitionend'
1393 // transEndEventName = transEndEventNames[ Modernizr.prefixed('transition') ];
1395 Modernizr.prefixed = function(prop, obj, elem){
1397 return testPropsAll(prop, 'pfx');
1399 // Testing DOM property e.g. Modernizr.prefixed('requestAnimationFrame', window) // 'mozRequestAnimationFrame'
1400 return testPropsAll(prop, obj, elem);
1407 // Remove "no-js" class from <html> element, if it exists:
1408 docElement.className = docElement.className.replace(/(^|\s)no-js(\s|$)/, '$1$2') +
1410 // Add the new classes to the <html> element.
1411 (enableClasses ? ' js ' + classes.join(' ') : '');
1416 })(this, this.document);