X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=e46fc73865c83b517f3ffcb95d8f77f6aa2038b8;hb=2aa67026ebe6bea90fd137fc99b4c9422977e3f0;hp=607038944cbe1d3a4e7a10a246e08d77d55d8e03;hpb=4b2028896db81e7c5fee13b92a23e89526762f6a;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 6070389..e46fc73 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -1,7 +1,7 @@ /* * jQuery @VERSION - New Wave Javascript * - * Copyright (c) 2006 John Resig (jquery.com) + * Copyright (c) 2007 John Resig (jquery.com) * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * @@ -33,19 +33,19 @@ var jQuery = function(a,c) { // HANDLE: $(function) // Shortcut for document ready // Safari reports typeof on DOM NodeLists as a function - if ( typeof a == "function" && !a.nodeType && a[0] == undefined ) + if ( jQuery.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] ] ); + + a = m ? + // HANDLE: $(html) -> $(array) + jQuery.clean( [ m[1] ] ) : - // HANDLE: $(expr) - else - return new jQuery( c ).find( a ); + // HANDLE: $(expr) + jQuery.find( a, c ); } return this.setArray( @@ -122,11 +122,6 @@ var $ = jQuery; * This function also accepts XML Documents and Window objects * as valid arguments (even though they are not DOM Elements). * - * @example $(document).find("div > p") - * @before

one

two

three

- * @result [

two

] - * @desc Same as $("div > p") because the document - * * @example $(document.body).background( "black" ); * @desc Sets the background color of the page to black. * @@ -320,17 +315,17 @@ jQuery.fn = jQuery.prototype = { * Returns -1 if the object wasn't found. * * @example $("*").index( $('#foobar')[0] ) - * @before
+ * @before
* @result 0 * @desc Returns the index for the element with ID foobar * - * @example $("*").index( $('#foo')) - * @before
+ * @example $("*").index( $('#foo')[0] ) + * @before
* @result 2 - * @desc Returns the index for the element with ID foo + * @desc Returns the index for the element with ID foo within another element * - * @example $("*").index( $('#bar')) - * @before
+ * @example $("*").index( $('#bar')[0] ) + * @before
* @result -1 * @desc Returns -1, as there is no element with ID bar * @@ -544,12 +539,18 @@ jQuery.fn = jQuery.prototype = { * @cat DOM/Attributes */ 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; }); + if ( typeof e == "string" ) + return this.empty().append( document.createTextNode( e ) ); + + var t = ""; + jQuery.each( e || this, function(){ + jQuery.each( this.childNodes, function(){ + if ( this.nodeType != 8 ) + t += this.nodeType != 1 ? + this.nodeValue : jQuery.fn.text([ this ]); + }); + }); + return t; }, /** @@ -864,7 +865,7 @@ jQuery.fn = jQuery.prototype = { */ filter: function(t) { return this.pushStack( - t.constructor == Function && + jQuery.isFunction( t ) && jQuery.grep(this, function(el, index){ return t.apply(el, [index]) }) || @@ -915,7 +916,7 @@ jQuery.fn = jQuery.prototype = { * * @name not * @type jQuery - * @param Array|jQuery elems A set of elements to remove from the jQuery set of matched elements. + * @param jQuery elems A set of elements to remove from the jQuery set of matched elements. * @cat DOM/Traversing */ not: function(t) { @@ -932,11 +933,11 @@ jQuery.fn = jQuery.prototype = { }, /** - * Adds the elements matched by the expression to the jQuery object. This - * can be used to concatenate the result sets of two expressions. + * Adds more elements, matched by the given expression, + * to the set of matched elements. * * @example $("p").add("span") - * @before

Hello

Hello Again

+ * @before

Hello

Hello Again * @result [

Hello

, Hello Again ] * * @name add @@ -946,7 +947,8 @@ jQuery.fn = jQuery.prototype = { */ /** - * Adds the on the fly created elements to the jQuery object. + * Adds more elements, created on the fly, to the set of + * matched elements. * * @example $("p").add("Again") * @before

Hello

@@ -961,15 +963,13 @@ jQuery.fn = jQuery.prototype = { /** * Adds one or more Elements to the set of matched elements. * - * This is used to add a set of Elements to a jQuery object. - * * @example $("p").add( document.getElementById("a") ) * @before

Hello

Hello Again

* @result [

Hello

, Hello Again ] * - * @example $("p").add([document.getElementById("a"), document.getElementById("b")]) - * @before

Hello

Hello AgainAnd Again

- * @result [

Hello

, Hello Again, And Again ] + * @example $("p").add( document.forms[0].elements ) + * @before

Hello