markus / MarkusLogview / MARKUS_LOGVIEW / Scripts / modernizr-2.6.2.js @ 068113d5
이력 | 보기 | 이력해설 | 다운로드 (50.3 KB)
1 |
/* NUGET: BEGIN LICENSE TEXT
|
---|---|
2 |
*
|
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.
|
13 |
*
|
14 |
* Copyright (c) Faruk Ates, Paul Irish, Alex Sexton; http://www.modernizr.com/license/
|
15 |
*
|
16 |
* Includes matchMedia polyfill; Copyright (c) 2010 Filament Group, Inc; http://opensource.org/licenses/MIT
|
17 |
*
|
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
|
19 |
*
|
20 |
* Includes material from css-support; Copyright (c) 2005-2012 Diego Perini; https://github.com/dperini/css-support/blob/master/LICENSE
|
21 |
*
|
22 |
* NUGET: END LICENSE TEXT */
|
23 |
|
24 |
/*!
|
25 |
* Modernizr v2.6.2
|
26 |
* www.modernizr.com
|
27 |
*
|
28 |
* Copyright (c) Faruk Ates, Paul Irish, Alex Sexton
|
29 |
* Available under the BSD and MIT licenses: www.modernizr.com/license/
|
30 |
*/
|
31 |
|
32 |
/*
|
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.
|
38 |
*
|
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/
|
43 |
*
|
44 |
* Authors Faruk Ates, Paul Irish, Alex Sexton
|
45 |
* Contributors Ryan Seddon, Ben Alman
|
46 |
*/
|
47 |
|
48 |
window.Modernizr = (function( window, document, undefined ) { |
49 |
|
50 |
var version = '2.6.2', |
51 |
|
52 |
Modernizr = {}, |
53 |
|
54 |
/*>>cssclasses*/
|
55 |
// option for enabling the HTML classes to be added
|
56 |
enableClasses = true,
|
57 |
/*>>cssclasses*/
|
58 |
|
59 |
docElement = document.documentElement, |
60 |
|
61 |
/**
|
62 |
* Create our "modernizr" element that we do most feature tests on.
|
63 |
*/
|
64 |
mod = 'modernizr',
|
65 |
modElem = document.createElement(mod), |
66 |
mStyle = modElem.style, |
67 |
|
68 |
/**
|
69 |
* Create the input element for various Web Forms feature tests.
|
70 |
*/
|
71 |
inputElem /*>>inputelem*/ = document.createElement('input') /*>>inputelem*/ , |
72 |
|
73 |
/*>>smile*/
|
74 |
smile = ':)',
|
75 |
/*>>smile*/
|
76 |
|
77 |
toString = {}.toString, |
78 |
|
79 |
// TODO :: make the prefixes more granular
|
80 |
/*>>prefixes*/
|
81 |
// List of property values to set for css tests. See ticket #21
|
82 |
prefixes = ' -webkit- -moz- -o- -ms- '.split(' '), |
83 |
/*>>prefixes*/
|
84 |
|
85 |
/*>>domprefixes*/
|
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
|
90 |
|
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/
|
94 |
|
95 |
// More here: github.com/Modernizr/Modernizr/issues/issue/21
|
96 |
omPrefixes = 'Webkit Moz O ms',
|
97 |
|
98 |
cssomPrefixes = omPrefixes.split(' '),
|
99 |
|
100 |
domPrefixes = omPrefixes.toLowerCase().split(' '),
|
101 |
/*>>domprefixes*/
|
102 |
|
103 |
/*>>ns*/
|
104 |
ns = {'svg': 'http://www.w3.org/2000/svg'}, |
105 |
/*>>ns*/
|
106 |
|
107 |
tests = {}, |
108 |
inputs = {}, |
109 |
attrs = {}, |
110 |
|
111 |
classes = [], |
112 |
|
113 |
slice = classes.slice, |
114 |
|
115 |
featureName, // used in testing loop
|
116 |
|
117 |
|
118 |
/*>>teststyles*/
|
119 |
// Inject element with style element and some CSS rules
|
120 |
injectElementWithStyles = function( rule, callback, nodes, testnames ) { |
121 |
|
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');
|
128 |
|
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
|
132 |
while ( nodes-- ) {
|
133 |
node = document.createElement('div');
|
134 |
node.id = testnames ? testnames[nodes] : mod + (nodes + 1);
|
135 |
div.appendChild(node); |
136 |
} |
137 |
} |
138 |
|
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(''); |
145 |
div.id = mod; |
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); |
150 |
if ( !body ) {
|
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); |
158 |
} |
159 |
|
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
|
162 |
if ( !body ) {
|
163 |
fakeBody.parentNode.removeChild(fakeBody); |
164 |
docElement.style.overflow = docOverflow; |
165 |
} else {
|
166 |
div.parentNode.removeChild(div); |
167 |
} |
168 |
|
169 |
return !!ret;
|
170 |
|
171 |
}, |
172 |
/*>>teststyles*/
|
173 |
|
174 |
/*>>mq*/
|
175 |
// adapted from matchMedia polyfill
|
176 |
// by Scott Jehl and Paul Irish
|
177 |
// gist.github.com/786768
|
178 |
testMediaQuery = function( mq ) { |
179 |
|
180 |
var matchMedia = window.matchMedia || window.msMatchMedia;
|
181 |
if ( matchMedia ) {
|
182 |
return matchMedia(mq).matches;
|
183 |
} |
184 |
|
185 |
var bool;
|
186 |
|
187 |
injectElementWithStyles('@media ' + mq + ' { #' + mod + ' { position: absolute; } }', function( node ) { |
188 |
bool = (window.getComputedStyle ? |
189 |
getComputedStyle(node, null) :
|
190 |
node.currentStyle)['position'] == 'absolute'; |
191 |
}); |
192 |
|
193 |
return bool;
|
194 |
|
195 |
}, |
196 |
/*>>mq*/
|
197 |
|
198 |
|
199 |
/*>>hasevent*/
|
200 |
//
|
201 |
// isEventSupported determines if a given element supports the given event
|
202 |
// kangax.github.com/iseventsupported/
|
203 |
//
|
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
|
207 |
// ...
|
208 |
isEventSupported = (function() {
|
209 |
|
210 |
var TAGNAMES = {
|
211 |
'select': 'input', 'change': 'input', |
212 |
'submit': 'form', 'reset': 'form', |
213 |
'error': 'img', 'load': 'img', 'abort': 'img' |
214 |
}; |
215 |
|
216 |
function isEventSupported( eventName, element ) { |
217 |
|
218 |
element = element || document.createElement(TAGNAMES[eventName] || 'div');
|
219 |
eventName = 'on' + eventName;
|
220 |
|
221 |
// When using `setAttribute`, IE skips "unload", WebKit skips "unload" and "resize", whereas `in` "catches" those
|
222 |
var isSupported = eventName in element; |
223 |
|
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');
|
228 |
} |
229 |
if ( element.setAttribute && element.removeAttribute ) {
|
230 |
element.setAttribute(eventName, '');
|
231 |
isSupported = is(element[eventName], 'function');
|
232 |
|
233 |
// If property was created, "remove it" (by setting value to `undefined`)
|
234 |
if ( !is(element[eventName], 'undefined') ) { |
235 |
element[eventName] = undefined;
|
236 |
} |
237 |
element.removeAttribute(eventName); |
238 |
} |
239 |
} |
240 |
|
241 |
element = null;
|
242 |
return isSupported;
|
243 |
} |
244 |
return isEventSupported;
|
245 |
})(), |
246 |
/*>>hasevent*/
|
247 |
|
248 |
// TODO :: Add flag for hasownprop ? didn't last time
|
249 |
|
250 |
// hasOwnProperty shim by kangax needed for Safari 2.0 support
|
251 |
_hasOwnProperty = ({}).hasOwnProperty, hasOwnProp; |
252 |
|
253 |
if ( !is(_hasOwnProperty, 'undefined') && !is(_hasOwnProperty.call, 'undefined') ) { |
254 |
hasOwnProp = function (object, property) { |
255 |
return _hasOwnProperty.call(object, property);
|
256 |
}; |
257 |
} |
258 |
else {
|
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')); |
261 |
}; |
262 |
} |
263 |
|
264 |
// Adapted from ES5-shim https://github.com/kriskowal/es5-shim/blob/master/es5-shim.js
|
265 |
// es5.github.com/#x15.3.4.5
|
266 |
|
267 |
if (!Function.prototype.bind) {
|
268 |
Function.prototype.bind = function bind(that) { |
269 |
|
270 |
var target = this; |
271 |
|
272 |
if (typeof target != "function") { |
273 |
throw new TypeError(); |
274 |
} |
275 |
|
276 |
var args = slice.call(arguments, 1), |
277 |
bound = function () { |
278 |
|
279 |
if (this instanceof bound) { |
280 |
|
281 |
var F = function(){}; |
282 |
F.prototype = target.prototype; |
283 |
var self = new F(); |
284 |
|
285 |
var result = target.apply(
|
286 |
self, |
287 |
args.concat(slice.call(arguments))
|
288 |
); |
289 |
if (Object(result) === result) {
|
290 |
return result;
|
291 |
} |
292 |
return self;
|
293 |
|
294 |
} else {
|
295 |
|
296 |
return target.apply(
|
297 |
that, |
298 |
args.concat(slice.call(arguments))
|
299 |
); |
300 |
|
301 |
} |
302 |
|
303 |
}; |
304 |
|
305 |
return bound;
|
306 |
}; |
307 |
} |
308 |
|
309 |
/**
|
310 |
* setCss applies given styles to the Modernizr DOM node.
|
311 |
*/
|
312 |
function setCss( str ) { |
313 |
mStyle.cssText = str; |
314 |
} |
315 |
|
316 |
/**
|
317 |
* setCssAll extrapolates all vendor-specific css strings.
|
318 |
*/
|
319 |
function setCssAll( str1, str2 ) { |
320 |
return setCss(prefixes.join(str1 + ';') + ( str2 || '' )); |
321 |
} |
322 |
|
323 |
/**
|
324 |
* is returns a boolean for if typeof obj is exactly type.
|
325 |
*/
|
326 |
function is( obj, type ) { |
327 |
return typeof obj === type; |
328 |
} |
329 |
|
330 |
/**
|
331 |
* contains returns a boolean for if substr is found within str.
|
332 |
*/
|
333 |
function contains( str, substr ) { |
334 |
return !!~('' + str).indexOf(substr); |
335 |
} |
336 |
|
337 |
/*>>testprop*/
|
338 |
|
339 |
// testProps is a generic CSS / DOM property test.
|
340 |
|
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.
|
345 |
|
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
|
348 |
// empty string.
|
349 |
|
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.
|
356 |
|
357 |
function testProps( props, prefixed ) { |
358 |
for ( var i in props ) { |
359 |
var prop = props[i];
|
360 |
if ( !contains(prop, "-") && mStyle[prop] !== undefined ) { |
361 |
return prefixed == 'pfx' ? prop : true; |
362 |
} |
363 |
} |
364 |
return false; |
365 |
} |
366 |
/*>>testprop*/
|
367 |
|
368 |
// TODO :: add testDOMProps
|
369 |
/**
|
370 |
* testDOMProps is a generic DOM property test; if a browser supports
|
371 |
* a certain property, it won't return undefined for it.
|
372 |
*/
|
373 |
function testDOMProps( props, obj, elem ) { |
374 |
for ( var i in props ) { |
375 |
var item = obj[props[i]];
|
376 |
if ( item !== undefined) { |
377 |
|
378 |
// return the property name as a string
|
379 |
if (elem === false) return props[i]; |
380 |
|
381 |
// let's bind a function
|
382 |
if (is(item, 'function')){ |
383 |
// default to autobind unless override
|
384 |
return item.bind(elem || obj);
|
385 |
} |
386 |
|
387 |
// return the unbound function or obj or value
|
388 |
return item;
|
389 |
} |
390 |
} |
391 |
return false; |
392 |
} |
393 |
|
394 |
/*>>testallprops*/
|
395 |
/**
|
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-
|
399 |
* compatibility.
|
400 |
*/
|
401 |
function testPropsAll( prop, prefixed, elem ) { |
402 |
|
403 |
var ucProp = prop.charAt(0).toUpperCase() + prop.slice(1), |
404 |
props = (prop + ' ' + cssomPrefixes.join(ucProp + ' ') + ucProp).split(' '); |
405 |
|
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);
|
409 |
|
410 |
// otherwise, they called .prefixed('requestAnimationFrame', window[, elem])
|
411 |
} else {
|
412 |
props = (prop + ' ' + (domPrefixes).join(ucProp + ' ') + ucProp).split(' '); |
413 |
return testDOMProps(props, prefixed, elem);
|
414 |
} |
415 |
} |
416 |
/*>>testallprops*/
|
417 |
|
418 |
|
419 |
/**
|
420 |
* Tests
|
421 |
* -----
|
422 |
*/
|
423 |
|
424 |
// The *new* flexbox
|
425 |
// dev.w3.org/csswg/css3-flexbox
|
426 |
|
427 |
tests['flexbox'] = function() { |
428 |
return testPropsAll('flexWrap'); |
429 |
}; |
430 |
|
431 |
// The *old* flexbox
|
432 |
// www.w3.org/TR/2009/WD-css3-flexbox-20090723/
|
433 |
|
434 |
tests['flexboxlegacy'] = function() { |
435 |
return testPropsAll('boxDirection'); |
436 |
}; |
437 |
|
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/
|
441 |
|
442 |
tests['canvas'] = function() { |
443 |
var elem = document.createElement('canvas'); |
444 |
return !!(elem.getContext && elem.getContext('2d')); |
445 |
}; |
446 |
|
447 |
tests['canvastext'] = function() { |
448 |
return !!(Modernizr['canvas'] && is(document.createElement('canvas').getContext('2d').fillText, 'function')); |
449 |
}; |
450 |
|
451 |
// webk.it/70117 is tracking a legit WebGL feature detect proposal
|
452 |
|
453 |
// We do a soft detect which may false positive in order to avoid
|
454 |
// an expensive context creation: bugzil.la/732441
|
455 |
|
456 |
tests['webgl'] = function() { |
457 |
return !!window.WebGLRenderingContext;
|
458 |
}; |
459 |
|
460 |
/*
|
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.
|
465 |
*
|
466 |
* Additionally, Chrome (desktop) used to lie about its support on this,
|
467 |
* but that has since been rectified: crbug.com/36415
|
468 |
*
|
469 |
* We also test for Firefox 4 Multitouch Support.
|
470 |
*
|
471 |
* For more info, see: modernizr.github.com/Modernizr/touch.html
|
472 |
*/
|
473 |
|
474 |
tests['touch'] = function() { |
475 |
var bool;
|
476 |
|
477 |
if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) { |
478 |
bool = true;
|
479 |
} else {
|
480 |
injectElementWithStyles(['@media (',prefixes.join('touch-enabled),('),mod,')','{#modernizr{top:9px;position:absolute}}'].join(''), function( node ) { |
481 |
bool = node.offsetTop === 9;
|
482 |
}); |
483 |
} |
484 |
|
485 |
return bool;
|
486 |
}; |
487 |
|
488 |
|
489 |
// geolocation is often considered a trivial feature detect...
|
490 |
// Turns out, it's quite tricky to get right:
|
491 |
//
|
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
|
495 |
//
|
496 |
// Meanwhile, in Firefox < 8, an about:config setting could expose
|
497 |
// a false positive that would throw an exception: bugzil.la/688158
|
498 |
|
499 |
tests['geolocation'] = function() { |
500 |
return 'geolocation' in navigator; |
501 |
}; |
502 |
|
503 |
|
504 |
tests['postmessage'] = function() { |
505 |
return !!window.postMessage;
|
506 |
}; |
507 |
|
508 |
|
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;
|
513 |
}; |
514 |
|
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); |
521 |
}; |
522 |
|
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); |
527 |
}; |
528 |
|
529 |
// Per 1.6:
|
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);
|
536 |
}; |
537 |
|
538 |
tests['draganddrop'] = function() { |
539 |
var div = document.createElement('div'); |
540 |
return ('draggable' in div) || ('ondragstart' in div && 'ondrop' in div); |
541 |
}; |
542 |
|
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; |
549 |
}; |
550 |
|
551 |
|
552 |
// css-tricks.com/rgba-browser-support/
|
553 |
tests['rgba'] = function() { |
554 |
// Set an rgba() color and check the returned value
|
555 |
|
556 |
setCss('background-color:rgba(150,255,150,.5)');
|
557 |
|
558 |
return contains(mStyle.backgroundColor, 'rgba'); |
559 |
}; |
560 |
|
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
|
564 |
|
565 |
setCss('background-color:hsla(120,40%,100%,.5)');
|
566 |
|
567 |
return contains(mStyle.backgroundColor, 'rgba') || contains(mStyle.backgroundColor, 'hsla'); |
568 |
}; |
569 |
|
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!
|
574 |
|
575 |
setCss('background:url(https://),url(https://),red url(https://)');
|
576 |
|
577 |
// If the UA supports multiple backgrounds, there should be three occurrences
|
578 |
// of the string "url(" in the return value for elemStyle.background
|
579 |
|
580 |
return (/(url\s*\(.*?){3}/).test(mStyle.background); |
581 |
}; |
582 |
|
583 |
|
584 |
|
585 |
// this will false positive in Opera Mini
|
586 |
// github.com/Modernizr/Modernizr/issues/396
|
587 |
|
588 |
tests['backgroundsize'] = function() { |
589 |
return testPropsAll('backgroundSize'); |
590 |
}; |
591 |
|
592 |
tests['borderimage'] = function() { |
593 |
return testPropsAll('borderImage'); |
594 |
}; |
595 |
|
596 |
|
597 |
// Super comprehensive table about all the unique implementations of
|
598 |
// border-radius: muddledramblings.com/table-of-css3-border-radius-compliance
|
599 |
|
600 |
tests['borderradius'] = function() { |
601 |
return testPropsAll('borderRadius'); |
602 |
}; |
603 |
|
604 |
// WebOS unfortunately false positives on this test.
|
605 |
tests['boxshadow'] = function() { |
606 |
return testPropsAll('boxShadow'); |
607 |
}; |
608 |
|
609 |
// FF3.0 will false positive on this test
|
610 |
tests['textshadow'] = function() { |
611 |
return document.createElement('div').style.textShadow === ''; |
612 |
}; |
613 |
|
614 |
|
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.
|
619 |
|
620 |
setCssAll('opacity:.55');
|
621 |
|
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); |
626 |
}; |
627 |
|
628 |
|
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'); |
634 |
}; |
635 |
|
636 |
|
637 |
tests['csscolumns'] = function() { |
638 |
return testPropsAll('columnCount'); |
639 |
}; |
640 |
|
641 |
|
642 |
tests['cssgradients'] = function() { |
643 |
/**
|
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-
|
649 |
*/
|
650 |
|
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);';
|
654 |
|
655 |
setCss( |
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)
|
660 |
); |
661 |
|
662 |
return contains(mStyle.backgroundImage, 'gradient'); |
663 |
}; |
664 |
|
665 |
|
666 |
tests['cssreflections'] = function() { |
667 |
return testPropsAll('boxReflect'); |
668 |
}; |
669 |
|
670 |
|
671 |
tests['csstransforms'] = function() { |
672 |
return !!testPropsAll('transform'); |
673 |
}; |
674 |
|
675 |
|
676 |
tests['csstransforms3d'] = function() { |
677 |
|
678 |
var ret = !!testPropsAll('perspective'); |
679 |
|
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 ) { |
685 |
|
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; |
690 |
}); |
691 |
} |
692 |
return ret;
|
693 |
}; |
694 |
|
695 |
|
696 |
tests['csstransitions'] = function() { |
697 |
return testPropsAll('transition'); |
698 |
}; |
699 |
|
700 |
|
701 |
/*>>fontface*/
|
702 |
// @font-face detection routine by Diego Perini
|
703 |
// javascript.nwbox.com/CSSSupport/
|
704 |
|
705 |
// false positives:
|
706 |
// WebOS github.com/Modernizr/Modernizr/issues/342
|
707 |
// WP7 github.com/Modernizr/Modernizr/issues/538
|
708 |
tests['fontface'] = function() { |
709 |
var bool;
|
710 |
|
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 || '') : ''; |
715 |
|
716 |
bool = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0; |
717 |
}); |
718 |
|
719 |
return bool;
|
720 |
}; |
721 |
/*>>fontface*/
|
722 |
|
723 |
// CSS generated content detection
|
724 |
tests['generatedcontent'] = function() { |
725 |
var bool;
|
726 |
|
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;
|
729 |
}); |
730 |
|
731 |
return bool;
|
732 |
}; |
733 |
|
734 |
|
735 |
|
736 |
// These tests evaluate support of the video/audio elements, as well as
|
737 |
// testing what types of content they support.
|
738 |
//
|
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'
|
742 |
//
|
743 |
// Codec values from : github.com/NielsLeenheer/html5test/blob/9106a8/index.html#L845
|
744 |
// thx to NielsLeenheer and zcorpan
|
745 |
|
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
|
749 |
|
750 |
tests['video'] = function() { |
751 |
var elem = document.createElement('video'), |
752 |
bool = false;
|
753 |
|
754 |
// IE9 Running on Windows Server SKU can cause an exception to be thrown, bug #224
|
755 |
try {
|
756 |
if ( bool = !!elem.canPlayType ) {
|
757 |
bool = new Boolean(bool);
|
758 |
bool.ogg = elem.canPlayType('video/ogg; codecs="theora"') .replace(/^no$/,''); |
759 |
|
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$/,''); |
762 |
|
763 |
bool.webm = elem.canPlayType('video/webm; codecs="vp8, vorbis"').replace(/^no$/,''); |
764 |
} |
765 |
|
766 |
} catch(e) { }
|
767 |
|
768 |
return bool;
|
769 |
}; |
770 |
|
771 |
tests['audio'] = function() { |
772 |
var elem = document.createElement('audio'), |
773 |
bool = false;
|
774 |
|
775 |
try {
|
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$/,''); |
780 |
|
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$/,''); |
787 |
} |
788 |
} catch(e) { }
|
789 |
|
790 |
return bool;
|
791 |
}; |
792 |
|
793 |
|
794 |
// In FF4, if disabled, window.localStorage should === null.
|
795 |
|
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
|
799 |
|
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.
|
804 |
|
805 |
// Because we are forced to try/catch this, we'll go aggressive.
|
806 |
|
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
|
810 |
|
811 |
tests['localstorage'] = function() { |
812 |
try {
|
813 |
localStorage.setItem(mod, mod); |
814 |
localStorage.removeItem(mod); |
815 |
return true; |
816 |
} catch(e) {
|
817 |
return false; |
818 |
} |
819 |
}; |
820 |
|
821 |
tests['sessionstorage'] = function() { |
822 |
try {
|
823 |
sessionStorage.setItem(mod, mod); |
824 |
sessionStorage.removeItem(mod); |
825 |
return true; |
826 |
} catch(e) {
|
827 |
return false; |
828 |
} |
829 |
}; |
830 |
|
831 |
|
832 |
tests['webworkers'] = function() { |
833 |
return !!window.Worker;
|
834 |
}; |
835 |
|
836 |
|
837 |
tests['applicationcache'] = function() { |
838 |
return !!window.applicationCache;
|
839 |
}; |
840 |
|
841 |
|
842 |
// Thanks to Erik Dahlstrom
|
843 |
tests['svg'] = function() { |
844 |
return !!document.createElementNS && !!document.createElementNS(ns.svg, 'svg').createSVGRect; |
845 |
}; |
846 |
|
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;
|
853 |
}; |
854 |
|
855 |
// SVG SMIL animation
|
856 |
tests['smil'] = function() { |
857 |
return !!document.createElementNS && /SVGAnimate/.test(toString.call(document.createElementNS(ns.svg, 'animate'))); |
858 |
}; |
859 |
|
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
|
862 |
|
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'))); |
867 |
}; |
868 |
|
869 |
/*>>webforms*/
|
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() { |
873 |
/*>>input*/
|
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
|
880 |
|
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);
|
887 |
} |
888 |
if (attrs.list){
|
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);
|
892 |
} |
893 |
return attrs;
|
894 |
})('autocomplete autofocus list placeholder max min multiple pattern required step'.split(' ')); |
895 |
/*>>input*/
|
896 |
|
897 |
/*>>inputtypes*/
|
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
|
902 |
|
903 |
// Big thanks to @miketaylr for the html5 forms expertise. miketaylr.com/
|
904 |
Modernizr['inputtypes'] = (function(props) { |
905 |
|
906 |
for ( var i = 0, bool, inputElemType, defaultView, len = props.length; i < len; i++ ) { |
907 |
|
908 |
inputElem.setAttribute('type', inputElemType = props[i]);
|
909 |
bool = inputElem.type !== 'text';
|
910 |
|
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
|
914 |
if ( bool ) {
|
915 |
|
916 |
inputElem.value = smile; |
917 |
inputElem.style.cssText = 'position:absolute;visibility:hidden;';
|
918 |
|
919 |
if ( /^range$/.test(inputElemType) && inputElem.style.WebkitAppearance !== undefined ) { |
920 |
|
921 |
docElement.appendChild(inputElem); |
922 |
defaultView = document.defaultView; |
923 |
|
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);
|
930 |
|
931 |
docElement.removeChild(inputElem); |
932 |
|
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
|
936 |
|
937 |
// Interestingly, opera fails the earlier test, so it doesn't
|
938 |
// even make it here.
|
939 |
|
940 |
} else if ( /^(url|email)$/.test(inputElemType) ) { |
941 |
// Real url and email support comes with prebaked validation.
|
942 |
bool = inputElem.checkValidity && inputElem.checkValidity() === false;
|
943 |
|
944 |
} else {
|
945 |
// If the upgraded input compontent rejects the :) text, we got a winner
|
946 |
bool = inputElem.value != smile; |
947 |
} |
948 |
} |
949 |
|
950 |
inputs[ props[i] ] = !!bool; |
951 |
} |
952 |
return inputs;
|
953 |
})('search tel url email datetime date month week time datetime-local number range color'.split(' ')); |
954 |
/*>>inputtypes*/
|
955 |
} |
956 |
/*>>webforms*/
|
957 |
|
958 |
|
959 |
// End of test definitions
|
960 |
// -----------------------
|
961 |
|
962 |
|
963 |
|
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](); |
973 |
|
974 |
classes.push((Modernizr[featureName] ? '' : 'no-') + featureName); |
975 |
} |
976 |
} |
977 |
|
978 |
/*>>webforms*/
|
979 |
// input tests need to run.
|
980 |
Modernizr.input || webforms(); |
981 |
/*>>webforms*/
|
982 |
|
983 |
|
984 |
/**
|
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
|
988 |
*
|
989 |
* @param feature - String naming the feature
|
990 |
* @param test - Function returning true if feature is supported, false if not
|
991 |
*/
|
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 ] ); |
997 |
} |
998 |
} |
999 |
} else {
|
1000 |
|
1001 |
feature = feature.toLowerCase(); |
1002 |
|
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.
|
1009 |
return Modernizr;
|
1010 |
} |
1011 |
|
1012 |
test = typeof test == 'function' ? test() : test; |
1013 |
|
1014 |
if (typeof enableClasses !== "undefined" && enableClasses) { |
1015 |
docElement.className += ' ' + (test ? '' : 'no-') + feature; |
1016 |
} |
1017 |
Modernizr[feature] = test; |
1018 |
|
1019 |
} |
1020 |
|
1021 |
return Modernizr; // allow chaining. |
1022 |
}; |
1023 |
|
1024 |
|
1025 |
// Reset modElem.cssText to nothing to reduce memory footprint.
|
1026 |
setCss('');
|
1027 |
modElem = inputElem = null;
|
1028 |
|
1029 |
/*>>shiv*/
|
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 || {};
|
1035 |
|
1036 |
/** Used to skip problem elements */
|
1037 |
var reSkip = /^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i; |
1038 |
|
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; |
1041 |
|
1042 |
/** Detect whether the browser supports default html5 styles */
|
1043 |
var supportsHtml5Styles;
|
1044 |
|
1045 |
/** Name of the expando, to work with multiple documents or to re-shiv one document */
|
1046 |
var expando = '_html5shiv'; |
1047 |
|
1048 |
/** The id for the the documents expando */
|
1049 |
var expanID = 0; |
1050 |
|
1051 |
/** Cached data for each document */
|
1052 |
var expandoData = {};
|
1053 |
|
1054 |
/** Detect whether the browser supports unknown elements */
|
1055 |
var supportsUnknownElements;
|
1056 |
|
1057 |
(function() {
|
1058 |
try {
|
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); |
1063 |
|
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();
|
1068 |
return (
|
1069 |
typeof frag.cloneNode == 'undefined' || |
1070 |
typeof frag.createDocumentFragment == 'undefined' || |
1071 |
typeof frag.createElement == 'undefined' |
1072 |
); |
1073 |
}()); |
1074 |
} catch(e) {
|
1075 |
supportsHtml5Styles = true;
|
1076 |
supportsUnknownElements = true;
|
1077 |
} |
1078 |
|
1079 |
}()); |
1080 |
|
1081 |
/*--------------------------------------------------------------------------*/
|
1082 |
|
1083 |
/**
|
1084 |
* Creates a style sheet with the given CSS text and adds it to the document.
|
1085 |
* @private
|
1086 |
* @param {Document} ownerDocument The document.
|
1087 |
* @param {String} cssText The CSS text.
|
1088 |
* @returns {StyleSheet} The style element.
|
1089 |
*/
|
1090 |
function addStyleSheet(ownerDocument, cssText) { |
1091 |
var p = ownerDocument.createElement('p'), |
1092 |
parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement; |
1093 |
|
1094 |
p.innerHTML = 'x<style>' + cssText + '</style>'; |
1095 |
return parent.insertBefore(p.lastChild, parent.firstChild);
|
1096 |
} |
1097 |
|
1098 |
/**
|
1099 |
* Returns the value of `html5.elements` as an array.
|
1100 |
* @private
|
1101 |
* @returns {Array} An array of shived element node names.
|
1102 |
*/
|
1103 |
function getElements() { |
1104 |
var elements = html5.elements;
|
1105 |
return typeof elements == 'string' ? elements.split(' ') : elements; |
1106 |
} |
1107 |
|
1108 |
/**
|
1109 |
* Returns the data associated to the given document
|
1110 |
* @private
|
1111 |
* @param {Document} ownerDocument The document.
|
1112 |
* @returns {Object} An object of data.
|
1113 |
*/
|
1114 |
function getExpandoData(ownerDocument) { |
1115 |
var data = expandoData[ownerDocument[expando]];
|
1116 |
if (!data) {
|
1117 |
data = {}; |
1118 |
expanID++; |
1119 |
ownerDocument[expando] = expanID; |
1120 |
expandoData[expanID] = data; |
1121 |
} |
1122 |
return data;
|
1123 |
} |
1124 |
|
1125 |
/**
|
1126 |
* returns a shived element for the given nodeName and document
|
1127 |
* @memberOf html5
|
1128 |
* @param {String} nodeName name of the element
|
1129 |
* @param {Document} ownerDocument The context document.
|
1130 |
* @returns {Object} The shived element.
|
1131 |
*/
|
1132 |
function createElement(nodeName, ownerDocument, data){ |
1133 |
if (!ownerDocument) {
|
1134 |
ownerDocument = document; |
1135 |
} |
1136 |
if(supportsUnknownElements){
|
1137 |
return ownerDocument.createElement(nodeName);
|
1138 |
} |
1139 |
if (!data) {
|
1140 |
data = getExpandoData(ownerDocument); |
1141 |
} |
1142 |
var node;
|
1143 |
|
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(); |
1148 |
} else {
|
1149 |
node = data.createElem(nodeName); |
1150 |
} |
1151 |
|
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;
|
1160 |
} |
1161 |
|
1162 |
/**
|
1163 |
* returns a shived DocumentFragment for the given document
|
1164 |
* @memberOf html5
|
1165 |
* @param {Document} ownerDocument The context document.
|
1166 |
* @returns {Object} The shived DocumentFragment.
|
1167 |
*/
|
1168 |
function createDocumentFragment(ownerDocument, data){ |
1169 |
if (!ownerDocument) {
|
1170 |
ownerDocument = document; |
1171 |
} |
1172 |
if(supportsUnknownElements){
|
1173 |
return ownerDocument.createDocumentFragment();
|
1174 |
} |
1175 |
data = data || getExpandoData(ownerDocument); |
1176 |
var clone = data.frag.cloneNode(),
|
1177 |
i = 0,
|
1178 |
elems = getElements(), |
1179 |
l = elems.length; |
1180 |
for(;i<l;i++){
|
1181 |
clone.createElement(elems[i]); |
1182 |
} |
1183 |
return clone;
|
1184 |
} |
1185 |
|
1186 |
/**
|
1187 |
* Shivs the `createElement` and `createDocumentFragment` methods of the document.
|
1188 |
* @private
|
1189 |
* @param {Document|DocumentFragment} ownerDocument The document.
|
1190 |
* @param {Object} data of the document.
|
1191 |
*/
|
1192 |
function shivMethods(ownerDocument, data) { |
1193 |
if (!data.cache) {
|
1194 |
data.cache = {}; |
1195 |
data.createElem = ownerDocument.createElement; |
1196 |
data.createFrag = ownerDocument.createDocumentFragment; |
1197 |
data.frag = data.createFrag(); |
1198 |
} |
1199 |
|
1200 |
|
1201 |
ownerDocument.createElement = function(nodeName) { |
1202 |
//abort shiv
|
1203 |
if (!html5.shivMethods) {
|
1204 |
return data.createElem(nodeName);
|
1205 |
} |
1206 |
return createElement(nodeName, ownerDocument, data);
|
1207 |
}; |
1208 |
|
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 + '")'; |
1217 |
}) + |
1218 |
');return n}'
|
1219 |
)(html5, data.frag); |
1220 |
} |
1221 |
|
1222 |
/*--------------------------------------------------------------------------*/
|
1223 |
|
1224 |
/**
|
1225 |
* Shivs the given document.
|
1226 |
* @memberOf html5
|
1227 |
* @param {Document} ownerDocument The document to shiv.
|
1228 |
* @returns {Document} The shived document.
|
1229 |
*/
|
1230 |
function shivDocument(ownerDocument) { |
1231 |
if (!ownerDocument) {
|
1232 |
ownerDocument = document; |
1233 |
} |
1234 |
var data = getExpandoData(ownerDocument);
|
1235 |
|
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}'
|
1242 |
); |
1243 |
} |
1244 |
if (!supportsUnknownElements) {
|
1245 |
shivMethods(ownerDocument, data); |
1246 |
} |
1247 |
return ownerDocument;
|
1248 |
} |
1249 |
|
1250 |
/*--------------------------------------------------------------------------*/
|
1251 |
|
1252 |
/**
|
1253 |
* The `html5` object is exposed so that more elements can be shived and
|
1254 |
* existing shiving can be detected on iframes.
|
1255 |
* @type Object
|
1256 |
* @example
|
1257 |
*
|
1258 |
* // options can be changed before the script is included
|
1259 |
* html5 = { 'elements': 'mark section', 'shivCSS': false, 'shivMethods': false };
|
1260 |
*/
|
1261 |
var html5 = {
|
1262 |
|
1263 |
/**
|
1264 |
* An array or space separated string of node names of the elements to shiv.
|
1265 |
* @memberOf html5
|
1266 |
* @type Array|String
|
1267 |
*/
|
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', |
1269 |
|
1270 |
/**
|
1271 |
* A flag to indicate that the HTML5 style sheet should be inserted.
|
1272 |
* @memberOf html5
|
1273 |
* @type Boolean
|
1274 |
*/
|
1275 |
'shivCSS': (options.shivCSS !== false), |
1276 |
|
1277 |
/**
|
1278 |
* Is equal to true if a browser supports creating unknown/HTML5 elements
|
1279 |
* @memberOf html5
|
1280 |
* @type boolean
|
1281 |
*/
|
1282 |
'supportsUnknownElements': supportsUnknownElements,
|
1283 |
|
1284 |
/**
|
1285 |
* A flag to indicate that the document's `createElement` and `createDocumentFragment`
|
1286 |
* methods should be overwritten.
|
1287 |
* @memberOf html5
|
1288 |
* @type Boolean
|
1289 |
*/
|
1290 |
'shivMethods': (options.shivMethods !== false), |
1291 |
|
1292 |
/**
|
1293 |
* A string to describe the type of `html5` object ("default" or "default print").
|
1294 |
* @memberOf html5
|
1295 |
* @type String
|
1296 |
*/
|
1297 |
'type': 'default', |
1298 |
|
1299 |
// shivs the document according to the specified `html5` object options
|
1300 |
'shivDocument': shivDocument,
|
1301 |
|
1302 |
//creates a shived element
|
1303 |
createElement: createElement,
|
1304 |
|
1305 |
//creates a shived documentFragment
|
1306 |
createDocumentFragment: createDocumentFragment
|
1307 |
}; |
1308 |
|
1309 |
/*--------------------------------------------------------------------------*/
|
1310 |
|
1311 |
// expose html5
|
1312 |
window.html5 = html5; |
1313 |
|
1314 |
// shiv the document
|
1315 |
shivDocument(document); |
1316 |
|
1317 |
}(this, document));
|
1318 |
/*>>shiv*/
|
1319 |
|
1320 |
// Assign private properties to the return object with prefix
|
1321 |
Modernizr._version = version; |
1322 |
|
1323 |
// expose these for the plugin API. Look in the source for how to join() them against your input
|
1324 |
/*>>prefixes*/
|
1325 |
Modernizr._prefixes = prefixes; |
1326 |
/*>>prefixes*/
|
1327 |
/*>>domprefixes*/
|
1328 |
Modernizr._domPrefixes = domPrefixes; |
1329 |
Modernizr._cssomPrefixes = cssomPrefixes; |
1330 |
/*>>domprefixes*/
|
1331 |
|
1332 |
/*>>mq*/
|
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)')
|
1339 |
// usage:
|
1340 |
// Modernizr.mq('only screen and (max-width:768)')
|
1341 |
Modernizr.mq = testMediaQuery; |
1342 |
/*>>mq*/
|
1343 |
|
1344 |
/*>>hasevent*/
|
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; |
1348 |
/*>>hasevent*/
|
1349 |
|
1350 |
/*>>testprop*/
|
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]);
|
1356 |
}; |
1357 |
/*>>testprop*/
|
1358 |
|
1359 |
/*>>testallprops*/
|
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; |
1365 |
/*>>testallprops*/
|
1366 |
|
1367 |
|
1368 |
/*>>teststyles*/
|
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; |
1372 |
/*>>teststyles*/
|
1373 |
|
1374 |
|
1375 |
/*>>prefixed*/
|
1376 |
// Modernizr.prefixed() returns the prefixed or nonprefixed property name variant of your input
|
1377 |
// Modernizr.prefixed('boxSizing') // 'MozBoxSizing'
|
1378 |
|
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:
|
1381 |
//
|
1382 |
// str.replace(/([A-Z])/g, function(str,m1){ return '-' + m1.toLowerCase(); }).replace(/^ms-/,'-ms-');
|
1383 |
|
1384 |
// If you're trying to ascertain which transition end event to bind to, you might do something like...
|
1385 |
//
|
1386 |
// var transEndEventNames = {
|
1387 |
// 'WebkitTransition' : 'webkitTransitionEnd',
|
1388 |
// 'MozTransition' : 'transitionend',
|
1389 |
// 'OTransition' : 'oTransitionEnd',
|
1390 |
// 'msTransition' : 'MSTransitionEnd',
|
1391 |
// 'transition' : 'transitionend'
|
1392 |
// },
|
1393 |
// transEndEventName = transEndEventNames[ Modernizr.prefixed('transition') ];
|
1394 |
|
1395 |
Modernizr.prefixed = function(prop, obj, elem){ |
1396 |
if(!obj) {
|
1397 |
return testPropsAll(prop, 'pfx'); |
1398 |
} else {
|
1399 |
// Testing DOM property e.g. Modernizr.prefixed('requestAnimationFrame', window) // 'mozRequestAnimationFrame'
|
1400 |
return testPropsAll(prop, obj, elem);
|
1401 |
} |
1402 |
}; |
1403 |
/*>>prefixed*/
|
1404 |
|
1405 |
|
1406 |
/*>>cssclasses*/
|
1407 |
// Remove "no-js" class from <html> element, if it exists:
|
1408 |
docElement.className = docElement.className.replace(/(^|\s)no-js(\s|$)/, '$1$2') + |
1409 |
|
1410 |
// Add the new classes to the <html> element.
|
1411 |
(enableClasses ? ' js ' + classes.join(' ') : ''); |
1412 |
/*>>cssclasses*/
|
1413 |
|
1414 |
return Modernizr;
|
1415 |
|
1416 |
})(this, this.document); |