1+ /*! HTML5 Shiv v3.5 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed */
2+ ; ( function ( window , document ) {
3+
4+ /** Preset options */
5+ var options = window . html5 || { } ;
6+
7+ /** Used to skip problem elements */
8+ var reSkip = / ^ < | ^ (?: b u t t o n | f o r m | m a p | s e l e c t | t e x t a r e a | o b j e c t | i f r a m e | o p t i o n | o p t g r o u p ) $ / i;
9+
10+ /** Not all elements can be cloned in IE (this list can be shortend) **/
11+ var saveClones = / ^ < | ^ (?: a | b | b u t t o n | c o d e | d i v | f i e l d s e t | f o r m | h 1 | h 2 | h 3 | h 4 | h 5 | h 6 | i | i f r a m e | i m g | i n p u t | l a b e l | l i | l i n k | o l | o p t i o n | p | p a r a m | q | s c r i p t | s e l e c t | s p a n | s t r o n g | s t y l e | t a b l e | t b o d y | t d | t e x t a r e a | t f o o t | t h | t h e a d | t r | u l ) $ / i;
12+
13+ /** Detect whether the browser supports default html5 styles */
14+ var supportsHtml5Styles ;
15+
16+ /** Detect whether the browser supports unknown elements */
17+ var supportsUnknownElements ;
18+
19+ ( function ( ) {
20+ var a = document . createElement ( 'a' ) ;
21+
22+ a . innerHTML = '<xyz></xyz>' ;
23+
24+ //if the hidden property is implemented we can assume, that the browser supports HTML5 Styles | this fails in Chrome 8
25+ supportsHtml5Styles = ( 'hidden' in a ) ;
26+ //if we are part of Modernizr, we do an additional test to solve the Chrome 8 fail
27+ if ( supportsHtml5Styles && typeof injectElementWithStyles == 'function' ) {
28+ injectElementWithStyles ( '#modernizr{}' , function ( node ) {
29+ node . hidden = true ;
30+ supportsHtml5Styles = ( window . getComputedStyle ?
31+ getComputedStyle ( node , null ) :
32+ node . currentStyle ) . display == 'none' ;
33+ } ) ;
34+ }
35+
36+ supportsUnknownElements = a . childNodes . length == 1 || ( function ( ) {
37+ // assign a false positive if unable to shiv
38+ try {
39+ ( document . createElement ) ( 'a' ) ;
40+ } catch ( e ) {
41+ return true ;
42+ }
43+ var frag = document . createDocumentFragment ( ) ;
44+ return (
45+ typeof frag . cloneNode == 'undefined' ||
46+ typeof frag . createDocumentFragment == 'undefined' ||
47+ typeof frag . createElement == 'undefined'
48+ ) ;
49+ } ( ) ) ;
50+
51+ } ( ) ) ;
52+
53+ /*--------------------------------------------------------------------------*/
54+
55+ /**
56+ * Creates a style sheet with the given CSS text and adds it to the document.
57+ * @private
58+ * @param {Document } ownerDocument The document.
59+ * @param {String } cssText The CSS text.
60+ * @returns {StyleSheet } The style element.
61+ */
62+ function addStyleSheet ( ownerDocument , cssText ) {
63+ var p = ownerDocument . createElement ( 'p' ) ,
64+ parent = ownerDocument . getElementsByTagName ( 'head' ) [ 0 ] || ownerDocument . documentElement ;
65+
66+ p . innerHTML = 'x<style>' + cssText + '</style>' ;
67+ return parent . insertBefore ( p . lastChild , parent . firstChild ) ;
68+ }
69+
70+ /**
71+ * Returns the value of `html5.elements` as an array.
72+ * @private
73+ * @returns {Array } An array of shived element node names.
74+ */
75+ function getElements ( ) {
76+ var elements = html5 . elements ;
77+ return typeof elements == 'string' ? elements . split ( ' ' ) : elements ;
78+ }
79+
80+ /**
81+ * Shivs the `createElement` and `createDocumentFragment` methods of the document.
82+ * @private
83+ * @param {Document|DocumentFragment } ownerDocument The document.
84+ */
85+ function shivMethods ( ownerDocument ) {
86+ var cache = { } ,
87+ docCreateElement = ownerDocument . createElement ,
88+ docCreateFragment = ownerDocument . createDocumentFragment ,
89+ frag = docCreateFragment ( ) ;
90+
91+ ownerDocument . createElement = function ( nodeName ) {
92+ //abort shiv
93+ if ( ! html5 . shivMethods ) {
94+ return docCreateElement ( nodeName ) ;
95+ }
96+
97+ var node ;
98+
99+ if ( cache [ nodeName ] ) {
100+ node = cache [ nodeName ] . cloneNode ( ) ;
101+ } else if ( saveClones . test ( nodeName ) ) {
102+ node = ( cache [ nodeName ] = docCreateElement ( nodeName ) ) . cloneNode ( ) ;
103+ } else {
104+ node = docCreateElement ( nodeName ) ;
105+ }
106+
107+ // Avoid adding some elements to fragments in IE < 9 because
108+ // * Attributes like `name` or `type` cannot be set/changed once an element
109+ // is inserted into a document/fragment
110+ // * Link elements with `src` attributes that are inaccessible, as with
111+ // a 403 response, will cause the tab/window to crash
112+ // * Script elements appended to fragments will execute when their `src`
113+ // or `text` property is set
114+ return node . canHaveChildren && ! reSkip . test ( nodeName ) ? frag . appendChild ( node ) : node ;
115+ } ;
116+
117+ ownerDocument . createDocumentFragment = Function ( 'h,f' , 'return function(){' +
118+ 'var n=f.cloneNode(),c=n.createElement;' +
119+ 'h.shivMethods&&(' +
120+ // unroll the `createElement` calls
121+ getElements ( ) . join ( ) . replace ( / \w + / g, function ( nodeName ) {
122+ docCreateElement ( nodeName ) ;
123+ frag . createElement ( nodeName ) ;
124+ return 'c("' + nodeName + '")' ;
125+ } ) +
126+ ');return n}'
127+ ) ( html5 , frag ) ;
128+ }
129+
130+ /*--------------------------------------------------------------------------*/
131+
132+ /**
133+ * Shivs the given document.
134+ * @memberOf html5
135+ * @param {Document } ownerDocument The document to shiv.
136+ * @returns {Document } The shived document.
137+ */
138+ function shivDocument ( ownerDocument ) {
139+ var shived ;
140+ if ( ownerDocument . documentShived ) {
141+ return ownerDocument ;
142+ }
143+ if ( html5 . shivCSS && ! supportsHtml5Styles ) {
144+ shived = ! ! addStyleSheet ( ownerDocument ,
145+ // corrects block display not defined in IE6/7/8/9
146+ 'article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block}' +
147+ // corrects audio display not defined in IE6/7/8/9
148+ 'audio{display:none}' +
149+ // corrects canvas and video display not defined in IE6/7/8/9
150+ 'canvas,video{display:inline-block;*display:inline;*zoom:1}' +
151+ // corrects 'hidden' attribute and audio[controls] display not present in IE7/8/9
152+ '[hidden]{display:none}audio[controls]{display:inline-block;*display:inline;*zoom:1}' +
153+ // adds styling not present in IE6/7/8/9
154+ 'mark{background:#FF0;color:#000}'
155+ ) ;
156+ }
157+ if ( ! supportsUnknownElements ) {
158+ shived = ! shivMethods ( ownerDocument ) ;
159+ }
160+ if ( shived ) {
161+ ownerDocument . documentShived = shived ;
162+ }
163+ return ownerDocument ;
164+ }
165+
166+ /*--------------------------------------------------------------------------*/
167+
168+ /**
169+ * The `html5` object is exposed so that more elements can be shived and
170+ * existing shiving can be detected on iframes.
171+ * @type Object
172+ * @example
173+ *
174+ * // options can be changed before the script is included
175+ * html5 = { 'elements': 'mark section', 'shivCSS': false, 'shivMethods': false };
176+ */
177+ var html5 = {
178+
179+ /**
180+ * An array or space separated string of node names of the elements to shiv.
181+ * @memberOf html5
182+ * @type Array|String
183+ */
184+ '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' ,
185+
186+ /**
187+ * A flag to indicate that the HTML5 style sheet should be inserted.
188+ * @memberOf html5
189+ * @type Boolean
190+ */
191+ 'shivCSS' : ! ( options . shivCSS === false ) ,
192+
193+ /**
194+ * A flag to indicate that the document's `createElement` and `createDocumentFragment`
195+ * methods should be overwritten.
196+ * @memberOf html5
197+ * @type Boolean
198+ */
199+ 'shivMethods' : ! ( options . shivMethods === false ) ,
200+
201+ /**
202+ * A string to describe the type of `html5` object ("default" or "default print").
203+ * @memberOf html5
204+ * @type String
205+ */
206+ 'type' : 'default' ,
207+
208+ // shivs the document according to the specified `html5` object options
209+ 'shivDocument' : shivDocument
210+ } ;
211+
212+ /*--------------------------------------------------------------------------*/
213+
214+ // expose html5
215+ window . html5 = html5 ;
216+
217+ // shiv the document
218+ shivDocument ( document ) ;
219+
220+ } ( this , document ) ) ;
0 commit comments