Skip to content

Commit

Permalink
* Fix createElement for IE
Browse files Browse the repository at this point in the history
  • Loading branch information
cpojer committed Sep 14, 2010
1 parent 1ba2093 commit 581383a
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions Source/Element/Element.js
Expand Up @@ -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){
Expand Down Expand Up @@ -177,6 +194,8 @@ Document.implement({

});

})();

if (window.$ == null) Window.implement({
$: function(el, nc){
return document.id(el, nc, this.document);
Expand Down

0 comments on commit 581383a

Please sign in to comment.