Permalink
Browse files

* Fix createElement for IE

  • Loading branch information...
1 parent 1ba2093 commit 581383ab245fc9f07331cd42d86c315c58f486c5 @cpojer cpojer committed Sep 14, 2010
Showing with 27 additions and 8 deletions.
  1. +27 −8 Source/Element/Element.js
@@ -114,18 +114,35 @@ Elements.implement({
});
+(function(){
+
+/*<ltIE8>*/
+var createElementAcceptsHTML;
+try {
+ var x = document.createElement('<input name=x>');
+ createElementAcceptsHTML = (x.name == 'x');
+} catch(e){}
+
+var escapeQuotes = function(html){
+ return ('' + html).replace(/&/g,'&amp;').replace(/"/g,'&quot;');
+};
+/*</ltIE8>*/
+
Document.implement({
newElement: function(tag, props){
- if (Browser.Engine.trident && props){
- ['name', 'type', 'checked'].each(function(attribute){
- if (!props[attribute]) return;
- tag += ' ' + attribute + '="' + props[attribute] + '"';
- if (attribute != 'checked') delete props[attribute];
- });
- tag = '<' + tag + '>';
+ if (props && props.checked != null) props.defaultChecked = props.checked;
+ /*<ltIE8>*/// Fix for readonly name and type properties in IE < 8
+ if (createElementAcceptsHTML && props){
+ tag = '<' + tag;
+ if (props.name) tag += ' name="' + escapeQuotes(props.name) + '"';
+ if (props.type) tag += ' type="' + escapeQuotes(props.type) + '"';
+ tag += '>';
+ delete props.name;
+ delete props.type;
}
- return document.id(this.createElement(tag)).set(props);
+ /*</ltIE8>*/
+ return this.id(this.createElement(tag)).set(props);
},
newTextNode: function(text){
@@ -177,6 +194,8 @@ Document.implement({
});
+})();
+
if (window.$ == null) Window.implement({
$: function(el, nc){
return document.id(el, nc, this.document);

0 comments on commit 581383a

Please sign in to comment.