Add a feature test for options inside a disabled select. Follow-up to 157a383dae5335e...
[jquery.git] / src / support.js
1 (function( jQuery ) {
2
3 (function() {
4
5         jQuery.support = {};
6
7         var root = document.documentElement,
8                 script = document.createElement("script"),
9                 div = document.createElement("div"),
10                 id = "script" + jQuery.now();
11
12         div.style.display = "none";
13         div.innerHTML = "   <link/><table></table><a href='/a' style='color:red;float:left;opacity:.55;'>a</a><input type='checkbox'/>";
14
15         var all = div.getElementsByTagName("*"),
16                 a = div.getElementsByTagName("a")[0];
17
18         // Can't get basic test support
19         if ( !all || !all.length || !a ) {
20                 return;
21         }
22
23         var select = document.createElement("select");
24         var opt = select.appendChild( document.createElement("option") );
25
26         jQuery.support = {
27                 // IE strips leading whitespace when .innerHTML is used
28                 leadingWhitespace: div.firstChild.nodeType === 3,
29
30                 // Make sure that tbody elements aren't automatically inserted
31                 // IE will insert them into empty tables
32                 tbody: !div.getElementsByTagName("tbody").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                 // Use a regex to work around a WebKit issue. See #5145
49                 opacity: /^0.55$/.test( a.style.opacity ),
50
51                 // Verify style float existence
52                 // (IE uses styleFloat instead of cssFloat)
53                 cssFloat: !!a.style.cssFloat,
54
55                 // Make sure that if no value is specified for a checkbox
56                 // that it defaults to "on".
57                 // (WebKit defaults to "" instead)
58                 checkOn: div.getElementsByTagName("input")[0].value === "on",
59
60                 // Make sure that a selected-by-default option has a working selected property.
61                 // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
62                 optSelected: opt.selected,
63
64                 // Will be defined later
65                 optDisabled: false,
66                 checkClone: false,
67                 scriptEval: false,
68                 noCloneEvent: true,
69                 boxModel: null
70         };
71
72         // Make sure that the options inside disabled selects aren't marked as disabled
73         // (WebKit marks them as diabled)
74         select.disabled = true;
75         jQuery.support.optDisabled = !opt.disabled;
76
77         script.type = "text/javascript";
78         try {
79                 script.appendChild( document.createTextNode( "window." + id + "=1;" ) );
80         } catch(e) {}
81
82         root.insertBefore( script, root.firstChild );
83
84         // Make sure that the execution of code works by injecting a script
85         // tag with appendChild/createTextNode
86         // (IE doesn't support this, fails, and uses .text instead)
87         if ( window[ id ] ) {
88                 jQuery.support.scriptEval = true;
89                 delete window[ id ];
90         }
91
92         root.removeChild( script );
93
94         if ( div.attachEvent && div.fireEvent ) {
95                 div.attachEvent("onclick", function click() {
96                         // Cloning a node shouldn't copy over any
97                         // bound event handlers (IE does this)
98                         jQuery.support.noCloneEvent = false;
99                         div.detachEvent("onclick", click);
100                 });
101                 div.cloneNode(true).fireEvent("onclick");
102         }
103
104         div = document.createElement("div");
105         div.innerHTML = "<input type='radio' name='radiotest' checked='checked'/>";
106
107         var fragment = document.createDocumentFragment();
108         fragment.appendChild( div.firstChild );
109
110         // WebKit doesn't clone checked state correctly in fragments
111         jQuery.support.checkClone = fragment.cloneNode(true).cloneNode(true).lastChild.checked;
112
113         // Figure out if the W3C box model works as expected
114         // document.body must exist before we can do this
115         jQuery(function() {
116                 var div = document.createElement("div");
117                 div.style.width = div.style.paddingLeft = "1px";
118
119                 document.body.appendChild( div );
120                 jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
121                 document.body.removeChild( div ).style.display = 'none';
122                 div = null;
123         });
124
125         // Technique from Juriy Zaytsev
126         // http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
127         var eventSupported = function( eventName ) { 
128                 var el = document.createElement("div"); 
129                 eventName = "on" + eventName; 
130
131                 var isSupported = (eventName in el); 
132                 if ( !isSupported ) { 
133                         el.setAttribute(eventName, "return;"); 
134                         isSupported = typeof el[eventName] === "function"; 
135                 } 
136                 el = null; 
137
138                 return isSupported; 
139         };
140         
141         jQuery.support.submitBubbles = eventSupported("submit");
142         jQuery.support.changeBubbles = eventSupported("change");
143
144         // release memory in IE
145         root = script = div = all = a = null;
146 })();
147
148 jQuery.props = {
149         "for": "htmlFor",
150         "class": "className",
151         readonly: "readOnly",
152         maxlength: "maxLength",
153         cellspacing: "cellSpacing",
154         rowspan: "rowSpan",
155         colspan: "colSpan",
156         tabindex: "tabIndex",
157         usemap: "useMap",
158         frameborder: "frameBorder"
159 };
160
161 })( jQuery );