X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=401fd142d80ea45651de7ab67b2cdbc22d70517a;hb=ee0175c4b9d665322ac496dfcc6f8b0cc70b3c35;hp=4fb7f8e75b86a147be99c51b9833206eec61705c;hpb=76d6d445bb68009c010e0b91dbf21747bc2d35ba;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 4fb7f8e..401fd14 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -160,21 +160,6 @@ var $ = jQuery; * @type jQuery */ -/** - * A means of creating a cloned copy of a jQuery object. This function - * copies the set of matched elements from one jQuery object and creates - * another, new, jQuery object containing the same elements. - * - * @example var div = $("div"); - * $( div ).find("p"); - * @desc Locates all p elements with all div elements, without disrupting the original jQuery object contained in 'div' (as would normally be the case if a simple div.find("p") was done). - * - * @name $ - * @param jQuery obj The jQuery object to be cloned. - * @cat Core - * @type jQuery - */ - jQuery.fn = jQuery.prototype = { /** * The current version of jQuery. @@ -260,16 +245,16 @@ jQuery.fn = jQuery.prototype = { * Set the jQuery object to an array of elements, while maintaining * the stack. * - * @example $("img").set([ document.body ]); - * @result $("img").set() == [ document.body ] + * @example $("img").pushStack([ document.body ]); + * @result $("img").pushStack() == [ document.body ] * * @private - * @name set + * @name pushStack * @type jQuery * @param Elements elems An array of elements * @cat Core */ - set: function( a ) { + pushStack: function( a ) { var ret = jQuery(this); ret.prevObject = this; return ret.setArray( a ); @@ -277,7 +262,7 @@ jQuery.fn = jQuery.prototype = { /** * Set the jQuery object to an array of elements. This operation is - * completely destructive - be sure to use .set() if you wish to maintain + * completely destructive - be sure to use .pushStack() if you wish to maintain * the jQuery stack. * * @example $("img").setArray([ document.body ]); @@ -447,7 +432,7 @@ jQuery.fn = jQuery.prototype = { for ( var prop in obj ) jQuery.attr( type ? this.style : this, - prop, jQuery.prop(this, prop, obj[prop], type) + prop, jQuery.prop(this, obj[prop]) ); }); }, @@ -796,7 +781,7 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Traversing */ find: function(t) { - return this.set( jQuery.map( this, function(a){ + return this.pushStack( jQuery.map( this, function(a){ return jQuery.find(t,a); }) ); }, @@ -817,7 +802,7 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Manipulation */ clone: function(deep) { - return this.set( jQuery.map( this, function(a){ + return this.pushStack( jQuery.map( this, function(a){ return a.cloneNode( deep != undefined ? deep : true ); }) ); }, @@ -863,7 +848,7 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Traversing */ filter: function(t) { - return this.set( + return this.pushStack( t.constructor == Array && jQuery.map(this,function(a){ for ( var i = 0, tl = t.length; i < tl; i++ ) @@ -912,7 +897,7 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Traversing */ not: function(t) { - return this.set( typeof t == "string" ? + return this.pushStack( typeof t == "string" ? jQuery.filter(t,this,true).r : jQuery.grep(this,function(a){ return a != t; }) ); }, @@ -930,6 +915,19 @@ jQuery.fn = jQuery.prototype = { * @param String expr An expression whose matched elements are added * @cat DOM/Traversing */ + + /** + * Adds the on the fly created elements to the jQuery object. + * + * @example $("p").add("Again") + * @before

Hello

+ * @result [

Hello

, Again ] + * + * @name add + * @type jQuery + * @param String html A string of HTML to create on the fly. + * @cat DOM/Traversing + */ /** * Adds one or more Elements to the set of matched elements. @@ -950,10 +948,10 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Traversing */ add: function(t) { - return this.set( jQuery.merge( - this.get(), typeof t == "string" ? - jQuery.find(t) : - t.constructor == Array ? t : [t] ) ); + return this.pushStack( jQuery.merge( + this.get(), + typeof t == "string" ? jQuery(t).get() : t ) + ); }, /** @@ -1220,7 +1218,7 @@ jQuery.extend({ return obj; }, - prop: function(elem, key, value){ + prop: function(elem, value){ // Handle executable functions return value.constructor == Function && value.call( elem ) || value; @@ -1234,13 +1232,15 @@ jQuery.extend({ elem.className += ( elem.className ? " " : "" ) + cur; }); }, + // internal only, use removeClass("class") remove: function( elem, c ){ - elem.className = c ? - jQuery.grep( elem.className.split(/\s+/), function(cur){ - return !jQuery.className.has( c, cur ); - }).join(' ') : ""; + elem.className = c ? + jQuery.grep( elem.className.split(/\s+/), function(cur){ + return !jQuery.className.has( c, cur ); + }).join(' ') : ""; }, + // internal only, use is(".class") has: function( t, c ) { t = t.className || t; @@ -1355,16 +1355,17 @@ jQuery.extend({ var wrap = // option or optgroup - !s.indexOf("", ""] || + !s.indexOf("", ""] || - !s.indexOf("", ""] || !s.indexOf("", ""] || // matched above - !s.indexOf("", ""] || [0,"",""]; @@ -1400,6 +1401,7 @@ jQuery.extend({ r.push( arg ); else r = jQuery.merge( r, arg ); + } return r; @@ -1817,9 +1819,9 @@ new function() { */ jQuery.each({ parent: "a.parentNode", - parents: jQuery.parents, - next: "jQuery.nth(a,1,'nextSibling')", - prev: "jQuery.nth(a,1,'previousSibling')", + parents: "jQuery.parents(a)", + next: "jQuery.nth(a,2,'nextSibling')", + prev: "jQuery.nth(a,2,'previousSibling')", siblings: "jQuery.sibling(a.parentNode.firstChild,a)", children: "jQuery.sibling(a.firstChild)" }, function(i,n){ @@ -1827,7 +1829,7 @@ jQuery.each({ var ret = jQuery.map(this,n); if ( a && typeof a == "string" ) ret = jQuery.filter(a,ret).r; - return this.set( ret ); + return this.pushStack( ret ); }; }); @@ -1844,8 +1846,9 @@ jQuery.each({ * * @name appendTo * @type jQuery - * @param String expr A jQuery expression of elements to match. + * @param content Content to append to the selected element to. * @cat DOM/Manipulation + * @see append() */ /** @@ -1861,8 +1864,9 @@ jQuery.each({ * * @name prependTo * @type jQuery - * @param String expr A jQuery expression of elements to match. + * @param content Content to prepend to the selected element to. * @cat DOM/Manipulation + * @see prepend() */ /** @@ -1878,8 +1882,9 @@ jQuery.each({ * * @name insertBefore * @type jQuery - * @param String expr A jQuery expression of elements to match. + * @param content Content to insert the selected element before. * @cat DOM/Manipulation + * @see before() */ /** @@ -1895,8 +1900,9 @@ jQuery.each({ * * @name insertAfter * @type jQuery - * @param String expr A jQuery expression of elements to match. + * @param content Content to insert the selected element after. * @cat DOM/Manipulation + * @see after() */ jQuery.each({ @@ -1928,65 +1934,25 @@ jQuery.each({ */ /** - * Displays each of the set of matched elements if they are hidden. - * - * @example $("p").show() - * @before

Hello

- * @result [

Hello

] - * - * @name show - * @type jQuery - * @cat Effects - */ - -/** - * Hides each of the set of matched elements if they are shown. - * - * @example $("p").hide() - * @before

Hello

- * @result [

Hello

] - * - * var pass = true, div = $("div"); - * div.hide().each(function(){ - * if ( this.style.display != "none" ) pass = false; - * }); - * ok( pass, "Hide" ); - * - * @name hide - * @type jQuery - * @cat Effects - */ - -/** - * Toggles each of the set of matched elements. If they are shown, - * toggle makes them hidden. If they are hidden, toggle - * makes them shown. - * - * @example $("p").toggle() - * @before

Hello

Hello Again

- * @result [

Hello

,

Hello Again

] - * - * @name toggle - * @type jQuery - * @cat Effects - */ - -/** - * Adds the specified class to each of the set of matched elements. + * Adds the specified class(es) to each of the set of matched elements. * * @example $("p").addClass("selected") * @before

Hello

* @result [

Hello

] * + * @example $("p").addClass("selected highlight") + * @before

Hello

+ * @result [

Hello

] + * * @name addClass * @type jQuery - * @param String class A CSS class to add to the elements + * @param String class One or more CSS classes to add to the elements * @cat DOM/Attributes * @see removeClass(String) */ /** - * Removes all or the specified class from the set of matched elements. + * Removes all or the specified class(es) from the set of matched elements. * * @example $("p").removeClass() * @before

Hello

@@ -1996,9 +1962,13 @@ jQuery.each({ * @before

Hello

* @result [

Hello

] * + * @example $("p").removeClass("selected highlight") + * @before

Hello

+ * @result [

Hello

] + * * @name removeClass * @type jQuery - * @param String class (optional) A CSS class to remove from the elements + * @param String class (optional) One or more CSS classes to remove from the elements * @cat DOM/Attributes * @see addClass(String) */ @@ -2054,20 +2024,6 @@ jQuery.each( { jQuery.attr( this, key, "" ); this.removeAttribute( key ); }, - show: function(){ - this.style.display = this.oldblock ? this.oldblock : ""; - if ( jQuery.css(this,"display") == "none" ) - this.style.display = "block"; - }, - hide: function(){ - this.oldblock = this.oldblock || jQuery.css(this,"display"); - if ( this.oldblock == "none" ) - this.oldblock = "block"; - this.style.display = "none"; - }, - toggle: function(){ - jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments ); - }, addClass: function(c){ jQuery.className.add(this,c); }, @@ -2078,7 +2034,7 @@ jQuery.each( { jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c); }, remove: function(a){ - if ( !a || jQuery.filter( a, [this] ).r ) + if ( !a || jQuery.filter( a, [this] ).r.length ) this.parentNode.removeChild( this ); }, empty: function() { @@ -2153,3 +2109,71 @@ jQuery.each( [ "eq", "lt", "gt", "contains" ], function(i,n){ return this.filter( ":" + n + "(" + num + ")", fn ); }; }); + +/** + * Get the current computed, pixel, width of the first matched element. + * + * @example $("p").width(); + * @before

This is just a test.

+ * @result 300 + * + * @name width + * @type String + * @cat CSS + */ + +/** + * Set the CSS width of every matched element. If no explicit unit + * was specified (like 'em' or '%') then "px" is added to the width. + * + * @example $("p").width(20); + * @before

This is just a test.

+ * @result

This is just a test.

+ * + * @example $("p").width("20em"); + * @before

This is just a test.

+ * @result

This is just a test.

+ * + * @name width + * @type jQuery + * @param Number|String val Set the CSS property to the specified value. + * @cat CSS + */ + +/** + * Get the current computed, pixel, height of the first matched element. + * + * @example $("p").height(); + * @before

This is just a test.

+ * @result 300 + * + * @name height + * @type String + * @cat CSS + */ + +/** + * Set the CSS width of every matched element. If no explicit unit + * was specified (like 'em' or '%') then "px" is added to the width. + * + * @example $("p").height(20); + * @before

This is just a test.

+ * @result

This is just a test.

+ * + * @example $("p").height("20em"); + * @before

This is just a test.

+ * @result

This is just a test.

+ * + * @name height + * @type jQuery + * @param Number|String val Set the CSS property to the specified value. + * @cat CSS + */ + +jQuery.each( [ "height", "width" ], function(i,n){ + jQuery.fn[ n ] = function(h) { + return h == undefined ? + ( this.length ? jQuery.css( this[0], n ) : null ) : + this.css( n, h.constructor == String ? h : h + "px" ); + }; +});