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