Skip to content
This repository

IE6–7 input name fix #12

Closed
wants to merge 3 commits into from

3 participants

Thomas Aylott Christoph Pojer Scott Kyle
Scott Kyle
Collaborator

I like the more DRY way in 1.2 with ['name', 'type'].each(...)

You seriously prefer 3 function calls to loop over an array with 2 items?

Collaborator

Yea I like avoiding micro-optimizations by writing clean code, and only optimizing where there are bottlenecks. For this case, I don't care that much, but I try to be consistent in how I apply my personal rules. :)

Christoph Pojer
Owner

@appden Olmo did benchmarks a year ago which showed that using the loop in newElement is actually a massive slowdown. We did actually iterate three times on every element creation in 1.2 in IE, even if no name/type/checked attribute where specified. And the each loop is not even native!

Christoph Pojer
Owner

I approve

Christoph Pojer
Owner

Awesomeness.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
32  Source/Element/Element.js
@@ -144,12 +144,42 @@ new Type('Elements', Elements).implement({
144 144
 
145 145
 Array.mirror(Elements);
146 146
 
  147
+(function(){
  148
+
  149
+/*<ltIE8>*/
  150
+var createElementAcceptsHTML;
  151
+try {
  152
+	var x = document.createElement('<input name=x>');
  153
+	createElementAcceptsHTML = (x.name == 'x');
  154
+} catch(e){}
  155
+
  156
+var escapeQuotes = function(html){
  157
+	return ('' + html).replace(/&/g,'&amp;').replace(/"/g,'&quot;');
  158
+};
  159
+/*</ltIE8>*/
  160
+
147 161
 Document.implement({
148 162
 
149 163
 	newElement: function(tag, props){
150 164
 		if (props && props.checked != null) props.defaultChecked = props.checked;
  165
+		/*<ltIE8>*/// Fix for readonly name and type properties in IE < 8
  166
+		if (createElementAcceptsHTML && props){
  167
+			tag = '<' + tag;
  168
+			if (props.name) tag += ' name="' + escapeQuotes(props.name) + '"';
  169
+			if (props.type) tag += ' type="' + escapeQuotes(props.type) + '"';
  170
+			tag += '>';
  171
+			delete props.name;
  172
+			delete props.type;
  173
+		}
  174
+		/*</ltIE8>*/
151 175
 		return this.id(this.createElement(tag)).set(props);
152  
-	},
  176
+	}
  177
+
  178
+});
  179
+
  180
+})();
  181
+
  182
+Document.implement({
153 183
 
154 184
 	newTextNode: function(text){
155 185
 		return this.createTextNode(text);
2  Specs
... ...
@@ -1 +1 @@
1  
-Subproject commit ef5af1517133eadc13802f0e176abf433cebe479
  1
+Subproject commit 805a1ac2ad604a5b10447bfdc226360da0e88b45
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.