diff --git a/src/dom.js b/src/dom.js index b2d7f2b..e92eba6 100644 --- a/src/dom.js +++ b/src/dom.js @@ -108,8 +108,9 @@ Element.Methods = { insert: function(element, insertions) { element = $(element); - if(typeof insertions == 'string' || insertions.ownerDocument === document) - insertions = {bottom:insertions}; + if (typeof insertions == 'string' || typeof insertions == 'number' || + (insertions && insertions.ownerDocument === document)) + insertions = {bottom:insertions}; var content, t, range; @@ -123,7 +124,7 @@ Element.Methods = { continue; } - content = content.toString(); + content = String.interpret(content); range = element.ownerDocument.createRange(); t.initializeRange(element, range); @@ -635,8 +636,9 @@ if (!document.createRange || Prototype.Browser.Opera) { Element.Methods.insert = function(element, insertions) { element = $(element); - if(typeof insertions == 'string' || insertions.ownerDocument === document) - insertions = {bottom:insertions}; + if (typeof insertions == 'string' || typeof insertions == 'number' || + (insertions && insertions.ownerDocument === document)) + insertions = {bottom:insertions}; var t = Element._insertionTranslations, content, position, pos, tagName; @@ -650,7 +652,7 @@ if (!document.createRange || Prototype.Browser.Opera) { continue; } - content = content.toString(); + content = String.interpret(content); tagName = ((position == 'before' || position == 'after') ? element.parentNode : element).tagName.toUpperCase(); diff --git a/test/unit/dom.html b/test/unit/dom.html index 8813484..9009282 100644 --- a/test/unit/dom.html +++ b/test/unit/dom.html @@ -446,7 +446,14 @@ assert(getInnerHTML('element-insertions-multiple-main').startsWith('1')); assert(getInnerHTML('element-insertions-multiple-main').endsWith('2')); assert(getInnerHTML('element-insertions-multiple-container').startsWith('

3

')); - assert(getInnerHTML('element-insertions-multiple-container').endsWith('4')); + assert(getInnerHTML('element-insertions-multiple-container').endsWith('4')); + + $('element-insertions-main').update('test'); + $('element-insertions-main').insert(null); + $('element-insertions-main').insert({bottom:null}); + assertEqual('test', getInnerHTML('element-insertions-main')); + $('element-insertions-main').insert(1337); + assertEqual('test1337', getInnerHTML('element-insertions-main')); }}, testInsertionBackwardsCompatibility: function() {with(this) {