22
33jQuery . support = ( function ( ) {
44
5- var div = document . createElement ( "div" ) ,
6- documentElement = document . documentElement ,
5+ var support ,
76 all ,
87 a ,
98 select ,
109 opt ,
1110 input ,
1211 marginDiv ,
13- support ,
1412 fragment ,
15- body ,
16- testElementParent ,
17- testElement ,
18- testElementStyle ,
1913 tds ,
2014 events ,
2115 eventName ,
2216 i ,
23- isSupported ;
17+ isSupported ,
18+ div = document . createElement ( "div" ) ,
19+ documentElement = document . documentElement ;
2420
2521 // Preliminary tests
2622 div . setAttribute ( "className" , "t" ) ;
2723 div . innerHTML = " <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>" ;
2824
29-
3025 all = div . getElementsByTagName ( "*" ) ;
3126 a = div . getElementsByTagName ( "a" ) [ 0 ] ;
3227
@@ -46,19 +41,19 @@ jQuery.support = (function() {
4641
4742 // Make sure that tbody elements aren't automatically inserted
4843 // IE will insert them into empty tables
49- tbody : ! div . getElementsByTagName ( "tbody" ) . length ,
44+ tbody : ! div . getElementsByTagName ( "tbody" ) . length ,
5045
5146 // Make sure that link elements get serialized correctly by innerHTML
5247 // This requires a wrapper element in IE
53- htmlSerialize : ! ! div . getElementsByTagName ( "link" ) . length ,
48+ htmlSerialize : ! ! div . getElementsByTagName ( "link" ) . length ,
5449
5550 // Get the style information from getAttribute
5651 // (IE uses .cssText instead)
5752 style : / t o p / . test ( a . getAttribute ( "style" ) ) ,
5853
5954 // Make sure that URLs aren't manipulated
6055 // (IE normalizes it by default)
61- hrefNormalized : ( a . getAttribute ( "href" ) === "/a" ) ,
56+ hrefNormalized : ( a . getAttribute ( "href" ) === "/a" ) ,
6257
6358 // Make sure that element opacity exists
6459 // (IE uses filter instead)
@@ -140,95 +135,28 @@ jQuery.support = (function() {
140135 // WebKit doesn't clone checked state correctly in fragments
141136 support . checkClone = fragment . cloneNode ( true ) . cloneNode ( true ) . lastChild . checked ;
142137
143- div . innerHTML = "" ;
144-
145- // Figure out if the W3C box model works as expected
146- div . style . width = div . style . paddingLeft = "1px" ;
147-
148- // We don't want to do body-related feature tests on frameset
149- // documents, which lack a body. So we use
150- // document.getElementsByTagName("body")[0], which is undefined in
151- // frameset documents, while document.body isn’t. (7398)
152- body = document . getElementsByTagName ( "body" ) [ 0 ] ;
153- // We use our own, invisible, body unless the body is already present
154- // in which case we use a div (#9239)
155- testElement = document . createElement ( body ? "div" : "body" ) ;
156- testElementStyle = {
157- visibility : "hidden" ,
158- width : 0 ,
159- height : 0 ,
160- border : 0 ,
161- margin : 0 ,
162- background : "none"
163- } ;
164- if ( body ) {
165- jQuery . extend ( testElementStyle , {
166- position : "absolute" ,
167- left : "-999px" ,
168- top : "-999px"
169- } ) ;
170- }
171- for ( i in testElementStyle ) {
172- testElement . style [ i ] = testElementStyle [ i ] ;
173- }
174- testElement . appendChild ( div ) ;
175- testElementParent = body || documentElement ;
176- testElementParent . insertBefore ( testElement , testElementParent . firstChild ) ;
177-
178138 // Check if a disconnected checkbox will retain its checked
179139 // value of true after appended to the DOM (IE6/7)
180140 support . appendChecked = input . checked ;
181141
182- support . boxModel = div . offsetWidth === 2 ;
183-
184- if ( "zoom" in div . style ) {
185- // Check if natively block-level elements act like inline-block
186- // elements when setting their display to 'inline' and giving
187- // them layout
188- // (IE < 8 does this)
189- div . style . display = "inline" ;
190- div . style . zoom = 1 ;
191- support . inlineBlockNeedsLayout = ( div . offsetWidth === 2 ) ;
192-
193- // Check if elements with layout shrink-wrap their children
194- // (IE 6 does this)
195- div . style . display = "" ;
196- div . innerHTML = "<div style='width:4px;'></div>" ;
197- support . shrinkWrapBlocks = ( div . offsetWidth !== 2 ) ;
198- }
199-
200- div . innerHTML = "<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>" ;
201- tds = div . getElementsByTagName ( "td" ) ;
202-
203- // Check if table cells still have offsetWidth/Height when they are set
204- // to display:none and there are still other visible table cells in a
205- // table row; if so, offsetWidth/Height are not reliable for use when
206- // determining if an element has been hidden directly using
207- // display:none (it is still safe to use offsets if a parent element is
208- // hidden; don safety goggles and see bug #4512 for more information).
209- // (only IE 8 fails this test)
210- isSupported = ( tds [ 0 ] . offsetHeight === 0 ) ;
211-
212- tds [ 0 ] . style . display = "" ;
213- tds [ 1 ] . style . display = "none" ;
142+ fragment . removeChild ( input ) ;
143+ fragment . appendChild ( div ) ;
214144
215- // Check if empty table cells still have offsetWidth/Height
216- // (IE < 8 fail this test)
217- support . reliableHiddenOffsets = isSupported && ( tds [ 0 ] . offsetHeight === 0 ) ;
218145 div . innerHTML = "" ;
219146
220147 // Check if div with explicit width and no margin-right incorrectly
221148 // gets computed margin-right based on width of container. For more
222149 // info see bug #3333
223150 // Fails in WebKit before Feb 2011 nightlies
224151 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
225- if ( document . defaultView && document . defaultView . getComputedStyle ) {
152+ if ( window . getComputedStyle ) {
226153 marginDiv = document . createElement ( "div" ) ;
227154 marginDiv . style . width = "0" ;
228155 marginDiv . style . marginRight = "0" ;
156+ div . style . width = "2px" ;
229157 div . appendChild ( marginDiv ) ;
230158 support . reliableMarginRight =
231- ( parseInt ( ( document . defaultView . getComputedStyle ( marginDiv , null ) || { marginRight : 0 } ) . marginRight , 10 ) || 0 ) === 0 ;
159+ ( parseInt ( ( window . getComputedStyle ( marginDiv , null ) || { marginRight : 0 } ) . marginRight , 10 ) || 0 ) === 0 ;
232160 }
233161
234162 // Technique from Juriy Zaytsev
@@ -242,7 +170,7 @@ jQuery.support = (function() {
242170 submit : 1 ,
243171 change : 1 ,
244172 focusin : 1
245- } ) {
173+ } ) {
246174 eventName = "on" + i ;
247175 isSupported = ( eventName in div ) ;
248176 if ( ! isSupported ) {
@@ -253,11 +181,10 @@ jQuery.support = (function() {
253181 }
254182 }
255183
256- testElement . innerHTML = "" ;
257- testElementParent . removeChild ( testElement ) ;
184+ fragment . removeChild ( div ) ;
258185
259- // Null connected elements to avoid leaks in IE
260- testElement = fragment = select = opt = body = marginDiv = div = input = null ;
186+ // Null elements to avoid leaks in IE
187+ fragment = select = opt = body = marginDiv = div = input = null ;
261188
262189 // Run fixed position tests at doc ready to avoid a crash
263190 // related to the invisible body in IE8
@@ -268,8 +195,8 @@ jQuery.support = (function() {
268195 vb = "visibility:hidden;border:0;" ,
269196 style = "style='" + ptlm + "border:5px solid #000;padding:0;'" ,
270197 html = "<div " + style + "><div></div></div>" +
271- "<table " + style + " cellpadding='0' cellspacing='0'>" +
272- "<tr><td></td></tr></table>" ;
198+ "<table " + style + " cellpadding='0' cellspacing='0'>" +
199+ "<tr><td></td></tr></table>" ;
273200
274201 // Reconstruct a container
275202 body = document . getElementsByTagName ( "body" ) [ 0 ] ;
@@ -283,13 +210,53 @@ jQuery.support = (function() {
283210 container . style . cssText = vb + "width:0;height:0;position:static;top:0;margin-top:" + conMarginTop + "px" ;
284211 body . insertBefore ( container , body . firstChild ) ;
285212
286- // Construct a test element
287- testElement = document . createElement ( "div" ) ;
288- testElement . style . cssText = ptlm + vb ;
213+ // Construct the test element
214+ div = document . createElement ( "div" ) ;
215+ container . appendChild ( div ) ;
216+
217+ // Check if table cells still have offsetWidth/Height when they are set
218+ // to display:none and there are still other visible table cells in a
219+ // table row; if so, offsetWidth/Height are not reliable for use when
220+ // determining if an element has been hidden directly using
221+ // display:none (it is still safe to use offsets if a parent element is
222+ // hidden; don safety goggles and see bug #4512 for more information).
223+ // (only IE 8 fails this test)
224+ div . innerHTML = "<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>" ;
225+ tds = div . getElementsByTagName ( "td" ) ;
226+ isSupported = ( tds [ 0 ] . offsetHeight === 0 ) ;
227+
228+ tds [ 0 ] . style . display = "" ;
229+ tds [ 1 ] . style . display = "none" ;
230+
231+ // Check if empty table cells still have offsetWidth/Height
232+ // (IE <= 8 fail this test)
233+ support . reliableHiddenOffsets = isSupported && ( tds [ 0 ] . offsetHeight === 0 ) ;
234+
235+ // Figure out if the W3C box model works as expected
236+ div . innerHTML = "" ;
237+ div . style . width = div . style . paddingLeft = "1px" ;
238+ jQuery . boxModel = support . boxModel = div . offsetWidth === 2 ;
239+
240+ if ( typeof div . style . zoom !== "undefined" ) {
241+ // Check if natively block-level elements act like inline-block
242+ // elements when setting their display to 'inline' and giving
243+ // them layout
244+ // (IE < 8 does this)
245+ div . style . display = "inline" ;
246+ div . style . zoom = 1 ;
247+ support . inlineBlockNeedsLayout = ( div . offsetWidth === 2 ) ;
248+
249+ // Check if elements with layout shrink-wrap their children
250+ // (IE 6 does this)
251+ div . style . display = "" ;
252+ div . innerHTML = "<div style='width:4px;'></div>" ;
253+ support . shrinkWrapBlocks = ( div . offsetWidth !== 2 ) ;
254+ }
255+
256+ div . style . cssText = ptlm + vb ;
257+ div . innerHTML = html ;
289258
290- testElement . innerHTML = html ;
291- container . appendChild ( testElement ) ;
292- outer = testElement . firstChild ;
259+ outer = div . firstChild ;
293260 inner = outer . firstChild ;
294261 td = outer . nextSibling . firstChild . firstChild ;
295262
@@ -312,15 +279,12 @@ jQuery.support = (function() {
312279 offsetSupport . doesNotIncludeMarginInBodyOffset = ( body . offsetTop !== conMarginTop ) ;
313280
314281 body . removeChild ( container ) ;
315- testElement = container = null ;
282+ div = container = null ;
316283
317284 jQuery . extend ( support , offsetSupport ) ;
318285 } ) ;
319286
320287 return support ;
321288} ) ( ) ;
322289
323- // Keep track of boxModel
324- jQuery . boxModel = jQuery . support . boxModel ;
325-
326290} ) ( jQuery ) ;
0 commit comments