X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=db65cfb0cd24b1bd24e114bbc2409805359d2553;hb=ed5bda3020bd418ad8edb477ad2b1fd8b313cc04;hp=78d1ab94d2c4d60df35b40a659de9e7ee4000ee9;hpb=5acecf6e2814701f9e22f91f17fcb33ef910e88a;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 78d1ab9..db65cfb 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -23,39 +23,41 @@ window.undefined = window.undefined; * @cat Core */ var jQuery = function(a,c) { + // If the context is global, return a new object + if ( window == this ) + return new jQuery(a,c); + // Make sure that a selection was provided a = a || document; + // HANDLE: $(function) // Shortcut for document ready // Safari reports typeof on DOM NodeLists as a function - if ( typeof a == "function" && !a.nodeType && a[0] == undefined ) - return jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a ); - - // Watch for when a jQuery object is passed as the selector - if ( a.jquery ) - return jQuery( jQuery.makeArray( a ) ); - - // Watch for when a jQuery object is passed at the context - if ( c && c.jquery ) - return jQuery( c ).find(a); - - // If the context is global, return a new object - if ( window == this ) - return new jQuery(a,c); - + if ( isFunction(a) && !a.nodeType && a[0] == undefined ) + return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a ); + // Handle HTML strings if ( typeof a == "string" ) { + // HANDLE: $(html) -> $(array) var m = /^[^<]*(<.+>)[^>]*$/.exec(a); - if ( m ) a = jQuery.clean( [ m[1] ] ); + if ( m ) + a = jQuery.clean( [ m[1] ] ); + + // HANDLE: $(expr) + else + return new jQuery( c ).find( a ); } + + return this.setArray( + // HANDLE: $(array) + a.constructor == Array && a || - // Watch for when an array is passed in - return this.setArray( a.constructor == Array || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType ? - // Assume that it is an array of DOM Elements - jQuery.makeArray( a ) : + // HANDLE: $(arraylike) + // Watch for when an array-like object is passed as the selector + (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) || - // Find the matching elements and save them for later - jQuery.find( a, c ) ); + // HANDLE: $(*) + [ a ] ); }; // Map over the $ in case of overwrite @@ -152,25 +154,18 @@ var $ = jQuery; * }); * @desc Executes the function when the DOM is ready to be used. * - * @name $ - * @param Function fn The function to execute when the DOM is ready. - * @cat Core - * @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). + * @example jQuery(function($) { + * // Your code using failsafe $ alias here... + * }); + * @desc Uses both the shortcut for $(document).ready() and the argument + * to write failsafe jQuery code using the $ alias, without relying on the + * global alias. * * @name $ - * @param jQuery obj The jQuery object to be cloned. + * @param Function fn The function to execute when the DOM is ready. * @cat Core * @type jQuery + * @see ready(Function) */ jQuery.fn = jQuery.prototype = { @@ -258,16 +253,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 ); @@ -275,7 +270,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 ]); @@ -428,30 +423,26 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Attributes */ attr: function( key, value, type ) { + var obj = key; + + // Look for the case where we're accessing a style value + if ( key.constructor == String ) + if ( value == undefined ) + return jQuery[ type || "attr" ]( this[0], key ); + else { + obj = {}; + obj[ key ] = value; + } + // Check to see if we're setting style values - return typeof key != "string" || value != undefined ? - this.each(function(){ - // See if we're setting a hash of styles - if ( value == undefined ) - // Set all the styles - for ( var prop in key ) - jQuery.attr( - type ? this.style : this, - prop, jQuery.parseSetter(key[prop]) - ); - - // See if we're setting a single key/value style - else { - // convert ${this.property} to function returnung that property - jQuery.attr( - type ? this.style : this, - key, jQuery.parseSetter(value) - ); - } - }) : - - // Look for the case where we're accessing a style value - jQuery[ type || "attr" ]( this[0], key ); + return this.each(function(){ + // Set all the styles + for ( var prop in obj ) + jQuery.attr( + type ? this.style : this, + prop, jQuery.prop(this, obj[prop], type) + ); + }); }, /** @@ -494,16 +485,22 @@ jQuery.fn = jQuery.prototype = { /** * Set a single style property to a value, on all matched elements. + * If a number is provided, it is automatically converted into a pixel value. * * @example $("p").css("color","red"); * @before

Test Paragraph.

* @result

Test Paragraph.

* @desc Changes the color of all paragraphs to red * + * @example $("p").css("left",30); + * @before

Test Paragraph.

+ * @result

Test Paragraph.

+ * @desc Changes the left of all paragraphs to "30px" + * * @name css * @type jQuery * @param String key The name of the property to set. - * @param Object value The value to set the property to. + * @param String|Number value The value to set the property to. * @cat CSS */ css: function( key, value ) { @@ -528,10 +525,8 @@ jQuery.fn = jQuery.prototype = { /** * Set the text contents of all matched elements. * - * Similar to html(), but escapes HTML (replace "<" and ">" with their - * HTML entities. - * - * If stripTags argument is set to true, HTML is stripped. + * Similar to html(), but escapes HTML (replace "<" and ">" with their + * HTML entities). * * @example $("p").text("Some new text."); * @before

Test Paragraph.

@@ -546,23 +541,15 @@ jQuery.fn = jQuery.prototype = { * @name text * @type String * @param String val The text value to set the contents of the element to. - * @param Boolean stripTags (optional) Wheather to strip or only escape tags * @cat DOM/Attributes */ - text: function(e, stripTags) { - if ( typeof e == "string" ) - return this.html( stripTags ? e.replace(/<\/?[^>]+>/gi, '') : e.replace(//g, ">") ); - - e = e || this; - var t = ""; - for ( var j = 0, el = e.length; j < el; j++ ) { - var r = e[j].childNodes; - for ( var i = 0, rl = r.length; i < rl; i++ ) - if ( r[i].nodeType != 8 ) - t += r[i].nodeType != 1 ? - r[i].nodeValue : jQuery.fn.text([ r[i] ]); - } - return t; + text: function(e) { + var type = this.length && this[0].innerText == undefined ? + "textContent" : "innerText"; + + return e == undefined ? + jQuery.map(this, function(a){ return a[ type ]; }).join('') : + this.each(function(){ this[ type ] = e; }); }, /** @@ -808,7 +795,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); }) ); }, @@ -826,10 +813,11 @@ jQuery.fn = jQuery.prototype = { * * @name clone * @type jQuery + * @param Boolean deep (Optional) Set to false if you don't want to clone all descendant nodes, in addition to the element itself. * @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 ); }) ); }, @@ -839,21 +827,21 @@ jQuery.fn = jQuery.prototype = { * match the specified expression(s). This method is used to narrow down * the results of a search. * - * Provide a String array of expressions to apply multiple filters at once. + * Provide a comma-separated list of expressions to apply multiple filters at once. * * @example $("p").filter(".selected") * @before

Hello

How are you?

* @result [

Hello

] * @desc Selects all paragraphs and removes those without a class "selected". * - * @example $("p").filter([".selected", ":first"]) + * @example $("p").filter(".selected, :first") * @before

Hello

Hello Again

And Again

* @result [

Hello

,

And Again

] * @desc Selects all paragraphs and removes those without class "selected" and being the first one. * * @name filter * @type jQuery - * @param String|Array expression Expression(s) to search with. + * @param String expression Expression(s) to search with. * @cat DOM/Traversing */ @@ -875,22 +863,13 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Traversing */ filter: function(t) { - return this.set( - t.constructor == Array && - jQuery.map(this,function(a){ - for ( var i = 0, tl = t.length; i < tl; i++ ) - if ( jQuery.filter(t[i],[a]).r.length ) - return a; - return null; + return this.pushStack( + isFunction( t.constructor ) && + jQuery.grep(this, function(el, index){ + return t.apply(el, [index]) }) || - t.constructor == Boolean && - ( t ? this.get() : [] ) || - - typeof t == "function" && - jQuery.grep( this, function(el, index) { return t.apply(el, [index]) }) || - - jQuery.filter(t,this).r ); + jQuery.multiFilter(t,this) ); }, /** @@ -923,10 +902,33 @@ jQuery.fn = jQuery.prototype = { * @param String expr An expression with which to remove matching elements * @cat DOM/Traversing */ + + /** + * Removes any elements inside the array of elements from the set + * of matched elements. This method is used to remove one or more + * elements from a jQuery object. + * + * @example $("p").not( $("div p.selected") ) + * @before

Hello

Hello Again

+ * @result [

Hello

] + * @desc Removes all elements that match "div p.selected" from the total set of all paragraphs. + * + * @name not + * @type jQuery + * @param Array|jQuery elems A set of elements to remove from the jQuery set of matched elements. + * @cat DOM/Traversing + */ not: function(t) { - return this.set( typeof t == "string" ? - jQuery.filter(t,this,true).r : - jQuery.grep(this,function(a){ return a != t; }) ); + return this.pushStack( + t.constructor == String && + jQuery.multiFilter(t,this,true) || + + jQuery.grep(this,function(a){ + if ( t.constructor == Array || t.jquery ) + return jQuery.inArray( t, a ) < 0; + else + return a != t; + }) ); }, /** @@ -942,6 +944,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. @@ -962,10 +977,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 ) + ); }, /** @@ -1021,7 +1036,9 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Attributes */ val: function( val ) { - return val == undefined ? ( this.length ? this[0].value : null ) : this.attr( "value", val ); + return val == undefined ? + ( this.length ? this[0].value : null ) : + this.attr( "value", val ); }, /** @@ -1051,7 +1068,9 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Attributes */ html: function( val ) { - return val == undefined ? ( this.length ? this[0].innerHTML : null ) : this.attr( "innerHTML", val ); + return val == undefined ? + ( this.length ? this[0].innerHTML : null ) : + this.empty().append( val ); }, /** @@ -1193,6 +1212,10 @@ jQuery.extend({ $ = jQuery._$; }, + isFunction: function( fn ) { + return fn && typeof fn == "function"; + }, + /** * A generic iterator function, which can be used to seemlessly * iterate over both objects and arrays. This function is not the same @@ -1231,22 +1254,40 @@ jQuery.extend({ if ( fn.apply( obj[i], args || [i, obj[i]] ) === false ) break; return obj; }, + + prop: function(elem, value, type){ + // Handle executable functions + if ( isFunction( value ) ) + return value.call( elem ); + + // Handle passing in a number to a CSS property + if ( value.constructor == Number && type == "css" ) + return value + "px"; + + return value; + }, className: { + // internal only, use addClass("class") add: function( elem, c ){ jQuery.each( c.split(/\s+/), function(i, cur){ if ( !jQuery.className.has( elem.className, cur ) ) 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(' ') : ""; }, - has: function( classes, c ){ - return classes && new RegExp("(^|\\s)" + c + "(\\s|$)").test( classes ); + + // internal only, use is(".class") + has: function( t, c ) { + t = t.className || t; + return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t ); } }, @@ -1313,11 +1354,10 @@ jQuery.extend({ if (prop == "float" || prop == "cssFloat") prop = jQuery.browser.msie ? "styleFloat" : "cssFloat"; - if (!force && elem.style[prop]) { - + if (!force && elem.style[prop]) ret = elem.style[prop]; - } else if (document.defaultView && document.defaultView.getComputedStyle) { + else if (document.defaultView && document.defaultView.getComputedStyle) { if (prop == "cssFloat" || prop == "styleFloat") prop = "float"; @@ -1347,66 +1387,74 @@ jQuery.extend({ clean: function(a) { var r = []; + for ( var i = 0, al = a.length; i < al; i++ ) { var arg = a[i]; - if ( typeof arg == "string" ) { // Convert html string into DOM nodes + + if ( !arg ) continue; + + if ( arg.constructor == Number ) + arg = arg.toString(); + + // Convert html string into DOM nodes + if ( typeof arg == "string" ) { // Trim whitespace, otherwise indexOf won't work as expected - var s = jQuery.trim(arg), s3 = s.substring(0,3), s6 = s.substring(0,6), - div = document.createElement("div"), wrap = [0,"",""]; - - if ( s.substring(0,4) == "", ""]; - else if ( s6 == "", ""]; - else if ( s3 == "", ""]; - else if ( s3 == " matched above - wrap = [3, "", "
"]; + var s = jQuery.trim(arg), div = document.createElement("div"), tb = []; + + var wrap = + // option or optgroup + !s.indexOf("", ""] || + + (!s.indexOf("", ""] || + + !s.indexOf("", ""] || + + // matched above + (!s.indexOf("", ""] || + + [0,"",""]; // Go to html and back, then peel off extra wrappers div.innerHTML = wrap[1] + s + wrap[2]; - while ( wrap[0]-- ) div = div.firstChild; + + // Move to the right depth + while ( wrap[0]-- ) + div = div.firstChild; // Remove IE's autoinserted from table fragments if ( jQuery.browser.msie ) { - var tb = null; + // String was a , *may* have spurious - if ( s6 == " or else if ( wrap[1] == "
" && s.indexOf("= 0 ; --n ) - if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length ) - tb[n].parentNode.removeChild(tb[n]); - } + + for ( var n = tb.length-1; n >= 0 ; --n ) + if ( tb[n].nodeName.toUpperCase() == "TBODY" && !tb[n].childNodes.length ) + tb[n].parentNode.removeChild(tb[n]); + } arg = div.childNodes; - } - + } - if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function - for ( var n = 0, argl = arg.length; n < argl; n++ ) // Handles Array, jQuery, DOM NodeList collections - r.push(arg[n]); + if ( arg[0] == undefined ) + r.push( arg ); else - r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) ); + r = jQuery.merge( r, arg ); + } return r; }, - parseSetter: function(value) { - if( typeof value == "string" && value.charAt(0) == "$" ) { - var m = value.match(/{(.*)}$/); - if ( m && m[1] ) { - value = new Function( "return " + m[1] ); - } - } - return value; - }, - attr: function(elem, name, value){ var fix = { "for": "htmlFor", @@ -1422,11 +1470,6 @@ jQuery.extend({ selected: "selected" }; - // get value if a function is provided - if ( value && typeof value == "function" ) { - value = value.apply( elem ); - } - // IE actually uses filters for opacity ... elem is actually elem.style if ( name == "opacity" && jQuery.browser.msie && value != undefined ) { // IE has trouble with opacity if it does not have layout @@ -1437,10 +1480,9 @@ jQuery.extend({ return elem.filter = elem.filter.replace(/alpha\([^\)]*\)/gi,"") + ( value == 1 ? "" : "alpha(opacity=" + value * 100 + ")" ); - } else if ( name == "opacity" && jQuery.browser.msie ) { + } else if ( name == "opacity" && jQuery.browser.msie ) return elem.filter ? parseFloat( elem.filter.match(/alpha\(opacity=(.*)\)/)[1] ) / 100 : 1; - } // Mozilla doesn't play well with opacity 1 if ( name == "opacity" && jQuery.browser.mozilla && value == 1 ) @@ -1451,11 +1493,11 @@ jQuery.extend({ if ( value != undefined ) elem[fix[name]] = value; return elem[fix[name]]; - } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) { + } else if ( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) return elem.getAttributeNode(name).nodeValue; // IE elem.getAttribute passes even for style - } else if ( elem.tagName ) { + else if ( elem.tagName ) { if ( value != undefined ) elem.setAttribute( name, value ); return elem.getAttribute( name ); @@ -1484,10 +1526,10 @@ jQuery.extend({ makeArray: function( a ) { var r = []; - if ( a.constructor != Array ) { + if ( a.constructor != Array ) for ( var i = 0, al = a.length; i < al; i++ ) r.push( a[i] ); - } else + else r = a.slice( 0 ); return r; @@ -1525,12 +1567,11 @@ jQuery.extend({ // Now check for duplicates between the two arrays // and only add the unique items - for ( var i = 0, sl = second.length; i < sl; i++ ) { + for ( var i = 0, sl = second.length; i < sl; i++ ) // Check for duplicates if ( jQuery.inArray( second[i], r ) == -1 ) // The item is unique, add it first.push( second[i] ); - } return first; }, @@ -1667,7 +1708,7 @@ jQuery.extend({ */ /* - * Wheather the W3C compliant box model is being used. + * Whether the W3C compliant box model is being used. * * @property * @name $.boxModel @@ -1826,17 +1867,17 @@ 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){ jQuery.fn[ i ] = function(a) { var ret = jQuery.map(this,n); if ( a && typeof a == "string" ) - ret = jQuery.filter(a,ret).r; - return this.set( ret ); + ret = jQuery.multiFilter(a,ret); + return this.pushStack( ret ); }; }); @@ -1853,8 +1894,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() */ /** @@ -1870,8 +1912,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() */ /** @@ -1887,8 +1930,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() */ /** @@ -1904,8 +1948,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({ @@ -1937,65 +1982,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

@@ -2005,9 +2010,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) */ @@ -2063,20 +2072,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); }, @@ -2087,7 +2082,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() { @@ -2162,3 +2157,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" ); + }; +});