1 jQuery.support = (function() {
3 var support, all, a, select, opt, input, fragment, eventName, isSupported, i,
4 div = document.createElement("div");
7 div.setAttribute( "className", "t" );
8 div.innerHTML = " <table></table><a href='/a'>a</a><input type='checkbox'/>";
10 // Support tests won't run in some limited or non-browser environments
11 all = div.getElementsByTagName("*");
12 a = div.getElementsByTagName("a")[ 0 ];
13 if ( !all || !a || !all.length ) {
17 // First batch of tests
18 select = document.createElement("select");
19 opt = select.appendChild( document.createElement("option") );
20 input = div.getElementsByTagName("input")[ 0 ];
22 a.style.cssText = "top:1px;float:left;opacity:.5";
24 // Test setAttribute on camelCase class. If it works, we need attrFixes when doing get/setAttribute (ie6/7)
25 getSetAttribute: div.className !== "t",
27 // IE strips leading whitespace when .innerHTML is used
28 leadingWhitespace: div.firstChild.nodeType === 3,
30 // Make sure that tbody elements aren't automatically inserted
31 // IE will insert them into empty tables
32 tbody: !div.getElementsByTagName("tbody").length,
34 // Get the style information from getAttribute
35 // (IE uses .cssText instead)
36 style: /top/.test( a.getAttribute("style") ),
38 // Make sure that URLs aren't manipulated
39 // (IE normalizes it by default)
40 hrefNormalized: a.getAttribute("href") === "/a",
42 // Make sure that element opacity exists
43 // (IE uses filter instead)
44 // Use a regex to work around a WebKit issue. See #5145
45 opacity: /^0.5/.test( a.style.opacity ),
47 // Verify style float existence
48 // (IE uses styleFloat instead of cssFloat)
49 cssFloat: !!a.style.cssFloat,
51 // Check the default checkbox/radio value ("" on WebKit; "on" elsewhere)
52 checkOn: !!input.value,
54 // Make sure that a selected-by-default option has a working selected property.
55 // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
56 optSelected: opt.selected,
58 // Tests for enctype support on a form (#6743)
59 enctype: !!document.createElement("form").enctype,
61 // jQuery.support.boxModel DEPRECATED in 1.8 since we don't support Quirks Mode
62 boxModel: document.compatMode === "CSS1Compat",
64 // Will be defined later
67 inlineBlockNeedsLayout: false,
68 shrinkWrapBlocks: false,
69 reliableMarginRight: true,
70 boxSizingReliable: true,
74 // Make sure checked status is properly cloned
76 support.noCloneChecked = input.cloneNode( true ).checked;
78 // Make sure that the options inside disabled selects aren't marked as disabled
79 // (WebKit marks them as disabled)
80 select.disabled = true;
81 support.optDisabled = !opt.disabled;
87 support.deleteExpando = false;
90 // Check if we can trust getAttribute("value")
91 input = document.createElement("input");
92 input.setAttribute( "value", "" );
93 support.input = input.getAttribute( "value" ) === "";
95 // Check if an input maintains its value after becoming a radio
97 input.setAttribute( "type", "radio" );
98 support.radioValue = input.value === "t";
100 // #11217 - WebKit loses check when the name is after the checked attribute
101 input.setAttribute( "checked", "t" );
102 input.setAttribute( "name", "t" );
104 fragment = document.createDocumentFragment();
105 fragment.appendChild( input );
107 // Check if a disconnected checkbox will retain its checked
108 // value of true after appended to the DOM (IE6/7)
109 support.appendChecked = input.checked;
111 // WebKit doesn't clone checked state correctly in fragments
112 support.checkClone = fragment.cloneNode( true ).cloneNode( true ).lastChild.checked;
115 // Opera does not clone events (and typeof div.attachEvent === undefined).
116 // IE9-10 clones events bound via attachEvent, but they don't trigger with .click()
117 if ( div.attachEvent ) {
118 div.attachEvent( "onclick", function() {
119 support.noCloneEvent = false;
122 div.cloneNode( true ).click();
125 // Support: IE<9 (lack submit/change bubble), Firefox 17+ (lack focusin event)
126 // Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP), test/csp.php
127 for ( i in { submit: true, change: true, focusin: true }) {
128 div.setAttribute( eventName = "on" + i, "t" );
130 support[ i + "Bubbles" ] = eventName in window || div.attributes[ eventName ].expando === false;
133 // Run tests that need a body at doc ready
135 var container, marginDiv, tds,
136 divReset = "padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",
137 body = document.getElementsByTagName("body")[0];
140 // Return for frameset docs that don't have a body
144 container = document.createElement("div");
145 container.style.cssText = "border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px";
147 body.appendChild( container ).appendChild( div );
150 // Check if table cells still have offsetWidth/Height when they are set
151 // to display:none and there are still other visible table cells in a
152 // table row; if so, offsetWidth/Height are not reliable for use when
153 // determining if an element has been hidden directly using
154 // display:none (it is still safe to use offsets if a parent element is
155 // hidden; don safety goggles and see bug #4512 for more information).
156 div.innerHTML = "<table><tr><td></td><td>t</td></tr></table>";
157 tds = div.getElementsByTagName("td");
158 tds[ 0 ].style.cssText = "padding:0;margin:0;border:0;display:none";
159 isSupported = ( tds[ 0 ].offsetHeight === 0 );
161 tds[ 0 ].style.display = "";
162 tds[ 1 ].style.display = "none";
165 // Check if empty table cells still have offsetWidth/Height
166 support.reliableHiddenOffsets = isSupported && ( tds[ 0 ].offsetHeight === 0 );
168 // Check box-sizing and margin behavior
170 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%;";
171 support.boxSizing = ( div.offsetWidth === 4 );
172 support.doesNotIncludeMarginInBodyOffset = ( body.offsetTop !== 1 );
174 // Use window.getComputedStyle because jsdom on node.js will break without it.
175 if ( window.getComputedStyle ) {
176 support.pixelPosition = ( window.getComputedStyle( div, null ) || {} ).top !== "1%";
177 support.boxSizingReliable = ( window.getComputedStyle( div, null ) || { width: "4px" } ).width === "4px";
179 // Check if div with explicit width and no margin-right incorrectly
180 // gets computed margin-right based on width of container. (#3333)
181 // Fails in WebKit before Feb 2011 nightlies
182 // WebKit Bug 13343 - getComputedStyle returns wrong value for margin-right
183 marginDiv = div.appendChild( document.createElement("div") );
184 marginDiv.style.cssText = div.style.cssText = divReset;
185 marginDiv.style.marginRight = marginDiv.style.width = "0";
186 div.style.width = "1px";
188 support.reliableMarginRight =
189 !parseFloat( ( window.getComputedStyle( marginDiv, null ) || {} ).marginRight );
192 if ( typeof div.style.zoom !== "undefined" ) {
194 // Check if natively block-level elements act like inline-block
195 // elements when setting their display to 'inline' and giving
198 div.style.cssText = divReset + "width:1px;padding:1px;display:inline;zoom:1";
199 support.inlineBlockNeedsLayout = ( div.offsetWidth === 3 );
202 // Check if elements with layout shrink-wrap their children
203 div.style.display = "block";
204 div.innerHTML = "<div></div>";
205 div.firstChild.style.width = "5px";
206 support.shrinkWrapBlocks = ( div.offsetWidth !== 3 );
208 // Prevent IE 6 from affecting layout for positioned elements #11048
209 // Prevent IE from shrinking the body in IE 7 mode #12869
213 body.removeChild( container );
215 // Null elements to avoid leaks in IE
216 container = div = tds = marginDiv = null;
219 // Null elements to avoid leaks in IE
220 all = select = fragment = opt = a = input = null;