Make sure that .data() (no args) returns a list of all the data- properties as well...
[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                 deleteExpando: true,
65                 optDisabled: false,
66                 checkClone: false,
67                 scriptEval: false,
68                 noCloneEvent: true,
69                 boxModel: null,
70                 inlineBlockNeedsLayout: false,
71                 shrinkWrapBlocks: false,
72                 reliableHiddenOffsets: true
73         };
74
75         // Make sure that the options inside disabled selects aren't marked as disabled
76         // (WebKit marks them as diabled)
77         select.disabled = true;
78         jQuery.support.optDisabled = !opt.disabled;
79
80         script.type = "text/javascript";
81         try {
82                 script.appendChild( document.createTextNode( "window." + id + "=1;" ) );
83         } catch(e) {}
84
85         root.insertBefore( script, root.firstChild );
86
87         // Make sure that the execution of code works by injecting a script
88         // tag with appendChild/createTextNode
89         // (IE doesn't support this, fails, and uses .text instead)
90         if ( window[ id ] ) {
91                 jQuery.support.scriptEval = true;
92                 delete window[ id ];
93         }
94
95         // Test to see if it's possible to delete an expando from an element
96         // Fails in Internet Explorer
97         try {
98                 delete script.test;
99
100         } catch(e) {
101                 jQuery.support.deleteExpando = false;
102         }
103
104         root.removeChild( script );
105
106         if ( div.attachEvent && div.fireEvent ) {
107                 div.attachEvent("onclick", function click() {
108                         // Cloning a node shouldn't copy over any
109                         // bound event handlers (IE does this)
110                         jQuery.support.noCloneEvent = false;
111                         div.detachEvent("onclick", click);
112                 });
113                 div.cloneNode(true).fireEvent("onclick");
114         }
115
116         div = document.createElement("div");
117         div.innerHTML = "<input type='radio' name='radiotest' checked='checked'/>";
118
119         var fragment = document.createDocumentFragment();
120         fragment.appendChild( div.firstChild );
121
122         // WebKit doesn't clone checked state correctly in fragments
123         jQuery.support.checkClone = fragment.cloneNode(true).cloneNode(true).lastChild.checked;
124
125         // Figure out if the W3C box model works as expected
126         // document.body must exist before we can do this
127         jQuery(function() {
128                 var div = document.createElement("div");
129                 div.style.width = div.style.paddingLeft = "1px";
130
131                 document.body.appendChild( div );
132                 jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
133
134                 if ( "zoom" in div.style ) {
135                         // Check if natively block-level elements act like inline-block
136                         // elements when setting their display to 'inline' and giving
137                         // them layout
138                         // (IE < 8 does this)
139                         div.style.display = "inline";
140                         div.style.zoom = 1;
141                         jQuery.support.inlineBlockNeedsLayout = div.offsetWidth === 2;
142
143                         // Check if elements with layout shrink-wrap their children
144                         // (IE 6 does this)
145                         div.style.display = "";
146                         div.innerHTML = "<div style='width:4px;'></div>";
147                         jQuery.support.shrinkWrapBlocks = div.offsetWidth !== 2;
148                 }
149
150                 div.innerHTML = "<table><tr><td style='padding:0;display:none'></td><td>t</td></tr></table>";
151                 var tds = div.getElementsByTagName("td");
152
153                 // Check if table cells still have offsetWidth/Height when they are set
154                 // to display:none and there are still other visible table cells in a
155                 // table row; if so, offsetWidth/Height are not reliable for use when
156                 // determining if an element has been hidden directly using
157                 // display:none (it is still safe to use offsets if a parent element is
158                 // hidden; don safety goggles and see bug #4512 for more information).
159                 // (only IE 8 fails this test)
160                 jQuery.support.reliableHiddenOffsets = tds[0].offsetHeight === 0;
161
162                 tds[0].style.display = "";
163                 tds[1].style.display = "none";
164
165                 // Check if empty table cells still have offsetWidth/Height
166                 // (IE < 8 fail this test)
167                 jQuery.support.reliableHiddenOffsets = jQuery.support.reliableHiddenOffsets && tds[0].offsetHeight === 0;
168                 div.innerHTML = "";
169
170                 document.body.removeChild( div ).style.display = "none";
171                 div = tds = null;
172         });
173
174         // Technique from Juriy Zaytsev
175         // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
176         var eventSupported = function( eventName ) {
177                 var el = document.createElement("div");
178                 eventName = "on" + eventName;
179
180                 var isSupported = (eventName in el);
181                 if ( !isSupported ) {
182                         el.setAttribute(eventName, "return;");
183                         isSupported = typeof el[eventName] === "function";
184                 }
185                 el = null;
186
187                 return isSupported;
188         };
189
190         jQuery.support.submitBubbles = eventSupported("submit");
191         jQuery.support.changeBubbles = eventSupported("change");
192
193         // release memory in IE
194         root = script = div = all = a = null;
195 })();
196
197 jQuery.props = {
198         "for": "htmlFor",
199         "class": "className",
200         readonly: "readOnly",
201         maxlength: "maxLength",
202         cellspacing: "cellSpacing",
203         rowspan: "rowSpan",
204         colspan: "colSpan",
205         tabindex: "tabIndex",
206         usemap: "useMap",
207         frameborder: "frameBorder"
208 };
209
210 })( jQuery );