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