3d8054821d39127458c807327a091295a83850a3
[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>';
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.5",
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         jQuery(function(){
85                 var div = document.createElement("div");
86                 div.style.width = div.style.paddingLeft = "1px";
87
88                 document.body.appendChild( div );
89                 jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
90                 document.body.removeChild( div ).style.display = 'none';
91         });
92 })();
93
94 var styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat";
95
96 jQuery.props = {
97         "for": "htmlFor",
98         "class": "className",
99         "float": styleFloat,
100         cssFloat: styleFloat,
101         styleFloat: styleFloat,
102         readonly: "readOnly",
103         maxlength: "maxLength",
104         cellspacing: "cellSpacing",
105         rowspan: "rowSpan",
106         tabindex: "tabIndex"
107 };