Completely reworked the evalScripts() code, fixing bugs #1332, #975, and #777.
[jquery.git] / src / jquery / jquery.js
index e846e4d..f54ee30 100644 (file)
@@ -565,7 +565,7 @@ jQuery.fn = jQuery.prototype = {
         * @cat DOM/Attributes
         */
        text: function(e) {
-               if ( typeof e == "string" )
+               if ( typeof e != "object" && e != null )
                        return this.empty().append( document.createTextNode( e ) );
 
                var t = "";
@@ -811,7 +811,7 @@ jQuery.fn = jQuery.prototype = {
 
        /**
         * Searches for all elements that match the specified expression.
-        
+        * 
         * This method is a good way to find additional descendant
         * elements with which to process.
         *
@@ -1171,9 +1171,14 @@ jQuery.fn = jQuery.prototype = {
                                obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
 
                        jQuery.each( a, function(){
-                               fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
+                               if ( jQuery.nodeName(this, "script") ) {
+                                       if ( this.src )
+                                               jQuery.ajax({ url: this.src, async: false, dataType: "script" });
+                                       else
+                                               (new Function( this.text || this.textContent || this.innerHTML || "" ))();
+                               } else
+                                       fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
                        });
-
                });
        }
 };
@@ -1607,7 +1612,7 @@ jQuery.extend({
         * @cat JavaScript
         */
        trim: function(t){
-               return t.replace(/^\s+|\s+$/g, "");
+               return (t||"").replace(/^\s+|\s+$/g, "");
        },
 
        makeArray: function( a ) {
@@ -1666,11 +1671,15 @@ jQuery.extend({
        unique: function(first) {
                var r = [], num = jQuery.mergeNum++;
 
-               for ( var i = 0, fl = first.length; i < fl; i++ )
-                       if ( num != first[i].mergeNum ) {
-                               first[i].mergeNum = num;
-                               r.push(first[i]);
-                       }
+               try {
+                       for ( var i = 0, fl = first.length; i < fl; i++ )
+                               if ( num != first[i].mergeNum ) {
+                                       first[i].mergeNum = num;
+                                       r.push(first[i]);
+                               }
+               } catch(e) {
+                       r = first;
+               }
 
                return r;
        },