X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=115ee7f2d70274f81f43ae81829dde825fe089c3;hb=c0e4280282d03a449caaf87d5a6bfe151a874796;hp=33d7c05c0496bc9f63ac8d6cc96fdb7ba0d39d58;hpb=94fc6aac1990dc3233c70f471432c5b9f230e756;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 33d7c05..115ee7f 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -29,9 +29,6 @@ window.undefined = window.undefined; */ function jQuery(a,c) { - // Initalize the extra macro functions - if ( !jQuery.initDone ) jQuery.init(); - // Shortcut for document ready (because $(document).each() is silly) if ( a && a.constructor == Function && jQuery.fn.ready ) return jQuery(document).ready(a); @@ -39,25 +36,6 @@ function jQuery(a,c) { // Make sure that a selection was provided a = a || jQuery.context || document; - /* - * Handle support for overriding other $() functions. Way too many libraries - * provide this function to simply ignore it and overwrite it. - */ - /* - // Check to see if this is a possible collision case - if ( jQuery._$ && !c && a.constructor == String && - - // Make sure that the expression is a colliding one - !/[^a-zA-Z0-9_-]/.test(a) && - - // and that there are no elements that match it - // (this is the one truly ambiguous case) - !document.getElementsByTagName(a).length ) - - // Use the default method, in case it works some voodoo - return jQuery._$( a ); - */ - // Watch for when a jQuery object is passed as the selector if ( a.jquery ) return $( jQuery.merge( a, [] ) ); @@ -82,13 +60,16 @@ function jQuery(a,c) { // Find the matching elements and save them for later jQuery.find( a, c ) ); + // See if an extra function was provided var fn = arguments[ arguments.length - 1 ]; + + // If so, execute it in context if ( fn && fn.constructor == Function ) this.each(fn); } // Map over the $ in case of overwrite -if ( $ ) +if ( typeof $ != "undefined" ) jQuery._$ = $; // Map the jQuery namespace to the '$' one @@ -212,7 +193,15 @@ jQuery.fn = jQuery.prototype = { * argument representing the position of the element in the matched * set. * - * @example $("img").each(function(){ this.src = "test.jpg"; }); + * @example $("img").each(function(){ + * this.src = "test.jpg"; + * }); + * @before + * @result + * + * @example $("img").each(function(i){ + * alert( "Image #" + i + " is " + this ); + * }); * @before * @result * @@ -648,6 +637,7 @@ jQuery.fn = jQuery.prototype = { * @example $("p").not("#selected") * @before

Hello

Hello Again

* @result [

Hello

] + * @test cmpOK($("#main > p#ap > a").not("#google").length, "==", 2, ".not") * * @name not * @type jQuery @@ -685,7 +675,7 @@ jQuery.fn = jQuery.prototype = { * @name add * @type jQuery * @param Array els An array of Elements to add - * @cat jQuery + * @cat DOM/Traversing */ /** @@ -699,7 +689,7 @@ jQuery.fn = jQuery.prototype = { * @name add * @type jQuery * @param Element el An Element to add - * @cat jQuery + * @cat DOM/Traversing */ add: function(t) { return this.pushStack( jQuery.merge( this, t.constructor == String ? @@ -714,7 +704,7 @@ jQuery.fn = jQuery.prototype = { * @member jQuery * @param {String} expr The expression with which to filter * @type Boolean - * @cat jQuery + * @cat DOM/Traversing */ is: function(expr) { return expr ? jQuery.filter(expr,this).r.length > 0 : this.length > 0; @@ -811,8 +801,6 @@ jQuery.extend = jQuery.fn.extend = function(obj,prop) { jQuery.extend({ /** - * - * * @private * @name init * @type undefined @@ -934,17 +922,21 @@ jQuery.extend({ if (jQuery.css(e,"display") != "none") { oHeight = e.offsetHeight; oWidth = e.offsetWidth; - } else - jQuery.swap( e, { visibility: "hidden", position: "absolute", display: "block" }, - function(){ - oHeight = e.clientHeight; - oWidth = e.clientWidth; - }); + } else { + e = $(e.cloneNode(true)).css({ + visibility: "hidden", position: "absolute", display: "block" + }).prependTo("body")[0]; + + oHeight = e.clientHeight; + oWidth = e.clientWidth; + + e.parentNode.removeChild(e); + } }); return p == "height" ? oHeight : oWidth; } else if ( p == "opacity" && jQuery.browser.msie ) - return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1; + return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1; return jQuery.curCSS( e, p ); }, @@ -959,7 +951,7 @@ jQuery.extend({ } else if (elem.currentStyle) { var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()}); - ret = elem.currentStyle[prop] || elem.currentStyle[np]; + ret = elem.currentStyle[prop] || elem.currentStyle[newProp]; } else if (document.defaultView && document.defaultView.getComputedStyle) { @@ -2218,7 +2210,7 @@ jQuery.macros = { /** * Get a set of elements containing the unique ancestors of the matched - * set of elements. + * set of elements (except for the root element). * * @example $("span").ancestors() * @before

Hello

Hello Again
@@ -2246,7 +2238,7 @@ jQuery.macros = { /** * Get a set of elements containing the unique ancestors of the matched - * set of elements. + * set of elements (except for the root element). * * @example $("span").ancestors() * @before

Hello

Hello Again
@@ -2417,7 +2409,7 @@ jQuery.macros = { * @type jQuery * @cat Effects */ - _show: function(){ + show: function(){ this.style.display = this.oldblock ? this.oldblock : ""; if ( jQuery.css(this,"display") == "none" ) this.style.display = "block"; @@ -2440,7 +2432,7 @@ jQuery.macros = { * @type jQuery * @cat Effects */ - _hide: function(){ + hide: function(){ this.oldblock = this.oldblock || jQuery.css(this,"display"); if ( this.oldblock == "none" ) this.oldblock = "block"; @@ -2460,9 +2452,8 @@ jQuery.macros = { * @type jQuery * @cat Effects */ - _toggle: function(){ - var d = jQuery.css(this,"display"); - $(this)[ !d || d == "none" ? "show" : "hide" ](); + toggle: function(){ + $(this)[ $(this).is(":hidden") ? "show" : "hide" ].apply( $(this), arguments ); }, /** @@ -2672,3 +2663,5 @@ jQuery.macros = { } } }; + +jQuery.init();