Permalink
Browse files

After further tests, seems like that the only way to avoid the proble…

…m is to not use clone node at all

After further tests, seems like that the only way to avoid the problem
is to not use clone node at all.

So, I wrote a clone node function using outerHTML. need further
testing, to be sure everything is ok, but since it passes regression
I'll commit it.
  • Loading branch information...
1 parent 78992b8 commit 24fdab002db5d5292874fadfd1c3c01b0c09625c Cristian Carlesso committed Aug 14, 2012
Showing with 18 additions and 11 deletions.
  1. +18 −9 Source/Element/Element.js
  2. +0 −2 Specs/1.4client/Element/Element.js
@@ -818,18 +818,25 @@ Element.implement({
clone: function(contents, keepid){
contents = contents !== false;
- var oldID;
+ var cloneNode = function(){return false};
/*<ltIE8>*/
- if (Browser.ie6 || Browser.ie7 && !keepid){
- oldID = this.removeAttribute('id'); //if element has ID, IE6/7 will break document.id
- }
- /*</ltIE8>*/
- var clone = this.cloneNode(contents), ce = [clone], te = [this], i;
- /*<ltIE8>*/
- if (oldID && (Browser.ie6 || Browser.ie7)){
- this.setAttribute('id', oldID);
+ if (Browser.ie6 || Browser.ie7){
+ var self = this;
+ cloneNode = function(contents){
+ var oldID = '' + self.id;
+ self.removeAttribute('id');
+ var clonedHTML = self.outerHTML;
+ var cloned = document.createElement('div');
+ 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('*')));
@@ -860,6 +867,8 @@ Element.implement({
for (i = co.length; i--;) co[i].outerHTML = to[i].outerHTML;
}
/*</ltIE9>*/
+
+
return document.id(clone);
}
@@ -11,8 +11,6 @@ describe('Element', function(){
describe('Element.getProperty', function(){
it('should cloneNode properly on IE6/7', function(){
- var div = new Element('div');
- div.innerHTML = "<input id='Q1' class='foo' rel='hai' />​";
var div = new Element('div');
div.inject(document.documentElement);

0 comments on commit 24fdab0

Please sign in to comment.