Fixed boxModel support - is now computed with feature detection, rather than sniffing.
[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" + (new Date).getTime();
9
10         div.style.display = "none";
11         div.innerHTML = '   <link/><table></table><a href="/a" style="color:red;float:left;opacity:.5;">a</a><select><option>text</option></select><object><param></object>';
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 you can get all elements in an <object> element
30                 // IE 7 always returns no results
31                 objectAll: !!div.getElementsByTagName("object")[0]
32                         .getElementsByTagName("*").length,
33                 
34                 // Make sure that link elements get serialized correctly by innerHTML
35                 // This requires a wrapper element in IE
36                 htmlSerialize: !!div.getElementsByTagName("link").length,
37                 
38                 // Get the style information from getAttribute
39                 // (IE uses .cssText insted)
40                 style: /red/.test( a.getAttribute("style") ),
41                 
42                 // Make sure that URLs aren't manipulated
43                 // (IE normalizes it by default)
44                 hrefNormalized: a.getAttribute("href") === "/a",
45                 
46                 // Make sure that element opacity exists
47                 // (IE uses filter instead)
48                 opacity: a.style.opacity === "0.5",
49                 
50                 // Verify style float existence
51                 // (IE uses styleFloat instead of cssFloat)
52                 cssFloat: !!a.style.cssFloat,
53
54                 // Will be defined later
55                 scriptEval: false,
56                 noCloneEvent: true,
57                 boxModel: null
58         };
59         
60         script.type = "text/javascript";
61         try {
62                 script.appendChild( document.createTextNode( "window." + id + "=1;" ) );
63         } catch(e){}
64
65         root.insertBefore( script, root.firstChild );
66         
67         // Make sure that the execution of code works by injecting a script
68         // tag with appendChild/createTextNode
69         // (IE doesn't support this, fails, and uses .text instead)
70         if ( window[ id ] ) {
71                 jQuery.support.scriptEval = true;
72                 delete window[ id ];
73         }
74
75         root.removeChild( script );
76
77         if ( div.attachEvent && div.fireEvent ) {
78                 div.attachEvent("onclick", function(){
79                         // Cloning a node shouldn't copy over any
80                         // bound event handlers (IE does this)
81                         jQuery.support.noCloneEvent = false;
82                         div.detachEvent("onclick", arguments.callee);
83                 });
84                 div.cloneNode(true).fireEvent("onclick");
85         }
86
87         // Figure out if the W3C box model works as expected
88         // document.body must exist before we can do this
89         jQuery(function(){
90                 var div = document.createElement("div");
91                 div.style.width = "1px";
92                 div.style.paddingLeft = "1px";
93
94                 document.body.appendChild( div );
95                 jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
96                 document.body.removeChild( div );
97         });
98 })();
99
100 var styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat";
101
102 jQuery.props = {
103         "for": "htmlFor",
104         "class": "className",
105         "float": styleFloat,
106         cssFloat: styleFloat,
107         styleFloat: styleFloat,
108         readonly: "readOnly",
109         maxlength: "maxLength",
110         cellspacing: "cellSpacing",
111         rowspan: "rowSpan",
112         tabindex: "tabIndex"
113 };