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