Skip to content
Snippets Groups Projects
modernizr.js 50.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • Laura Cappelli's avatar
    Laura Cappelli committed
    1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406
    
        // Reset modElem.cssText to nothing to reduce memory footprint.
        setCss('');
        modElem = inputElem = null;
    
        /*>>shiv*/
        /**
         * @preserve HTML5 Shiv prev3.7.1 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed
         */
        ;(function(window, document) {
            /*jshint evil:true */
            /** version */
            var version = '3.7.0';
    
            /** Preset options */
            var options = window.html5 || {};
    
            /** Used to skip problem elements */
            var reSkip = /^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i;
    
            /** Not all elements can be cloned in IE **/
            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;
    
            /** Detect whether the browser supports default html5 styles */
            var supportsHtml5Styles;
    
            /** Name of the expando, to work with multiple documents or to re-shiv one document */
            var expando = '_html5shiv';
    
            /** The id for the the documents expando */
            var expanID = 0;
    
            /** Cached data for each document */
            var expandoData = {};
    
            /** Detect whether the browser supports unknown elements */
            var supportsUnknownElements;
    
            (function() {
              try {
                var a = document.createElement('a');
                a.innerHTML = '<xyz></xyz>';
                //if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles
                supportsHtml5Styles = ('hidden' in a);
    
                supportsUnknownElements = a.childNodes.length == 1 || (function() {
                  // assign a false positive if unable to shiv
                  (document.createElement)('a');
                  var frag = document.createDocumentFragment();
                  return (
                    typeof frag.cloneNode == 'undefined' ||
                    typeof frag.createDocumentFragment == 'undefined' ||
                    typeof frag.createElement == 'undefined'
                  );
                }());
              } catch(e) {
                // assign a false positive if detection fails => unable to shiv
                supportsHtml5Styles = true;
                supportsUnknownElements = true;
              }
    
            }());
    
            /*--------------------------------------------------------------------------*/
    
            /**
             * Creates a style sheet with the given CSS text and adds it to the document.
             * @private
             * @param {Document} ownerDocument The document.
             * @param {String} cssText The CSS text.
             * @returns {StyleSheet} The style element.
             */
            function addStyleSheet(ownerDocument, cssText) {
              var p = ownerDocument.createElement('p'),
              parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement;
    
              p.innerHTML = 'x<style>' + cssText + '</style>';
              return parent.insertBefore(p.lastChild, parent.firstChild);
            }
    
            /**
             * Returns the value of `html5.elements` as an array.
             * @private
             * @returns {Array} An array of shived element node names.
             */
            function getElements() {
              var elements = html5.elements;
              return typeof elements == 'string' ? elements.split(' ') : elements;
            }
    
            /**
             * Returns the data associated to the given document
             * @private
             * @param {Document} ownerDocument The document.
             * @returns {Object} An object of data.
             */
            function getExpandoData(ownerDocument) {
              var data = expandoData[ownerDocument[expando]];
              if (!data) {
                data = {};
                expanID++;
                ownerDocument[expando] = expanID;
                expandoData[expanID] = data;
              }
              return data;
            }
    
            /**
             * returns a shived element for the given nodeName and document
             * @memberOf html5
             * @param {String} nodeName name of the element
             * @param {Document} ownerDocument The context document.
             * @returns {Object} The shived element.
             */
            function createElement(nodeName, ownerDocument, data){
              if (!ownerDocument) {
                ownerDocument = document;
              }
              if(supportsUnknownElements){
                return ownerDocument.createElement(nodeName);
              }
              if (!data) {
                data = getExpandoData(ownerDocument);
              }
              var node;
    
              if (data.cache[nodeName]) {
                node = data.cache[nodeName].cloneNode();
              } else if (saveClones.test(nodeName)) {
                node = (data.cache[nodeName] = data.createElem(nodeName)).cloneNode();
              } else {
                node = data.createElem(nodeName);
              }
    
              // Avoid adding some elements to fragments in IE < 9 because
              // * Attributes like `name` or `type` cannot be set/changed once an element
              //   is inserted into a document/fragment
              // * Link elements with `src` attributes that are inaccessible, as with
              //   a 403 response, will cause the tab/window to crash
              // * Script elements appended to fragments will execute when their `src`
              //   or `text` property is set
              return node.canHaveChildren && !reSkip.test(nodeName) && !node.tagUrn ? data.frag.appendChild(node) : node;
            }
    
            /**
             * returns a shived DocumentFragment for the given document
             * @memberOf html5
             * @param {Document} ownerDocument The context document.
             * @returns {Object} The shived DocumentFragment.
             */
            function createDocumentFragment(ownerDocument, data){
              if (!ownerDocument) {
                ownerDocument = document;
              }
              if(supportsUnknownElements){
                return ownerDocument.createDocumentFragment();
              }
              data = data || getExpandoData(ownerDocument);
              var clone = data.frag.cloneNode(),
              i = 0,
              elems = getElements(),
              l = elems.length;
              for(;i<l;i++){
                clone.createElement(elems[i]);
              }
              return clone;
            }
    
            /**
             * Shivs the `createElement` and `createDocumentFragment` methods of the document.
             * @private
             * @param {Document|DocumentFragment} ownerDocument The document.
             * @param {Object} data of the document.
             */
            function shivMethods(ownerDocument, data) {
              if (!data.cache) {
                data.cache = {};
                data.createElem = ownerDocument.createElement;
                data.createFrag = ownerDocument.createDocumentFragment;
                data.frag = data.createFrag();
              }
    
    
              ownerDocument.createElement = function(nodeName) {
                //abort shiv
                if (!html5.shivMethods) {
                  return data.createElem(nodeName);
                }
                return createElement(nodeName, ownerDocument, data);
              };
    
              ownerDocument.createDocumentFragment = Function('h,f', 'return function(){' +
                                                              'var n=f.cloneNode(),c=n.createElement;' +
                                                              'h.shivMethods&&(' +
                                                              // unroll the `createElement` calls
                                                              getElements().join().replace(/[\w\-]+/g, function(nodeName) {
                data.createElem(nodeName);
                data.frag.createElement(nodeName);
                return 'c("' + nodeName + '")';
              }) +
                ');return n}'
                                                             )(html5, data.frag);
            }
    
            /*--------------------------------------------------------------------------*/
    
            /**
             * Shivs the given document.
             * @memberOf html5
             * @param {Document} ownerDocument The document to shiv.
             * @returns {Document} The shived document.
             */
            function shivDocument(ownerDocument) {
              if (!ownerDocument) {
                ownerDocument = document;
              }
              var data = getExpandoData(ownerDocument);
    
              if (html5.shivCSS && !supportsHtml5Styles && !data.hasCSS) {
                data.hasCSS = !!addStyleSheet(ownerDocument,
                                              // corrects block display not defined in IE6/7/8/9
                                              'article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}' +
                                                // adds styling not present in IE6/7/8/9
                                                'mark{background:#FF0;color:#000}' +
                                                // hides non-rendered elements
                                                'template{display:none}'
                                             );
              }
              if (!supportsUnknownElements) {
                shivMethods(ownerDocument, data);
              }
              return ownerDocument;
            }
    
            /*--------------------------------------------------------------------------*/
    
            /**
             * The `html5` object is exposed so that more elements can be shived and
             * existing shiving can be detected on iframes.
             * @type Object
             * @example
             *
             * // options can be changed before the script is included
             * html5 = { 'elements': 'mark section', 'shivCSS': false, 'shivMethods': false };
             */
            var html5 = {
    
              /**
               * An array or space separated string of node names of the elements to shiv.
               * @memberOf html5
               * @type Array|String
               */
              'elements': options.elements || 'abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output progress section summary template time video',
    
              /**
               * current version of html5shiv
               */
              'version': version,
    
              /**
               * A flag to indicate that the HTML5 style sheet should be inserted.
               * @memberOf html5
               * @type Boolean
               */
              'shivCSS': (options.shivCSS !== false),
    
              /**
               * Is equal to true if a browser supports creating unknown/HTML5 elements
               * @memberOf html5
               * @type boolean
               */
              'supportsUnknownElements': supportsUnknownElements,
    
              /**
               * A flag to indicate that the document's `createElement` and `createDocumentFragment`
               * methods should be overwritten.
               * @memberOf html5
               * @type Boolean
               */
              'shivMethods': (options.shivMethods !== false),
    
              /**
               * A string to describe the type of `html5` object ("default" or "default print").
               * @memberOf html5
               * @type String
               */
              'type': 'default',
    
              // shivs the document according to the specified `html5` object options
              'shivDocument': shivDocument,
    
              //creates a shived element
              createElement: createElement,
    
              //creates a shived documentFragment
              createDocumentFragment: createDocumentFragment
            };
    
            /*--------------------------------------------------------------------------*/
    
            // expose html5
            window.html5 = html5;
    
            // shiv the document
            shivDocument(document);
    
        }(this, document));
        /*>>shiv*/
    
        // Assign private properties to the return object with prefix
        Modernizr._version      = version;
    
        // expose these for the plugin API. Look in the source for how to join() them against your input
        /*>>prefixes*/
        Modernizr._prefixes     = prefixes;
        /*>>prefixes*/
        /*>>domprefixes*/
        Modernizr._domPrefixes  = domPrefixes;
        Modernizr._cssomPrefixes  = cssomPrefixes;
        /*>>domprefixes*/
    
        /*>>mq*/
        // Modernizr.mq tests a given media query, live against the current state of the window
        // A few important notes:
        //   * If a browser does not support media queries at all (eg. oldIE) the mq() will always return false
        //   * A max-width or orientation query will be evaluated against the current state, which may change later.
        //   * You must specify values. Eg. If you are testing support for the min-width media query use:
        //       Modernizr.mq('(min-width:0)')
        // usage:
        // Modernizr.mq('only screen and (max-width:768)')
        Modernizr.mq            = testMediaQuery;
        /*>>mq*/
    
        /*>>hasevent*/
        // Modernizr.hasEvent() detects support for a given event, with an optional element to test on
        // Modernizr.hasEvent('gesturestart', elem)
        Modernizr.hasEvent      = isEventSupported;
        /*>>hasevent*/
    
        /*>>testprop*/
        // Modernizr.testProp() investigates whether a given style property is recognized
        // Note that the property names must be provided in the camelCase variant.
        // Modernizr.testProp('pointerEvents')
        Modernizr.testProp      = function(prop){
            return testProps([prop]);
        };
        /*>>testprop*/
    
        /*>>testallprops*/
        // Modernizr.testAllProps() investigates whether a given style property,
        //   or any of its vendor-prefixed variants, is recognized
        // Note that the property names must be provided in the camelCase variant.
        // Modernizr.testAllProps('boxSizing')
        Modernizr.testAllProps  = testPropsAll;
        /*>>testallprops*/
    
    
        /*>>teststyles*/
        // Modernizr.testStyles() allows you to add custom styles to the document and test an element afterwards
        // Modernizr.testStyles('#modernizr { position:absolute }', function(elem, rule){ ... })
        Modernizr.testStyles    = injectElementWithStyles;
        /*>>teststyles*/
    
    
        /*>>prefixed*/
        // Modernizr.prefixed() returns the prefixed or nonprefixed property name variant of your input
        // Modernizr.prefixed('boxSizing') // 'MozBoxSizing'
    
        // Properties must be passed as dom-style camelcase, rather than `box-sizing` hypentated style.
        // Return values will also be the camelCase variant, if you need to translate that to hypenated style use:
        //
        //     str.replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
    
        // If you're trying to ascertain which transition end event to bind to, you might do something like...
        //
        //     var transEndEventNames = {
        //       'WebkitTransition' : 'webkitTransitionEnd',
        //       'MozTransition'    : 'transitionend',
        //       'OTransition'      : 'oTransitionEnd',
        //       'msTransition'     : 'MSTransitionEnd',
        //       'transition'       : 'transitionend'
        //     },
        //     transEndEventName = transEndEventNames[ Modernizr.prefixed('transition') ];
    
        Modernizr.prefixed      = function(prop, obj, elem){
          if(!obj) {
            return testPropsAll(prop, 'pfx');
          } else {
            // Testing DOM property e.g. Modernizr.prefixed('requestAnimationFrame', window) // 'mozRequestAnimationFrame'
            return testPropsAll(prop, obj, elem);
          }
        };
        /*>>prefixed*/
    
    
        /*>>cssclasses*/
        // Remove "no-js" class from <html> element, if it exists:
        docElement.className = docElement.className.replace(/(^|\s)no-js(\s|$)/, '$1$2') +
    
                                // Add the new classes to the <html> element.
                                (enableClasses ? ' js ' + classes.join(' ') : '');
        /*>>cssclasses*/
    
        return Modernizr;
    
    })(this, this.document);