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