X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=151f68fdf1bdcd60ddef17db699088fda0dbefb3;hb=34355cd6986d5939dc711c531263cb561cba5f24;hp=9db0f9d5f5f280be42709d806d12d9e29a639599;hpb=9449591eef44360b5bfdb9a23cea1f4a1a6f3c33;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 9db0f9d..151f68f 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -33,7 +33,7 @@ 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 @@ -320,17 +320,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 +544,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 +870,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 +921,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) { @@ -925,18 +931,18 @@ jQuery.fn = jQuery.prototype = { jQuery.grep(this,function(a){ if ( t.constructor == Array || t.jquery ) - return !jQuery.inArray( t, a ); + return jQuery.inArray( t, a ) < 0; else return a != t; }) ); }, /** - * 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 +952,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 +968,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