X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=jquery%2Fjquery.js;h=369ff88d62537597a58f9a2ea2193bbf60cbb586;hb=82e0a5a810f09b601543d3406b65ac15bd22307e;hp=59375613d1f86d2d28deb1fdb29071026867b7e0;hpb=f4c67b7c5aba7fbdaf4b883b71ff9cc1b66e9af8;p=jquery.git diff --git a/jquery/jquery.js b/jquery/jquery.js index 5937561..369ff88 100644 --- a/jquery/jquery.js +++ b/jquery/jquery.js @@ -18,6 +18,9 @@ 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); @@ -61,8 +64,8 @@ function jQuery(a,c) { if ( m ) a = jQuery.clean( [ m[1] ] ); // Watch for when an array is passed in - this.get( a.constructor == Array || a.length && a[0].nodeType ? - // Assume that it's an array of DOM Elements + this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ? + // Assume that it is an array of DOM Elements jQuery.merge( a, [] ) : // Find the matching elements and save them for later @@ -193,13 +196,7 @@ jQuery.fn = jQuery.prototype = { * @param Function fn A function to execute */ each: function( fn, args ) { - // Iterate through all of the matched elements - for ( var i = 0; i < this.length; i++ ) - - // Execute the function within the context of each element - fn.apply( this[i], args || [i] ); - - return this; + return jQuery.each( this, fn, args ); }, /** @@ -666,11 +663,10 @@ jQuery.fn = jQuery.prototype = { } else obj = tbody[0]; } - //alert( obj ); + for ( var i = ( dir < 0 ? a.length - 1 : 0 ); i != ( dir < 0 ? dir : a.length ); i += dir ) { fn.apply( obj, [ clone ? a[i].cloneNode(true) : a[i] ] ); - //alert( fn ); } }); }, @@ -700,438 +696,117 @@ jQuery.fn = jQuery.prototype = { } return this; - }, - - extend: function(obj,prop) { - if ( !prop ) { prop = obj; obj = this; } - for ( var i in prop ) obj[i] = prop[i]; - return obj; } }; -jQuery.extend = jQuery.fn.extend; - -new function() { - var b = navigator.userAgent.toLowerCase(); - - // Figure out what browser is being used - jQuery.browser = { - safari: /webkit/.test(b), - opera: /opera/.test(b), - msie: /msie/.test(b) && !/opera/.test(b), - mozilla: /mozilla/.test(b) && !/compatible/.test(b) - }; - - // Check to see if the W3C box model is being used - jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat"; - - var axis = { - /** - * Get a set of elements containing the unique parents of the matched - * set of elements. - * - * @example $("p").parent() - * @before

Hello

Hello

- * @result [

Hello

Hello

] - * - * @name parent - * @type jQuery - */ - - /** - * Get a set of elements containing the unique parents of the matched - * set of elements, and filtered by an expression. - * - * @example $("p").parent(".selected") - * @before

Hello

Hello Again

- * @result [

Hello Again

] - * - * @name parent - * @type jQuery - * @param String expr An expression to filter the parents with - */ - parent: "a.parentNode", - - /** - * Get a set of elements containing the unique ancestors of the matched - * set of elements. - * - * @example $("span").ancestors() - * @before

Hello

Hello Again
- * @result [ ...,
...
,

Hello

] - * - * @name ancestors - * @type jQuery - */ +/** + * + * + * @private + * @name extend + * @param Object obj + * @param Object prop + * @type Object + */ + +/** + * Extend one object with another, returning the original, + * modified, object. This is a great utility for simple inheritance. + * + * @name $.extend + * @param Object obj The object to extend + * @param Object prop The object that will be merged into the first. + * @type Object + */ +jQuery.extend = jQuery.fn.extend = function(obj,prop) { + if ( !prop ) { prop = obj; obj = this; } + for ( var i in prop ) obj[i] = prop[i]; + return obj; +}; - /** - * Get a set of elements containing the unique ancestors of the matched - * set of elements, and filtered by an expression. - * - * @example $("span").ancestors("p") - * @before

Hello

Hello Again
- * @result [

Hello

] - * - * @name ancestors - * @type jQuery - * @param String expr An expression to filter the ancestors with - */ - ancestors: jQuery.parents, +jQuery.extend({ + /** + * + * + * @private + * @name init + * @type undefined + */ + init: function(){ + jQuery.initDone = true; - /** - * A synonym for ancestors - */ - parents: jQuery.parents, - - /** - * Get a set of elements containing the unique next siblings of each of the - * matched set of elements. - * - * It only returns the very next sibling, not all next siblings. - * - * @example $("p").next() - * @before

Hello

Hello Again

And Again
- * @result [

Hello Again

,
And Again
] - * - * @name next - * @type jQuery - */ - - /** - * Get a set of elements containing the unique next siblings of each of the - * matched set of elements, and filtered by an expression. - * - * It only returns the very next sibling, not all next siblings. - * - * @example $("p").next(".selected") - * @before

Hello

Hello Again

And Again
- * @result [

Hello Again

] - * - * @name next - * @type jQuery - * @param String expr An expression to filter the next Elements with - */ - next: "jQuery.sibling(a).next", - - /** - * Get a set of elements containing the unique previous siblings of each of the - * matched set of elements. - * - * It only returns the immediately previous sibling, not all previous siblings. - * - * @example $("p").previous() - * @before

Hello

Hello Again

And Again

- * @result [
Hello Again
] - * - * @name prev - * @type jQuery - */ - - /** - * Get a set of elements containing the unique previous siblings of each of the - * matched set of elements, and filtered by an expression. - * - * It only returns the immediately previous sibling, not all previous siblings. - * - * @example $("p").previous("selected") - * @before
Hello

Hello Again

And Again

- * @result [
Hello
] - * - * @name prev - * @type jQuery - * @param String expr An expression to filter the previous Elements with - */ - prev: "jQuery.sibling(a).prev", - - /** - * Get a set of elements containing all of the unique siblings of each of the - * matched set of elements. - * - * @example $("div").siblings() - * @before

Hello

Hello Again

And Again

- * @result [

Hello

,

And Again

] - * - * @name siblings - * @type jQuery - */ - - /** - * Get a set of elements containing all of the unique siblings of each of the - * matched set of elements, and filtered by an expression. - * - * @example $("div").siblings("selected") - * @before
Hello

Hello Again

And Again

- * @result [

Hello Again

] - * - * @name siblings - * @type jQuery - * @param String expr An expression to filter the sibling Elements with - */ - siblings: jQuery.sibling - }; + jQuery.each( jQuery.macros.axis, function(i,n){ + jQuery.fn[ i ] = function(a) { + var ret = jQuery.map(this,n); + if ( a && a.constructor == String ) + ret = jQuery.filter(a,ret).r; + return this.pushStack( ret, arguments ); + }; + }); + + jQuery.each( jQuery.macros.to, function(i,n){ + jQuery.fn[ i ] = function(){ + var a = arguments; + return this.each(function(){ + for ( var j = 0; j < a.length; j++ ) + $(a[j])[n]( this ); + }); + }; + }); + + jQuery.each( jQuery.macros.each, function(i,n){ + jQuery.fn[ i ] = function() { + return this.each( n, arguments ); + }; + }); + + jQuery.each( jQuery.macros.attr, function(i,n){ + n = n || i; + jQuery.fn[ i ] = function(h) { + return h == undefined ? + this.length ? this[0][n] : null : + this.attr( n, h ); + }; + }); - for ( var i in axis ) new function(){ - var t = axis[i]; - jQuery.fn[ i ] = function(a) { - var ret = jQuery.map(this,t); - if ( a && a.constructor == String ) - ret = jQuery.filter(a,ret).r; - return this.pushStack( ret, arguments ); - }; - }; - - // appendTo, prependTo, beforeTo, afterTo + jQuery.each( jQuery.macros.css, function(i,n){ + jQuery.fn[ i ] = function(h) { + return h == undefined ? + ( this.length ? jQuery.css( this[0], n ) : null ) : + this.css( n, h ); + }; + }); - var to = ["append","prepend","before","after"]; + }, - for ( var i = 0; i < to.length; i++ ) new function(){ - var n = to[i]; - jQuery.fn[ n + "To" ] = function(){ - var a = arguments; - return this.each(function(){ - for ( var i = 0; i < a.length; i++ ) - $(a[i])[n]( this ); - }); - }; - }; + /** + * A generic iterator function, which can be used to seemlessly + * iterate over both objects and arrays. + * + * @name $.each + * @param Object obj The object, or array, to iterate over. + * @param Object fn The function that will be executed on every object. + * @type Object + */ + each: function( obj, fn, args ) { + if ( obj.length == undefined ) + for ( var i in obj ) + fn.apply( obj[i], args || [i, obj[i]] ); + else + for ( var i = 0; i < obj.length; i++ ) + fn.apply( obj[i], args || [i, obj[i]] ); + return obj; + }, - var each = { - /** - * Displays each of the set of matched elements if they are hidden. - * - * @example $("p").show() - * @before

Hello

- * @result [

Hello

] - * - * @name show - * @type jQuery - */ - show: function(){ - this.style.display = this.oldblock ? this.oldblock : ""; - if ( jQuery.css(this,"display") == "none" ) - this.style.display = "block"; - }, - - /** - * Hides each of the set of matched elements if they are shown. - * - * @example $("p").hide() - * @before

Hello

- * @result [

Hello

] - * - * @name hide - * @type jQuery - */ - hide: function(){ - this.oldblock = jQuery.css(this,"display"); - if ( this.oldblock == "none" ) - this.oldblock = "block"; - this.style.display = "none"; + className: { + add: function(o,c){ + if (jQuery.className.has(o,c)) return; + o.className += ( o.className ? " " : "" ) + c; }, - - /** - * 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 - */ - toggle: function(){ - var d = jQuery.css(this,"display"); - $(this)[ !d || d == "none" ? "show" : "hide" ](); - }, - - /** - * Adds the specified class to each of the set of matched elements. - * - * @example ("p").addClass("selected") - * @before

Hello

- * @result [

Hello

] - * - * @name addClass - * @type jQuery - * @param String class A CSS class to add to the elements - */ - addClass: function(c){ - jQuery.className.add(this,c); - }, - - /** - * The opposite of addClass. Removes the specified class from the - * set of matched elements. - * - * @example ("p").removeClass("selected") - * @before

Hello

- * @result [

Hello

] - * - * @name removeClass - * @type jQuery - * @param String class A CSS class to remove from the elements - */ - removeClass: function(c){ - jQuery.className.remove(this,c); - }, - - /** - * Adds the specified class if it is present. Remove it if it is - * not present. - * - * @example ("p").toggleClass("selected") - * @before

Hello

Hello Again

- * @result [

Hello

,

Hello Again

] - * - * @name toggleClass - * @type jQuery - * @param String class A CSS class with which to toggle the elements - */ - toggleClass: function( c ){ - jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c); - }, - - /** - * TODO: Document - */ - remove: function(a){ - if ( !a || jQuery.filter( [this], a ).r ) - this.parentNode.removeChild( this ); - }, - - /** - * Removes all child nodes from the set of matched elements. - * - * @example ("p").empty() - * @before

Hello, Person and person

- * @result [

] - * - * @name empty - * @type jQuery - */ - empty: function(){ - while ( this.firstChild ) - this.removeChild( this.firstChild ); - }, - - /** - * Binds a particular event (like click) to a each of a set of match elements. - * - * @example $("p").bind( "click", function() { alert("Hello"); } ) - * @before

Hello

- * @result [

Hello

] - * - * Cancel a default action and prevent it from bubbling by returning false - * from your function. - * - * @example $("form").bind( "submit", function() { return false; } ) - * - * Cancel a default action by using the preventDefault method. - * - * @example $("form").bind( "submit", function() { e.preventDefault(); } ) - * - * Stop an event from bubbling by using the stopPropogation method. - * - * @example $("form").bind( "submit", function() { e.stopPropogation(); } ) - * - * @name bind - * @type jQuery - * @param String type An event type - * @param Function fn A function to bind to the event on each of the set of matched elements - */ - bind: function( type, fn ) { - if ( fn.constructor == String ) - fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn); - jQuery.event.add( this, type, fn ); - }, - - /** - * The opposite of bind. Removes a bound event from each of a set of matched - * elements. You must pass the identical function that was used in the original - * bind method. - * - * @example $("p").unbind( "click", function() { alert("Hello"); } ) - * @before

Hello

- * @result [

Hello

] - * - * @name unbind - * @type jQuery - * @param String type An event type - * @param Function fn A function to unbind from the event on each of the set of matched elements - */ - unbind: function( type, fn ) { - jQuery.event.remove( this, type, fn ); - }, - - /** - * Trigger a particular event. - * - * @example $("p").trigger("click") - * @before

Hello

- * @result [

Hello

] - * - * @name trigger - * @type jQuery - * @param String type An event type - */ - trigger: function( type ) { - jQuery.event.trigger( this, type ); - } - }; - - for ( var i in each ) new function() { - var n = each[i]; - jQuery.fn[ i ] = function() { - return this.each( n, arguments ); - }; - }; - - var attr = { - val: "value", - html: "innerHTML", - value: null, - id: null, - title: null, - name: null, - href: null, - src: null, - rel: null - }; - - for ( var i in attr ) new function() { - var n = attr[i] || i; - jQuery.fn[ i ] = function(h) { - return h == undefined ? - this.length ? this[0][n] : null : - this.attr( n, h ); - }; - } - - var css = "width,height,top,left,position,float,overflow,color,background".split(","); - - for ( var i in css ) new function() { - var n = css[i]; - jQuery.fn[ i ] = function(h) { - return h == undefined ? - this.length ? jQuery.css( this[0], n ) : null : - this.css( n, h ); - }; - } - -} - -jQuery.extend({ - className: { - add: function(o,c){ - if (jQuery.className.has(o,c)) return; - o.className += ( o.className ? " " : "" ) + c; - }, - remove: function(o,c){ - o.className = !c ? "" : - o.className.replace( - new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), ""); + remove: function(o,c){ + o.className = !c ? "" : + o.className.replace( + new RegExp("(^|\\s*\\b[^-])"+c+"($|\\b(?=[^-]))", "g"), ""); }, has: function(e,a) { if ( e.className ) @@ -1176,19 +851,21 @@ jQuery.extend({ }); return p == "height" ? oHeight : oWidth; - } + } else if ( p == "opacity" && jQuery.browser.msie ) + return parseFloat( jQuery.curCSS(e,"filter").replace(/[^0-9.]/,"") ) || 1; return jQuery.curCSS( e, p ); }, - curCSS: function(e,p) { + curCSS: function(e,p,force) { var r; - if (e.style[p]) + if (!force && e.style[p]) r = e.style[p]; - else if (e.currentStyle) + else if (e.currentStyle) { + p = p.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()}); r = e.currentStyle[p]; - else if (document.defaultView && document.defaultView.getComputedStyle) { + } else if (document.defaultView && document.defaultView.getComputedStyle) { p = p.replace(/([A-Z])/g,"-$1").toLowerCase(); var s = document.defaultView.getComputedStyle(e,""); r = s ? s.getPropertyValue(p) : null; @@ -1292,7 +969,7 @@ jQuery.extend({ find: function( t, context ) { // Make sure that the context is a DOM Element - if ( context && context.getElementsByTagName == undefined ) + if ( context && context.nodeType == undefined ) context = null; // Set the correct context (if none is provided) @@ -1724,6 +1401,8 @@ jQuery.extend({ }, handle: function(event) { + if ( typeof jQuery == "undefined" ) return; + event = event || jQuery.event.fix( window.event ); // If no correct event was found, fail @@ -1760,3 +1439,900 @@ jQuery.extend({ } }); + +new function() { + var b = navigator.userAgent.toLowerCase(); + + // Figure out what browser is being used + jQuery.browser = { + safari: /webkit/.test(b), + opera: /opera/.test(b), + msie: /msie/.test(b) && !/opera/.test(b), + mozilla: /mozilla/.test(b) && !/compatible/.test(b) + }; + + // Check to see if the W3C box model is being used + jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat"; +}; + +jQuery.macros = { + to: { + /** + * Append all of the matched elements to another, specified, set of elements. + * This operation is, essentially, the reverse of doing a regular + * $(A).append(B), in that instead of appending B to A, you're appending + * A to B. + * + * @example $("p").appendTo("#foo"); + * @before

I would like to say:

+ * @result

I would like to say:

+ * + * @name appendTo + * @type jQuery + * @param String expr A jQuery expression of elements to match. + */ + append: "appendTo", + + /** + * Prepend all of the matched elements to another, specified, set of elements. + * This operation is, essentially, the reverse of doing a regular + * $(A).prepend(B), in that instead of prepending B to A, you're prepending + * A to B. + * + * @example $("p").prependTo("#foo"); + * @before

I would like to say:

Hello
+ * @result

I would like to say:

Hello
+ * + * @name prependTo + * @type jQuery + * @param String expr A jQuery expression of elements to match. + */ + prepend: "prependTo", + + /** + * Insert all of the matched elements before another, specified, set of elements. + * This operation is, essentially, the reverse of doing a regular + * $(A).before(B), in that instead of inserting B before A, you're inserting + * A before B. + * + * @example $("p").insertBefore("#foo"); + * @before
Hello

I would like to say:

+ * @result

I would like to say:

Hello
+ * + * @name insertBefore + * @type jQuery + * @param String expr A jQuery expression of elements to match. + */ + before: "insertBefore", + + /** + * Insert all of the matched elements after another, specified, set of elements. + * This operation is, essentially, the reverse of doing a regular + * $(A).after(B), in that instead of inserting B after A, you're inserting + * A after B. + * + * @example $("p").insertAfter("#foo"); + * @before

I would like to say:

Hello
+ * @result
Hello

I would like to say:

+ * + * @name insertAfter + * @type jQuery + * @param String expr A jQuery expression of elements to match. + */ + after: "insertAfter" + }, + + /** + * Get the current CSS width of the first matched element. + * + * @example $("p").width(); + * @before

This is just a test.

+ * @result "300px" + * + * @name width + * @type String + */ + + /** + * Set the CSS width of every matched element. Be sure to include + * the "px" (or other unit of measurement) after the number that you + * specify, otherwise you might get strange results. + * + * @example $("p").width("20px"); + * @before

This is just a test.

+ * @result

This is just a test.

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

This is just a test.

+ * @result "14px" + * + * @name height + * @type String + */ + + /** + * Set the CSS height of every matched element. Be sure to include + * the "px" (or other unit of measurement) after the number that you + * specify, otherwise you might get strange results. + * + * @example $("p").height("20px"); + * @before

This is just a test.

+ * @result

This is just a test.

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

This is just a test.

+ * @result "0px" + * + * @name top + * @type String + */ + + /** + * Set the CSS top of every matched element. Be sure to include + * the "px" (or other unit of measurement) after the number that you + * specify, otherwise you might get strange results. + * + * @example $("p").top("20px"); + * @before

This is just a test.

+ * @result

This is just a test.

+ * + * @name top + * @type jQuery + * @param String val Set the CSS property to the specified value. + */ + + /** + * Get the current CSS left of the first matched element. + * + * @example $("p").left(); + * @before

This is just a test.

+ * @result "0px" + * + * @name left + * @type String + */ + + /** + * Set the CSS left of every matched element. Be sure to include + * the "px" (or other unit of measurement) after the number that you + * specify, otherwise you might get strange results. + * + * @example $("p").left("20px"); + * @before

This is just a test.

+ * @result

This is just a test.

+ * + * @name left + * @type jQuery + * @param String val Set the CSS property to the specified value. + */ + + /** + * Get the current CSS position of the first matched element. + * + * @example $("p").position(); + * @before

This is just a test.

+ * @result "static" + * + * @name position + * @type String + */ + + /** + * Set the CSS position of every matched element. + * + * @example $("p").position("relative"); + * @before

This is just a test.

+ * @result

This is just a test.

+ * + * @name position + * @type jQuery + * @param String val Set the CSS property to the specified value. + */ + + /** + * Get the current CSS float of the first matched element. + * + * @example $("p").float(); + * @before

This is just a test.

+ * @result "none" + * + * @name float + * @type String + */ + + /** + * Set the CSS float of every matched element. + * + * @example $("p").float("left"); + * @before

This is just a test.

+ * @result

This is just a test.

+ * + * @name float + * @type jQuery + * @param String val Set the CSS property to the specified value. + */ + + /** + * Get the current CSS overflow of the first matched element. + * + * @example $("p").overflow(); + * @before

This is just a test.

+ * @result "none" + * + * @name overflow + * @type String + */ + + /** + * Set the CSS overflow of every matched element. + * + * @example $("p").overflow("auto"); + * @before

This is just a test.

+ * @result

This is just a test.

+ * + * @name overflow + * @type jQuery + * @param String val Set the CSS property to the specified value. + */ + + /** + * Get the current CSS color of the first matched element. + * + * @example $("p").color(); + * @before

This is just a test.

+ * @result "black" + * + * @name color + * @type String + */ + + /** + * Set the CSS color of every matched element. + * + * @example $("p").color("blue"); + * @before

This is just a test.

+ * @result

This is just a test.

+ * + * @name color + * @type jQuery + * @param String val Set the CSS property to the specified value. + */ + + /** + * Get the current CSS background of the first matched element. + * + * @example $("p").background(); + * @before

This is just a test.

+ * @result "" + * + * @name background + * @type String + */ + + /** + * Set the CSS background of every matched element. + * + * @example $("p").background("blue"); + * @before

This is just a test.

+ * @result

This is just a test.

+ * + * @name background + * @type jQuery + * @param String val Set the CSS property to the specified value. + */ + + css: "width,height,top,left,position,float,overflow,color,background".split(","), + + attr: { + /** + * Get the current value of the first matched element. + * + * @example $("input").val(); + * @before + * @result "some text" + * + * @name val + * @type String + */ + + /** + * Set the value of every matched element. + * + * @example $("input").value("test"); + * @before + * @result + * + * @name val + * @type jQuery + * @param String val Set the property to the specified value. + */ + val: "value", + + /** + * Get the html contents of the first matched element. + * + * @example $("div").html(); + * @before
+ * @result + * + * @name html + * @type String + */ + + /** + * Set the html contents of every matched element. + * + * @example $("div").html("new stuff"); + * @before
+ * @result
new stuff + * + * @name html + * @type jQuery + * @param String val Set the html contents to the specified value. + */ + html: "innerHTML", + + /** + * Get the current id of the first matched element. + * + * @example $("input").id(); + * @before + * @result "test" + * + * @name id + * @type String + */ + + /** + * Set the id of every matched element. + * + * @example $("input").id("newid"); + * @before + * @result + * + * @name id + * @type jQuery + * @param String val Set the property to the specified value. + */ + id: null, + + /** + * Get the current title of the first matched element. + * + * @example $("img").title(); + * @before + * @result "my image" + * + * @name title + * @type String + */ + + /** + * Set the title of every matched element. + * + * @example $("img").title("new title"); + * @before + * @result + * + * @name title + * @type jQuery + * @param String val Set the property to the specified value. + */ + title: null, + + /** + * Get the current name of the first matched element. + * + * @example $("input").name(); + * @before + * @result "username" + * + * @name name + * @type String + */ + + /** + * Set the name of every matched element. + * + * @example $("input").name("user"); + * @before + * @result + * + * @name name + * @type jQuery + * @param String val Set the property to the specified value. + */ + name: null, + + /** + * Get the current href of the first matched element. + * + * @example $("a").href(); + * @before my link + * @result "test.html" + * + * @name href + * @type String + */ + + /** + * Set the href of every matched element. + * + * @example $("a").href("test2.html"); + * @before my link + * @result my link + * + * @name href + * @type jQuery + * @param String val Set the property to the specified value. + */ + href: null, + + /** + * Get the current src of the first matched element. + * + * @example $("img").src(); + * @before + * @result "test.jpg" + * + * @name src + * @type String + */ + + /** + * Set the src of every matched element. + * + * @example $("img").src("test2.jpg"); + * @before + * @result + * + * @name src + * @type jQuery + * @param String val Set the property to the specified value. + */ + src: null, + + /** + * Get the current rel of the first matched element. + * + * @example $("a").rel(); + * @before my link + * @result "nofollow" + * + * @name rel + * @type String + */ + + /** + * Set the rel of every matched element. + * + * @example $("a").rel("nofollow"); + * @before my link + * @result my link + * + * @name rel + * @type jQuery + * @param String val Set the property to the specified value. + */ + rel: null + }, + + axis: { + /** + * Get a set of elements containing the unique parents of the matched + * set of elements. + * + * @example $("p").parent() + * @before

Hello

Hello

+ * @result [

Hello

Hello

] + * + * @name parent + * @type jQuery + */ + + /** + * Get a set of elements containing the unique parents of the matched + * set of elements, and filtered by an expression. + * + * @example $("p").parent(".selected") + * @before

Hello

Hello Again

+ * @result [

Hello Again

] + * + * @name parent + * @type jQuery + * @param String expr An expression to filter the parents with + */ + parent: "a.parentNode", + + /** + * Get a set of elements containing the unique ancestors of the matched + * set of elements. + * + * @example $("span").ancestors() + * @before

Hello

Hello Again
+ * @result [ ...,
...
,

Hello

] + * + * @name ancestors + * @type jQuery + */ + + /** + * Get a set of elements containing the unique ancestors of the matched + * set of elements, and filtered by an expression. + * + * @example $("span").ancestors("p") + * @before

Hello

Hello Again
+ * @result [

Hello

] + * + * @name ancestors + * @type jQuery + * @param String expr An expression to filter the ancestors with + */ + ancestors: jQuery.parents, + + /** + * Get a set of elements containing the unique ancestors of the matched + * set of elements. + * + * @example $("span").ancestors() + * @before

Hello

Hello Again
+ * @result [ ...,
...
,

Hello

] + * + * @name parents + * @type jQuery + */ + + /** + * Get a set of elements containing the unique ancestors of the matched + * set of elements, and filtered by an expression. + * + * @example $("span").ancestors("p") + * @before

Hello

Hello Again
+ * @result [

Hello

] + * + * @name parents + * @type jQuery + * @param String expr An expression to filter the ancestors with + */ + parents: jQuery.parents, + + /** + * Get a set of elements containing the unique next siblings of each of the + * matched set of elements. + * + * It only returns the very next sibling, not all next siblings. + * + * @example $("p").next() + * @before

Hello

Hello Again

And Again
+ * @result [

Hello Again

,
And Again
] + * + * @name next + * @type jQuery + */ + + /** + * Get a set of elements containing the unique next siblings of each of the + * matched set of elements, and filtered by an expression. + * + * It only returns the very next sibling, not all next siblings. + * + * @example $("p").next(".selected") + * @before

Hello

Hello Again

And Again
+ * @result [

Hello Again

] + * + * @name next + * @type jQuery + * @param String expr An expression to filter the next Elements with + */ + next: "jQuery.sibling(a).next", + + /** + * Get a set of elements containing the unique previous siblings of each of the + * matched set of elements. + * + * It only returns the immediately previous sibling, not all previous siblings. + * + * @example $("p").previous() + * @before

Hello

Hello Again

And Again

+ * @result [
Hello Again
] + * + * @name prev + * @type jQuery + */ + + /** + * Get a set of elements containing the unique previous siblings of each of the + * matched set of elements, and filtered by an expression. + * + * It only returns the immediately previous sibling, not all previous siblings. + * + * @example $("p").previous(".selected") + * @before
Hello

Hello Again

And Again

+ * @result [
Hello
] + * + * @name prev + * @type jQuery + * @param String expr An expression to filter the previous Elements with + */ + prev: "jQuery.sibling(a).prev", + + /** + * Get a set of elements containing all of the unique siblings of each of the + * matched set of elements. + * + * @example $("div").siblings() + * @before

Hello

Hello Again

And Again

+ * @result [

Hello

,

And Again

] + * + * @name siblings + * @type jQuery + */ + + /** + * Get a set of elements containing all of the unique siblings of each of the + * matched set of elements, and filtered by an expression. + * + * @example $("div").siblings(".selected") + * @before
Hello

Hello Again

And Again

+ * @result [

Hello Again

] + * + * @name siblings + * @type jQuery + * @param String expr An expression to filter the sibling Elements with + */ + siblings: jQuery.sibling, + + + /** + * Get a set of elements containing all of the unique children of each of the + * matched set of elements. + * + * @example $("div").children() + * @before

Hello

Hello Again

And Again

+ * @result [ Hello Again ] + * + * @name children + * @type jQuery + */ + + /** + * Get a set of elements containing all of the unique siblings of each of the + * matched set of elements, and filtered by an expression. + * + * @example $("div").children(".selected") + * @before
Hello

Hello Again

And Again

+ * @result [

Hello Again

] + * + * @name children + * @type jQuery + * @param String expr An expression to filter the child Elements with + */ + children: "a.childNodes" + }, + + each: { + /** + * Displays each of the set of matched elements if they are hidden. + * + * @example $("p").show() + * @before

Hello

+ * @result [

Hello

] + * + * @name show + * @type jQuery + */ + _show: function(){ + this.style.display = this.oldblock ? this.oldblock : ""; + if ( jQuery.css(this,"display") == "none" ) + this.style.display = "block"; + }, + + /** + * Hides each of the set of matched elements if they are shown. + * + * @example $("p").hide() + * @before

Hello

+ * @result [

Hello

] + * + * @name hide + * @type jQuery + */ + _hide: function(){ + this.oldblock = this.oldblock || jQuery.css(this,"display"); + if ( this.oldblock == "none" ) + this.oldblock = "block"; + this.style.display = "none"; + }, + + /** + * 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 + */ + _toggle: function(){ + var d = jQuery.css(this,"display"); + $(this)[ !d || d == "none" ? "show" : "hide" ](); + }, + + /** + * Adds the specified class to each of the set of matched elements. + * + * @example ("p").addClass("selected") + * @before

Hello

+ * @result [

Hello

] + * + * @name addClass + * @type jQuery + * @param String class A CSS class to add to the elements + */ + addClass: function(c){ + jQuery.className.add(this,c); + }, + + /** + * The opposite of addClass. Removes the specified class from the + * set of matched elements. + * + * @example ("p").removeClass("selected") + * @before

Hello

+ * @result [

Hello

] + * + * @name removeClass + * @type jQuery + * @param String class A CSS class to remove from the elements + */ + removeClass: function(c){ + jQuery.className.remove(this,c); + }, + + /** + * Adds the specified class if it is present. Remove it if it is + * not present. + * + * @example ("p").toggleClass("selected") + * @before

Hello

Hello Again

+ * @result [

Hello

,

Hello Again

] + * + * @name toggleClass + * @type jQuery + * @param String class A CSS class with which to toggle the elements + */ + toggleClass: function( c ){ + jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c); + }, + + /** + * TODO: Document + */ + remove: function(a){ + if ( !a || jQuery.filter( [this], a ).r ) + this.parentNode.removeChild( this ); + }, + + /** + * Removes all child nodes from the set of matched elements. + * + * @example ("p").empty() + * @before

Hello, Person and person

+ * @result [

] + * + * @name empty + * @type jQuery + */ + empty: function(){ + while ( this.firstChild ) + this.removeChild( this.firstChild ); + }, + + /** + * Binds a particular event (like click) to a each of a set of match elements. + * + * @example $("p").bind( "click", function() { alert("Hello"); } ) + * @before

Hello

+ * @result [

Hello

] + * + * Cancel a default action and prevent it from bubbling by returning false + * from your function. + * + * @example $("form").bind( "submit", function() { return false; } ) + * + * Cancel a default action by using the preventDefault method. + * + * @example $("form").bind( "submit", function() { e.preventDefault(); } ) + * + * Stop an event from bubbling by using the stopPropogation method. + * + * @example $("form").bind( "submit", function() { e.stopPropogation(); } ) + * + * @name bind + * @type jQuery + * @param String type An event type + * @param Function fn A function to bind to the event on each of the set of matched elements + */ + bind: function( type, fn ) { + if ( fn.constructor == String ) + fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn); + jQuery.event.add( this, type, fn ); + }, + + /** + * The opposite of bind, removes a bound event from each of the matched + * elements. You must pass the identical function that was used in the original + * bind method. + * + * @example $("p").unbind( "click", function() { alert("Hello"); } ) + * @before

Hello

+ * @result [

Hello

] + * + * @name unbind + * @type jQuery + * @param String type An event type + * @param Function fn A function to unbind from the event on each of the set of matched elements + */ + + /** + * Removes all bound events of a particular type from each of the matched + * elements. + * + * @example $("p").unbind( "click" ) + * @before

Hello

+ * @result [

Hello

] + * + * @name unbind + * @type jQuery + * @param String type An event type + */ + + /** + * Removes all bound events from each of the matched elements. + * + * @example $("p").unbind() + * @before

Hello

+ * @result [

Hello

] + * + * @name unbind + * @type jQuery + */ + unbind: function( type, fn ) { + jQuery.event.remove( this, type, fn ); + }, + + /** + * Trigger a type of event on every matched element. + * + * @example $("p").trigger("click") + * @before

Hello

+ * @result alert('hello') + * + * @name trigger + * @type jQuery + * @param String type An event type to trigger. + */ + trigger: function( type, data ) { + jQuery.event.trigger( type, data, this ); + } + } +};