AMD-ify jQuery sourcegit s! Woo! Fixes #14113, #14163.
[jquery.git] / src / support.js
blob147cb4ddf85ce60bb56fd3a740d1a4a63ad50175
1 define([
2         "./core",
3         "./var/strundefined",
4         "./core/swap"
5 ], function( jQuery, strundefined ) {
7 jQuery.support = (function( support ) {
9         var all, a, input, select, fragment, opt, eventName, isSupported, i,
10                 div = document.createElement("div");
12         // Setup
13         div.setAttribute( "className", "t" );
14         div.innerHTML = "  <link/><table></table><a href='/a'>a</a><input type='checkbox'/>";
16         // Finish early in limited (non-browser) environments
17         all = div.getElementsByTagName("*") || [];
18         a = div.getElementsByTagName("a")[ 0 ];
19         if ( !a || !a.style || !all.length ) {
20                 return support;
21         }
23         // First batch of tests
24         select = document.createElement("select");
25         opt = select.appendChild( document.createElement("option") );
26         input = div.getElementsByTagName("input")[ 0 ];
28         a.style.cssText = "top:1px;float:left;opacity:.5";
30         // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
31         support.getSetAttribute = div.className !== "t";
33         // IE strips leading whitespace when .innerHTML is used
34         support.leadingWhitespace = div.firstChild.nodeType === 3;
36         // Make sure that tbody elements aren't automatically inserted
37         // IE will insert them into empty tables
38         support.tbody = !div.getElementsByTagName("tbody").length;
40         // Make sure that link elements get serialized correctly by innerHTML
41         // This requires a wrapper element in IE
42         support.htmlSerialize = !!div.getElementsByTagName("link").length;
44         // Get the style information from getAttribute
45         // (IE uses .cssText instead)
46         support.style = /top/.test( a.getAttribute("style") );
48         // Make sure that URLs aren't manipulated
49         // (IE normalizes it by default)
50         support.hrefNormalized = a.getAttribute("href") === "/a";
52         // Make sure that element opacity exists
53         // (IE uses filter instead)
54         // Use a regex to work around a WebKit issue. See #5145
55         support.opacity = /^0.5/.test( a.style.opacity );
57         // Verify style float existence
58         // (IE uses styleFloat instead of cssFloat)
59         support.cssFloat = !!a.style.cssFloat;
61         // Check the default checkbox/radio value ("" on WebKit; "on" elsewhere)
62         support.checkOn = !!input.value;
64         // Make sure that a selected-by-default option has a working selected property.
65         // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
66         support.optSelected = opt.selected;
68         // Tests for enctype support on a form (#6743)
69         support.enctype = !!document.createElement("form").enctype;
71         // Makes sure cloning an html5 element does not cause problems
72         // Where outerHTML is undefined, this still works
73         support.html5Clone = document.createElement("nav").cloneNode( true ).outerHTML !== "<:nav></:nav>";
75         // Will be defined later
76         support.inlineBlockNeedsLayout = false;
77         support.shrinkWrapBlocks = false;
78         support.pixelPosition = false;
79         support.deleteExpando = true;
80         support.noCloneEvent = true;
81         support.reliableMarginRight = true;
82         support.boxSizingReliable = true;
84         // Make sure checked status is properly cloned
85         input.checked = true;
86         support.noCloneChecked = input.cloneNode( true ).checked;
88         // Make sure that the options inside disabled selects aren't marked as disabled
89         // (WebKit marks them as disabled)
90         select.disabled = true;
91         support.optDisabled = !opt.disabled;
93         // Support: IE<9
94         try {
95                 delete div.test;
96         } catch( e ) {
97                 support.deleteExpando = false;
98         }
100         // Check if we can trust getAttribute("value")
101         input = document.createElement("input");
102         input.setAttribute( "value", "" );
103         support.input = input.getAttribute( "value" ) === "";
105         // Check if an input maintains its value after becoming a radio
106         input.value = "t";
107         input.setAttribute( "type", "radio" );
108         support.radioValue = input.value === "t";
110         // #11217 - WebKit loses check when the name is after the checked attribute
111         input.setAttribute( "checked", "t" );
112         input.setAttribute( "name", "t" );
114         fragment = document.createDocumentFragment();
115         fragment.appendChild( input );
117         // Check if a disconnected checkbox will retain its checked
118         // value of true after appended to the DOM (IE6/7)
119         support.appendChecked = input.checked;
121         // WebKit doesn't clone checked state correctly in fragments
122         support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked;
124         // Support: IE<9
125         // Opera does not clone events (and typeof div.attachEvent === undefined).
126         // IE9-10 clones events bound via attachEvent, but they don't trigger with .click()
127         if ( div.attachEvent ) {
128                 div.attachEvent( "onclick", function() {
129                         support.noCloneEvent = false;
130                 });
132                 div.cloneNode( true ).click();
133         }
135         // Support: IE<9 (lack submit/change bubble), Firefox 17+ (lack focusin event)
136         // Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP)
137         for ( i in { submit: true, change: true, focusin: true }) {
138                 div.setAttribute( eventName = "on" + i, "t" );
140                 support[ i + "Bubbles" ] = eventName in window || div.attributes[ eventName ].expando === false;
141         }
143         div.style.backgroundClip = "content-box";
144         div.cloneNode( true ).style.backgroundClip = "";
145         support.clearCloneStyle = div.style.backgroundClip === "content-box";
147         // Support: IE<9
148         // Iteration over object's inherited properties before its own.
149         for ( i in jQuery( support ) ) {
150                 break;
151         }
152         support.ownLast = i !== "0";
154         // Run tests that need a body at doc ready
155         jQuery(function() {
156                 var container, marginDiv, tds,
157                         divReset = "padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",
158                         body = document.getElementsByTagName("body")[0];
160                 if ( !body ) {
161                         // Return for frameset docs that don't have a body
162                         return;
163                 }
165                 container = document.createElement("div");
166                 container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px";
168                 body.appendChild( container ).appendChild( div );
170                 // Support: IE8
171                 // Check if table cells still have offsetWidth/Height when they are set
172                 // to display:none and there are still other visible table cells in a
173                 // table row; if so, offsetWidth/Height are not reliable for use when
174                 // determining if an element has been hidden directly using
175                 // display:none (it is still safe to use offsets if a parent element is
176                 // hidden; don safety goggles and see bug #4512 for more information).
177                 div.innerHTML = "<table><tr><td></td><td>t</td></tr></table>";
178                 tds = div.getElementsByTagName("td");
179                 tds[ 0 ].style.cssText = "padding:0;margin:0;border:0;display:none";
180                 isSupported = ( tds[ 0 ].offsetHeight === 0 );
182                 tds[ 0 ].style.display = "";
183                 tds[ 1 ].style.display = "none";
185                 // Support: IE8
186                 // Check if empty table cells still have offsetWidth/Height
187                 support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 );
189                 // Check box-sizing and margin behavior.
190                 div.innerHTML = "";
191                 div.style.cssText = "box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;";
193                 // Workaround failing boxSizing test due to offsetWidth returning wrong value
194                 // with some non-1 values of body zoom, ticket #13543
195                 jQuery.swap( body, body.style.zoom != null ? { zoom: 1 } : {}, function() {
196                         support.boxSizing = div.offsetWidth === 4;
197                 });
199                 // Use window.getComputedStyle because jsdom on node.js will break without it.
200                 if ( window.getComputedStyle ) {
201                         support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%";
202                         support.boxSizingReliable = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px";
204                         // Check if div with explicit width and no margin-right incorrectly
205                         // gets computed margin-right based on width of container. (#3333)
206                         // Fails in WebKit before Feb 2011 nightlies
207                         // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
208                         marginDiv = div.appendChild( document.createElement("div") );
209                         marginDiv.style.cssText = div.style.cssText = divReset;
210                         marginDiv.style.marginRight = marginDiv.style.width = "0";
211                         div.style.width = "1px";
213                         support.reliableMarginRight =
214                                 !parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight );
215                 }
217                 if ( typeof div.style.zoom !== strundefined ) {
218                         // Support: IE<8
219                         // Check if natively block-level elements act like inline-block
220                         // elements when setting their display to 'inline' and giving
221                         // them layout
222                         div.innerHTML = "";
223                         div.style.cssText = divReset + "width:1px;padding:1px;display:inline;zoom:1";
224                         support.inlineBlockNeedsLayout = ( div.offsetWidth === 3 );
226                         // Support: IE6
227                         // Check if elements with layout shrink-wrap their children
228                         div.style.display = "block";
229                         div.innerHTML = "<div></div>";
230                         div.firstChild.style.width = "5px";
231                         support.shrinkWrapBlocks = ( div.offsetWidth !== 3 );
233                         if ( support.inlineBlockNeedsLayout ) {
234                                 // Prevent IE 6 from affecting layout for positioned elements #11048
235                                 // Prevent IE from shrinking the body in IE 7 mode #12869
236                                 // Support: IE<8
237                                 body.style.zoom = 1;
238                         }
239                 }
241                 body.removeChild( container );
243                 // Null elements to avoid leaks in IE
244                 container = div = tds = marginDiv = null;
245         });
247         // Null elements to avoid leaks in IE
248         all = select = fragment = opt = a = input = null;
250         return support;
251 })({});