Update $.fn.animate to change display mode only when necessary (inline, non-floated...
[jquery.git] / src / support.js
1 (function( jQuery ) {
2
3 (function() {
4
5         jQuery.support = {};
6
7         var root = document.documentElement,
8                 script = document.createElement("script"),
9                 div = document.createElement("div"),
10                 id = "script" + jQuery.now();
11
12         div.style.display = "none";
13         div.innerHTML = "   <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
14
15         var all = div.getElementsByTagName("*"),
16                 a = div.getElementsByTagName("a")[0],
17                 select = document.createElement("select"),
18                 opt = select.appendChild( document.createElement("option") );
19
20         // Can't get basic test support
21         if ( !all || !all.length || !a ) {
22                 return;
23         }
24
25         jQuery.support = {
26                 // IE strips leading whitespace when .innerHTML is used
27                 leadingWhitespace: div.firstChild.nodeType === 3,
28
29                 // Make sure that tbody elements aren't automatically inserted
30                 // IE will insert them into empty tables
31                 tbody: !div.getElementsByTagName("tbody").length,
32
33                 // Make sure that link elements get serialized correctly by innerHTML
34                 // This requires a wrapper element in IE
35                 htmlSerialize: !!div.getElementsByTagName("link").length,
36
37                 // Get the style information from getAttribute
38                 // (IE uses .cssText insted)
39                 style: /red/.test( a.getAttribute("style") ),
40
41                 // Make sure that URLs aren't manipulated
42                 // (IE normalizes it by default)
43                 hrefNormalized: a.getAttribute("href") === "/a",
44
45                 // Make sure that element opacity exists
46                 // (IE uses filter instead)
47                 // Use a regex to work around a WebKit issue. See #5145
48                 opacity: /^0.55$/.test( a.style.opacity ),
49
50                 // Verify style float existence
51                 // (IE uses styleFloat instead of cssFloat)
52                 cssFloat: !!a.style.cssFloat,
53
54                 // Make sure that if no value is specified for a checkbox
55                 // that it defaults to "on".
56                 // (WebKit defaults to "" instead)
57                 checkOn: div.getElementsByTagName("input")[0].value === "on",
58
59                 // Make sure that a selected-by-default option has a working selected property.
60                 // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
61                 optSelected: opt.selected,
62
63                 // Will be defined later
64                 optDisabled: false,
65                 checkClone: false,
66                 scriptEval: false,
67                 noCloneEvent: true,
68                 boxModel: null,
69                 inlineBlockNeedsLayout: false,
70                 reliableHiddenOffsets: true
71         };
72
73         // Make sure that the options inside disabled selects aren't marked as disabled
74         // (WebKit marks them as diabled)
75         select.disabled = true;
76         jQuery.support.optDisabled = !opt.disabled;
77
78         script.type = "text/javascript";
79         try {
80                 script.appendChild( document.createTextNode( "window." + id + "=1;" ) );
81         } catch(e) {}
82
83         root.insertBefore( script, root.firstChild );
84
85         // Make sure that the execution of code works by injecting a script
86         // tag with appendChild/createTextNode
87         // (IE doesn't support this, fails, and uses .text instead)
88         if ( window[ id ] ) {
89                 jQuery.support.scriptEval = true;
90                 delete window[ id ];
91         }
92
93         root.removeChild( script );
94
95         if ( div.attachEvent && div.fireEvent ) {
96                 div.attachEvent("onclick", function click() {
97                         // Cloning a node shouldn't copy over any
98                         // bound event handlers (IE does this)
99                         jQuery.support.noCloneEvent = false;
100                         div.detachEvent("onclick", click);
101                 });
102                 div.cloneNode(true).fireEvent("onclick");
103         }
104
105         div = document.createElement("div");
106         div.innerHTML = "<input type='radio' name='radiotest' checked='checked'/>";
107
108         var fragment = document.createDocumentFragment();
109         fragment.appendChild( div.firstChild );
110
111         // WebKit doesn't clone checked state correctly in fragments
112         jQuery.support.checkClone = fragment.cloneNode(true).cloneNode(true).lastChild.checked;
113
114         // Figure out if the W3C box model works as expected
115         // document.body must exist before we can do this
116         jQuery(function() {
117                 var div = document.createElement("div");
118                 div.style.width = div.style.paddingLeft = "1px";
119
120                 document.body.appendChild( div );
121                 jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
122
123                 // Check if natively block-level elements act like inline-block
124                 // elements when setting their display to 'inline'
125                 // (IE < 8 does this)
126                 if ( 'zoom' in div.style ) {
127                         div.style.display = 'inline';
128
129                         // Layout is necessary to trigger this “feature”
130                         div.style.zoom = 1;
131                         jQuery.support.inlineBlockNeedsLayout = div.offsetWidth === 2;
132                 }
133
134                 // Check if table cells still have offsetWidth/Height when they are set
135                 // to display:none and there are still other visible table cells in a
136                 // table row; if so, offsetWidth/Height are not reliable for use when
137                 // determining if an element has been hidden directly using
138                 // display:none (it is still safe to use offsets if a parent element is
139                 // hidden; don safety goggles and see bug #4512 for more information).
140                 // (only IE 8 fails this test)
141                 div.innerHTML = '<table><tr><td style="display:none"></td><td>t</td></tr></table>';
142                 jQuery.support.reliableHiddenOffsets = div.getElementsByTagName('td')[0].offsetHeight === 0;
143                 div.innerHTML = '';
144
145                 document.body.removeChild( div ).style.display = 'none';
146                 div = null;
147         });
148
149         // Technique from Juriy Zaytsev
150         // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
151         var eventSupported = function( eventName ) { 
152                 var el = document.createElement("div"); 
153                 eventName = "on" + eventName; 
154
155                 var isSupported = (eventName in el); 
156                 if ( !isSupported ) { 
157                         el.setAttribute(eventName, "return;"); 
158                         isSupported = typeof el[eventName] === "function"; 
159                 } 
160                 el = null; 
161
162                 return isSupported; 
163         };
164         
165         jQuery.support.submitBubbles = eventSupported("submit");
166         jQuery.support.changeBubbles = eventSupported("change");
167
168         // release memory in IE
169         root = script = div = all = a = null;
170 })();
171
172 jQuery.props = {
173         "for": "htmlFor",
174         "class": "className",
175         readonly: "readOnly",
176         maxlength: "maxLength",
177         cellspacing: "cellSpacing",
178         rowspan: "rowSpan",
179         colspan: "colSpan",
180         tabindex: "tabIndex",
181         usemap: "useMap",
182         frameborder: "frameBorder"
183 };
184
185 })( jQuery );