fix bug #2310 #2387

Closed
wants to merge 7 commits into
from
View
@@ -818,7 +818,26 @@ Element.implement({
clone: function(contents, keepid){
contents = contents !== false;
- var clone = this.cloneNode(contents), ce = [clone], te = [this], i;
+ var cloneNode = function(){return false};

This comment has been minimized.

Show comment Hide comment
@arian

arian Aug 19, 2012

Member
var self = this;
var cloneNode = function(){
    return self.cloneNode(contents);
};
@arian

arian Aug 19, 2012

Member
var self = this;
var cloneNode = function(){
    return self.cloneNode(contents);
};

This comment has been minimized.

Show comment Hide comment
@kentaromiura

kentaromiura Aug 19, 2012

Member

I think I need to move this on outer scope to avoid memory leaks too.

@kentaromiura

kentaromiura Aug 19, 2012

Member

I think I need to move this on outer scope to avoid memory leaks too.

+ /*<ltIE8>*/
+ if (Browser.ie6 || Browser.ie7){

This comment has been minimized.

Show comment Hide comment
@arian

arian Aug 19, 2012

Member

I think we could feature detect this..

@arian

arian Aug 19, 2012

Member

I think we could feature detect this..

+ var self = this;
+ cloneNode = function(contents){

This comment has been minimized.

Show comment Hide comment
@arian

arian Aug 19, 2012

Member

don't need the contents argument, it can get the contents variable from the outer scope.

@arian

arian Aug 19, 2012

Member

don't need the contents argument, it can get the contents variable from the outer scope.

+ var oldID = '' + self.id;
+ self.removeAttribute('id');
+ var clonedHTML = self.outerHTML;
+ var cloned = document.createElement('div');
+ if(!keepid) clonedHTML = clonedHTML.replace(/id=[^\ \>]/gim,'');
+ cloned.innerHTML = clonedHTML;
+ self.id = oldID;
+ var clone = cloned.firstChild;
+ if (keepid) clone.id = oldID;
+ if (!contents & clone.tagName !== 'INPUT' ) clone.innerHTML = '';
+ return clone;
+ }
+ }
+ /*</ltIE8>*/
+ var clone = cloneNode(contents) || this.cloneNode(contents), ce = [clone], te = [this], i;
if (contents){
ce.append(Array.from(clone.getElementsByTagName('*')));
@@ -849,6 +868,8 @@ Element.implement({
for (i = co.length; i--;) co[i].outerHTML = to[i].outerHTML;
}
/*</ltIE9>*/
+
+
return document.id(clone);
}
@@ -10,6 +10,34 @@ describe('Element', function(){
describe('Element.getProperty', function(){
+ it('should cloneNode properly on IE6/7', function(){

This comment has been minimized.

Show comment Hide comment
@arian

arian Aug 19, 2012

Member

should be split up in multiple its.

@arian

arian Aug 19, 2012

Member

should be split up in multiple its.

+
+ var div = new Element('div');
+ div.inject(document.documentElement);
+ div.innerHTML = "<input id='Q1' class='foo' rel='hai' />";
+
+ var q1 = document.id('Q1');
+ var clone = q1.clone();
+ clone.replaces(q1);
+
+ expect($$('input[id=Q1]').length).toEqual(0);
+ expect($$('input#Q1').length).toEqual(0);
+ expect($$('input[id=Q1]').length).toEqual(0); //<- element.erase will fail on this :(
+ clone.dispose();
+
+ var ul = new Element('ul',{id:'test'});
+ ul.set('html', '<li id="li1"></li><li id="li2"></li>');
+ ul.inject(document.documentElement);
+
+ var ulc = ul.clone();
+ ulc.replaces(ul);
+
+ expect($$('li#li1').length).toEqual(0);
+
+ ulc.destroy();
+
+ });
+
it('should get the attrubte of a form when the form has an input with as ID the attribute name', function(){
var div = new Element('div');
div.innerHTML = '<form action="s"><input id="action"></form>';