Added in support for injecting area elements into map elements. Fixes #4484.
[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         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                 div = null;
92         });
93
94         // Technique from Juriy Zaytsev
95         // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
96         var eventSupported = function( eventName ) { 
97                 var el = document.createElement("div"); 
98                 eventName = "on" + eventName; 
99
100                 var isSupported = (eventName in el); 
101                 if ( !isSupported ) { 
102                         el.setAttribute(eventName, "return;"); 
103                         isSupported = typeof el[eventName] === "function"; 
104                 } 
105                 el = null; 
106
107                 return isSupported; 
108         };
109         
110         jQuery.support.submitBubbles = eventSupported("submit");
111         jQuery.support.changeBubbles = eventSupported("change");
112
113         // release memory in IE
114         root = script = div = all = a = null;
115 })();
116
117 jQuery.props = {
118         "for": "htmlFor",
119         "class": "className",
120         readonly: "readOnly",
121         maxlength: "maxLength",
122         cellspacing: "cellSpacing",
123         rowspan: "rowSpan",
124         colspan: "colSpan",
125         tabindex: "tabIndex",
126         usemap: "useMap",
127         frameborder: "frameBorder"
128 };