Clean up expando removal code - only try to delete the expando from an element if...
[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                 deleteExpando: true,
63                 checkClone: false,
64                 scriptEval: false,
65                 noCloneEvent: true,
66                 boxModel: null
67         };
68
69         script.type = "text/javascript";
70         try {
71                 script.appendChild( document.createTextNode( "window." + id + "=1;" ) );
72         } catch(e) {}
73
74         root.insertBefore( script, root.firstChild );
75
76         // Make sure that the execution of code works by injecting a script
77         // tag with appendChild/createTextNode
78         // (IE doesn't support this, fails, and uses .text instead)
79         if ( window[ id ] ) {
80                 jQuery.support.scriptEval = true;
81                 delete window[ id ];
82         }
83
84         root.removeChild( script );
85
86         if ( div.attachEvent && div.fireEvent ) {
87                 div.attachEvent("onclick", function click() {
88                         // Cloning a node shouldn't copy over any
89                         // bound event handlers (IE does this)
90                         jQuery.support.noCloneEvent = false;
91                         div.detachEvent("onclick", click);
92                 });
93                 div.cloneNode(true).fireEvent("onclick");
94         }
95
96         div = document.createElement("div");
97         div.innerHTML = "<input type='radio' name='radiotest' checked='checked'/>";
98
99         var fragment = document.createDocumentFragment();
100         fragment.appendChild( div.firstChild );
101
102         // WebKit doesn't clone checked state correctly in fragments
103         jQuery.support.checkClone = fragment.cloneNode(true).cloneNode(true).lastChild.checked;
104
105         // Figure out if the W3C box model works as expected
106         // document.body must exist before we can do this
107         jQuery(function() {
108                 var div = document.createElement("div");
109                 div.style.width = div.style.paddingLeft = "1px";
110
111                 document.body.appendChild( div );
112                 jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
113                 document.body.removeChild( div ).style.display = 'none';
114
115                 // Test to see if it's possible to delete an expando from an element
116                 // Fails in Internet Explorer
117                 try {
118                         div.test = 1;
119                         delete doc.test;
120         
121                 } catch(e) {
122                         jQuery.support.deleteExpando = false;
123                 }
124
125                 div = null;
126         });
127
128         // Technique from Juriy Zaytsev
129         // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
130         var eventSupported = function( eventName ) { 
131                 var el = document.createElement("div"); 
132                 eventName = "on" + eventName; 
133
134                 var isSupported = (eventName in el); 
135                 if ( !isSupported ) { 
136                         el.setAttribute(eventName, "return;"); 
137                         isSupported = typeof el[eventName] === "function"; 
138                 } 
139                 el = null; 
140
141                 return isSupported; 
142         };
143         
144         jQuery.support.submitBubbles = eventSupported("submit");
145         jQuery.support.changeBubbles = eventSupported("change");
146
147         // release memory in IE
148         root = script = div = all = a = null;
149 })();
150
151 jQuery.props = {
152         "for": "htmlFor",
153         "class": "className",
154         readonly: "readOnly",
155         maxlength: "maxLength",
156         cellspacing: "cellSpacing",
157         rowspan: "rowSpan",
158         colspan: "colSpan",
159         tabindex: "tabIndex",
160         usemap: "useMap",
161         frameborder: "frameBorder"
162 };