X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=ff33034ede6ff512a4f6aac2e796bb891ef06b34;hb=2b05e24993c48f3b9c2cb9857090dc4b218b8834;hp=8e8f7be780a7ceae4148d8b8dab90e2b5460924e;hpb=3c82f8fb4aed7b4e65e1dd9ed79718a155a7a492;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 8e8f7be..ff33034 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -852,7 +852,7 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Manipulation */ clone: function(deep) { - deep = deep != undefined ? deep : true + deep = deep != undefined ? deep : true; var $this = this.add(this.find("*")); if (jQuery.browser.msie) { // Need to remove events on the element and its descendants @@ -938,7 +938,7 @@ jQuery.fn = jQuery.prototype = { return this.pushStack( jQuery.isFunction( t ) && jQuery.grep(this, function(el, index){ - return t.apply(el, [index]) + return t.apply(el, [index]); }) || jQuery.multiFilter(t,this) ); @@ -1160,6 +1160,10 @@ jQuery.fn = jQuery.prototype = { ( this.length ? this[0].innerHTML : null ) : this.empty().append( val ); }, + + slice: function() { + return this.pushStack( Array.prototype.slice.apply( this, arguments ) ); + }, /** * @private @@ -1191,7 +1195,7 @@ jQuery.fn = jQuery.prototype = { if ( this.src ) jQuery.ajax({ url: this.src, async: false, dataType: "script" }); else - (new Function( this.text || this.textContent || this.innerHTML || "" ))(); + jQuery.globalEval( this.text || this.textContent || this.innerHTML || "" ); } else fn.apply( obj, [ clone ? this.cloneNode(true) : this ] ); }); @@ -1252,17 +1256,33 @@ jQuery.fn = jQuery.prototype = { */ jQuery.extend = jQuery.fn.extend = function() { // copy reference to target object - var target = arguments[0], a = 1; + var target = arguments[0] || {}, a = 1, al = arguments.length; // extend jQuery itself if only one argument is passed - if ( arguments.length == 1 ) { + if ( al == 1 ) { target = this; a = 0; } + var prop; - while ( (prop = arguments[a++]) != null ) - // Extend the base object - for ( var i in prop ) target[i] = prop[i]; + + for ( ; a < al; a++ ) + // Only deal with non-null/undefined values + if ( (prop = arguments[a]) != null ) + // Extend the base object + for ( var i in prop ) { + // Prevent never-ending loop + if ( target == prop[i] ) + continue; + + // Recurse if we're merging object values + if ( typeof prop[i] == 'object' && target[i] ) + jQuery.extend( target[i], prop[i] ); + + // Don't bring in undefined values + else if ( prop[i] != undefined ) + target[i] = prop[i]; + } // Return the modified object return target; @@ -1322,6 +1342,21 @@ jQuery.extend({ elem.tagName && elem.ownerDocument && !elem.ownerDocument.body; }, + // Evalulates a script in a global context + // Evaluates Async. in Safari 2 :-( + globalEval: function( data ) { + data = jQuery.trim( data ); + if ( data ) { + if ( window.execScript ) + window.execScript( data ); + else if ( jQuery.browser.safari ) + // safari doesn't provide a synchronous global eval + window.setTimeout( data, 0 ); + else + eval.call( window, data ); + } + }, + nodeName: function( elem, name ) { return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase(); }, @@ -1457,8 +1492,16 @@ jQuery.extend({ }, curCSS: function(elem, prop, force) { - var ret, getComputedStyle = document.defaultView && - document.defaultView.getComputedStyle, stack = [], swap = []; + var ret, stack = [], swap = []; + + // A helper method for determining if an element's values are broken + function color(a){ + if ( !jQuery.browser.safari ) + return false; + + var ret = document.defaultView.getComputedStyle(a,null); + return !ret || ret.getPropertyValue("color") == ""; + } if (prop == "opacity" && jQuery.browser.msie) { ret = jQuery.attr(elem.style, "opacity"); @@ -1471,13 +1514,13 @@ jQuery.extend({ if (!force && elem.style[prop]) ret = elem.style[prop]; - else if (getComputedStyle) { + else if (document.defaultView && document.defaultView.getComputedStyle) { if (prop.match(/float/i)) prop = "float"; prop = prop.replace(/([A-Z])/g,"-$1").toLowerCase(); - var cur = getComputedStyle(elem, null); + var cur = document.defaultView.getComputedStyle(elem, null); if ( cur && !color(elem) ) ret = cur.getPropertyValue(prop); @@ -1486,7 +1529,7 @@ jQuery.extend({ // then some display: none elements are involved else { // Locate all of the parent display: none elements - for ( var a = elem; color(a); a = a.parentNode ) + for ( var a = elem; a && color(a); a = a.parentNode ) stack.unshift(a); // Go through and make them visible, but in reverse @@ -1501,7 +1544,7 @@ jQuery.extend({ // one special, otherwise get the value ret = prop == "display" && swap[stack.length-1] != null ? "none" : - getComputedStyle(elem,null).getPropertyValue(prop) || ""; + document.defaultView.getComputedStyle(elem,null).getPropertyValue(prop) || ""; // Finally, revert the display styles back for ( a = 0; a < swap.length; a++ ) @@ -1512,11 +1555,6 @@ jQuery.extend({ if ( prop == "opacity" && ret == "" ) ret = "1"; - // A helper method for determining if an element's values are broken - function color(a){ - return jQuery.browser.safari && getComputedStyle(a,null).getPropertyValue("color") == ""; - } - } else if (elem.currentStyle) { var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();}); ret = elem.currentStyle[prop] || elem.currentStyle[newProp]; @@ -1548,7 +1586,7 @@ jQuery.extend({ !s.indexOf("", ""] || - (!s.indexOf("", ""] || !s.indexOf("", ""] || !s.indexOf("", ""] || + [2, "", "
"] || + + // IE can't serialize and