Explicitly re-bind the events on clone. Copying over the data isn't enough. Fixes...
[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><select><option>text</option></select><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                 // Will be defined later
56                 scriptEval: false,
57                 noCloneEvent: true,
58                 boxModel: null
59         };
60
61         script.type = "text/javascript";
62         try {
63                 script.appendChild( document.createTextNode( "window." + id + "=1;" ) );
64         } catch(e) {}
65
66         root.insertBefore( script, root.firstChild );
67
68         // Make sure that the execution of code works by injecting a script
69         // tag with appendChild/createTextNode
70         // (IE doesn't support this, fails, and uses .text instead)
71         if ( window[ id ] ) {
72                 jQuery.support.scriptEval = true;
73                 delete window[ id ];
74         }
75
76         root.removeChild( script );
77
78         if ( div.attachEvent && div.fireEvent ) {
79                 div.attachEvent("onclick", function click() {
80                         // Cloning a node shouldn't copy over any
81                         // bound event handlers (IE does this)
82                         jQuery.support.noCloneEvent = false;
83                         div.detachEvent("onclick", click);
84                 });
85                 div.cloneNode(true).fireEvent("onclick");
86         }
87
88         // Figure out if the W3C box model works as expected
89         // document.body must exist before we can do this
90         // TODO: This timeout is temporary until I move ready into core.js.
91         jQuery(function() {
92                 var div = document.createElement("div");
93                 div.style.width = div.style.paddingLeft = "1px";
94
95                 document.body.appendChild( div );
96                 jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
97                 document.body.removeChild( div ).style.display = 'none';
98                 div = null;
99         });
100
101         // Technique from Juriy Zaytsev
102         // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
103         var eventSupported = function( eventName ) { 
104                 var el = document.createElement("div"); 
105                 eventName = "on" + eventName; 
106
107                 var isSupported = (eventName in el); 
108                 if ( !isSupported ) { 
109                         el.setAttribute(eventName, "return;"); 
110                         isSupported = typeof el[eventName] === "function"; 
111                 } 
112                 el = null; 
113
114                 return isSupported; 
115         };
116         
117         jQuery.support.submitBubbles = eventSupported("submit");
118         jQuery.support.changeBubbles = eventSupported("change");
119
120         // release memory in IE
121         root = script = div = all = a = null;
122 })();
123
124 jQuery.props = {
125         "for": "htmlFor",
126         "class": "className",
127         readonly: "readOnly",
128         maxlength: "maxLength",
129         cellspacing: "cellSpacing",
130         rowspan: "rowSpan",
131         colspan: "colSpan",
132         tabindex: "tabIndex",
133         usemap: "useMap",
134         frameborder: "frameBorder"
135 };