Fixed bug #1594, #1565, #1598 - all of which were concerning the improper execution...
[jquery.git] / src / core.js
index 140208d..d9749ba 100644 (file)
@@ -233,17 +233,23 @@ jQuery.fn = jQuery.prototype = {
                var ret = this.map(function(){
                        return this.outerHTML ? jQuery(this.outerHTML)[0] : this.cloneNode(true);
                });
-               
-               if (events === true) {
-                       var clone = ret.find("*").andSelf();
 
+               // Need to set the expando to null on the cloned set if it exists
+               // removeData doesn't work here, IE removes it from the original as well
+               // this is primarily for IE but the data expando shouldn't be copied over in any browser
+               var clone = ret.find("*").andSelf().each(function(){
+                       if ( this[ expando ] != undefined )
+                               this[ expando ] = null;
+               });
+               
+               // Copy the events from the original to the clone
+               if (events === true)
                        this.find("*").andSelf().each(function(i) {
                                var events = jQuery.data(this, "events");
                                for ( var type in events )
                                        for ( var handler in events[type] )
                                                jQuery.event.add(clone[i], type, events[type][handler], events[type][handler].data);
                        });
-               }
 
                // Return the cloned set
                return ret;
@@ -388,18 +394,32 @@ jQuery.fn = jQuery.prototype = {
                                obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
 
                        jQuery.each( a, function(){
-                               if ( jQuery.nodeName(this, "script") ) {
-                                       if ( this.src )
-                                               jQuery.ajax({ url: this.src, async: false, dataType: "script" });
-                                       else
-                                               jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" );
-                               } else
-                                       fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
+                               var elem = clone ? this.cloneNode(true) : this;
+                               if ( !evalScript(0, elem) )
+                                       fn.call( obj, elem );
                        });
                });
        }
 };
 
+function evalScript(i, elem){
+       var script = jQuery.nodeName(elem, "script");
+
+       if ( script ) {
+               if ( elem.src )
+                       jQuery.ajax({ url: elem.src, async: false, dataType: "script" });
+               else
+                       jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
+       
+               if ( elem.parentNode )
+                       elem.parentNode.removeChild(elem);
+
+       } else if ( elem.nodeType == 1 )
+    jQuery("script", elem).each(evalScript);
+
+       return script;
+}
+
 jQuery.extend = jQuery.fn.extend = function() {
        // copy reference to target object
        var target = arguments[0] || {}, a = 1, al = arguments.length, deep = false;