X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=fdb488e98be82faac08b0b7861f84635cb8dab7a;hb=69efa31318238a1af5644da7aa5dc691dc33b376;hp=115ee7f2d70274f81f43ae81829dde825fe089c3;hpb=c0e4280282d03a449caaf87d5a6bfe151a874796;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index 115ee7f..fdb488e 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -26,6 +26,7 @@ window.undefined = window.undefined; * @constructor * @private * @name jQuery + * @cat Core */ function jQuery(a,c) { @@ -38,11 +39,11 @@ function jQuery(a,c) { // Watch for when a jQuery object is passed as the selector if ( a.jquery ) - return $( jQuery.merge( a, [] ) ); + return jQuery( jQuery.merge( a, [] ) ); // Watch for when a jQuery object is passed at the context if ( c && c.jquery ) - return $( c ).find(a); + return jQuery( c ).find(a); // If the context is global, return a new object if ( window == this ) @@ -71,6 +72,108 @@ function jQuery(a,c) { // Map over the $ in case of overwrite if ( typeof $ != "undefined" ) jQuery._$ = $; + +/** + * This function accepts a string containing a CSS selector, + * basic XPath, or raw HTML, which is then used to match a set of elements. + * The HTML string is different from the traditional selectors in that + * it creates the DOM elements representing that HTML string, on the fly, + * to be (assumedly) inserted into the document later. + * + * The core functionality of jQuery centers around this function. + * Everything in jQuery is based upon this, or uses this in some way. + * The most basic use of this function is to pass in an expression + * (usually consisting of CSS or XPath), which then finds all matching + * elements and remembers them for later use. + * + * By default, $() looks for DOM elements within the context of the + * current HTML document. + * + * @example $("div > p") + * @desc This finds all p elements that are children of a div element. + * @before
one
two
three
+ * @result [two
] + * + * @example $("Hello
one
two
three
+ * @result [two
] + * + * @example $(document).ready( loaded ); + * @desc Executes the "loaded" function when the DOM is ready to + * be manipulated. + * + * @name $ + * @param Element elem A DOM element to be encapsulated by a jQuery object. + * @cat Core + * @type jQuery + */ + +/** + * Wrap jQuery functionality around a set of DOM Elements. + * + * @example $( myForm.elements ).hide() + * @desc Hides all the input elements within a form + * + * @name $ + * @param ArrayTest Paragraph.
@@ -400,10 +505,27 @@ jQuery.fn = jQuery.prototype = { * * @name wrap * @type jQuery - * @any String html A string of HTML, that will be created on the fly and wrapped around the target. - * @any Element elem A DOM element that will be wrapped. - * @any ArrayTest Paragraph.
+ * @resultTest Paragraph.
I would like to say:
Hello + * @resultI would like to say: Hello
+ * + * @name append + * @type jQuery + * @param Element elem A DOM element that will be appended. + * @cat DOM/Manipulation + */ + + /** + * Append any number of elements to the inside of all matched elements. + * This operation is similar to doing an appendChild to all the + * specified elements, adding them into the document. + * + * @example $("p").append( $("b") ); + * @beforeI would like to say:
Hello + * @resultI would like to say: Hello
+ * + * @name append + * @type jQuery + * @param ArrayI would like to say:
+ * @resultHelloI would like to say:
+ * + * @name prepend + * @type jQuery + * @param String html A string of HTML, that will be created on the fly and appended to the target. + * @cat DOM/Manipulation + */ + + /** + * Append an element to the inside of all matched elements. + * This operation is the best way to insert an element inside, at the + * beginning, of all the matched element. + * + * @example $("p").prepend( $("#foo")[0] ); + * @beforeI would like to say:
Hello + * @resultHelloI would like to say:
+ * + * @name prepend + * @type jQuery + * @param Element elem A DOM element that will be appended. + * @cat DOM/Manipulation + */ + + /** + * Append any number of elements to the inside of all matched elements. * This operation is the best way to insert a set of elements inside, at the * beginning, of all the matched element. * - * @example $("p").prepend("Hello"); - * @before, how are you?
- * @resultHello, how are you?
+ * @example $("p").prepend( $("b") ); + * @beforeI would like to say:
Hello + * @resultHelloI would like to say:
* * @name prepend * @type jQuery - * @any String html A string of HTML, that will be created on the fly and prepended to the target. - * @any Element elem A DOM element that will be prepended. - * @any Arrayhow are you?
- * @result Hellohow are you?
+ * @beforeI would like to say:
+ * @result HelloI would like to say:
* * @name before * @type jQuery - * @any String html A string of HTML, that will be created on the fly and inserted. - * @any Element elem A DOM element that will beinserted. - * @any ArrayI would like to say:
Hello + * @result HelloI would like to say:
+ * + * @name before + * @type jQuery + * @param Element elem A DOM element that will be appended. + * @cat DOM/Manipulation + */ + + /** + * Insert any number of elements before each of the matched elements. + * + * @example $("p").before( $("b") ); + * @beforeI would like to say:
Hello + * @result HelloI would like to say:
+ * + * @name before + * @type jQuery + * @param ArrayI would like to say:
+ * @resultI would like to say:
Hello + * + * @name after + * @type jQuery + * @param String html A string of HTML, that will be created on the fly and appended to the target. + * @cat DOM/Manipulation + */ + + /** + * Insert an element after each of the matched elements. + * + * @example $("p").after( $("#foo")[0] ); + * @before HelloI would like to say:
+ * @resultI would like to say:
Hello + * + * @name after + * @type jQuery + * @param Element elem A DOM element that will be appended. + * @cat DOM/Manipulation + */ + + /** * Insert any number of elements after each of the matched elements. * - * @example $("p").after("I'm doing fine.
"); - * @beforeHow are you?
- * @resultHow are you?
I'm doing fine.
+ * @example $("p").after( $("b") ); + * @before HelloI would like to say:
+ * @resultI would like to say:
Hello * * @name after * @type jQuery - * @any String html A string of HTML, that will be created on the fly and inserted. - * @any Element elem A DOM element that will beinserted. - * @any Array, how are you?
+ * @result HelloHello, how are you?
+ * + * @name clone + * @type jQuery + * @cat DOM/Manipulation + */ clone: function(deep) { return this.pushStack( jQuery.map( this, function(a){ return a.cloneNode( deep != undefined ? deep : true ); @@ -720,6 +961,7 @@ jQuery.fn = jQuery.prototype = { * @param Number int * @param Function fn The function doing the DOM manipulation. * @type jQuery + * @cat Core */ domManip: function(args, table, dir, fn){ var clone = this.size() > 1; @@ -753,6 +995,7 @@ jQuery.fn = jQuery.prototype = { * @param Array a * @param Array args * @type jQuery + * @cat Core */ pushStack: function(a,args) { var fn = args && args[args.length-1]; @@ -765,7 +1008,7 @@ jQuery.fn = jQuery.prototype = { var old = this.get(); this.get( a ); if ( fn.constructor == Function ) - return this.each( fn ); + this.each( fn ); this.get( old ); } @@ -779,15 +1022,15 @@ jQuery.fn = jQuery.prototype = { * @private * @name extend * @param Object obj - * @param Object prop * @type Object + * @cat Core */ /** * Extend one object with another, returning the original, * modified, object. This is a great utility for simple inheritance. * - * @name jQuery.extend + * @name $.extend * @param Object obj The object to extend * @param Object prop The object that will be merged into the first. * @type Object @@ -804,6 +1047,7 @@ jQuery.extend({ * @private * @name init * @type undefined + * @cat Core */ init: function(){ jQuery.initDone = true; @@ -822,7 +1066,7 @@ jQuery.extend({ var a = arguments; return this.each(function(){ for ( var j = 0; j < a.length; j++ ) - $(a[j])[n]( this ); + jQuery(a[j])[n]( this ); }); }; }); @@ -862,7 +1106,7 @@ jQuery.extend({ * A generic iterator function, which can be used to seemlessly * iterate over both objects and arrays. * - * @name jQuery.each + * @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 @@ -923,13 +1167,20 @@ jQuery.extend({ oHeight = e.offsetHeight; oWidth = e.offsetWidth; } else { - e = $(e.cloneNode(true)).css({ - visibility: "hidden", position: "absolute", display: "block" - }).prependTo("body")[0]; + e = jQuery(e.cloneNode(true)).css({ + visibility: "hidden", position: "absolute", display: "block", right: "0", left: "0" + }).appendTo(e.parentNode)[0]; + + var parPos = jQuery.css(e.parentNode,"position"); + if ( parPos == "" || parPos == "static" ) + e.parentNode.style.position = "relative"; oHeight = e.clientHeight; oWidth = e.clientWidth; + if ( parPos == "" || parPos == "static" ) + e.parentNode.style.position = "static"; + e.parentNode.removeChild(e); } }); @@ -950,7 +1201,7 @@ jQuery.extend({ } else if (elem.currentStyle) { - var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase()}); + var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();}); ret = elem.currentStyle[prop] || elem.currentStyle[newProp]; } else if (document.defaultView && document.defaultView.getComputedStyle) { @@ -1025,6 +1276,7 @@ jQuery.extend({ odd: "i%2", // Child Checks + "nth-child": "jQuery.sibling(a,m[3]).cur", "first-child": "jQuery.sibling(a,0).cur", "last-child": "jQuery.sibling(a,0).last", "only-child": "jQuery.sibling(a).length==1", @@ -1108,7 +1360,7 @@ jQuery.extend({ * @test t( "Adjacent", "p + p", ["ap","en","sap"] ); * @test t( "Comma, Child, and Adjacent", "a + a, code > a", ["groups","anchor1","anchor2"] ); * @test t( "First Child", "p:first-child", ["firstp","sndp"] ); - * @test t( "Attribute Exists", "a[@title]", ["google"] ); + * @test t( "Attribute Exists", "a[@title]", ["google"] ); * @test t( "Attribute Exists", "*[@title]", ["google"] ); * @test t( "Attribute Exists", "[@title]", ["google"] ); * @test t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] ); @@ -1160,8 +1412,10 @@ jQuery.extend({ * @test t( "Is Visible", "input:visible", ["text1","text2","radio1","radio2","check1","check2"] ); * @test t( "Is Hidden", "input:hidden", ["hidden1","hidden2"] ); * - * @name jQuery.find + * @name $.find + * @type ArrayThis is just a test.
- * @result "" + * @beforeThis is just a test.
+ * @result "blue" * * @name background * @type String @@ -1958,6 +2220,64 @@ jQuery.macros = { */ css: "width,height,top,left,position,float,overflow,color,background".split(","), + + /** + * Reduce the set of matched elements to a single element. + * The position of the element in the set of matched elements + * starts at 0 and goes to length - 1. + * + * @example $("p").eq(1) + * @beforeThis is just a test.
So is this
+ * @result [So is this
] + * + * @name eq + * @type jQuery + * @param Number pos The index of the element that you wish to limit to. + * @cat Core + */ + + /** + * Reduce the set of matched elements to all elements before a given position. + * The position of the element in the set of matched elements + * starts at 0 and goes to length - 1. + * + * @example $("p").lt(1) + * @beforeThis is just a test.
So is this
+ * @result [This is just a test.
] + * + * @name lt + * @type jQuery + * @param Number pos Reduce the set to all elements below this position. + * @cat Core + */ + + /** + * Reduce the set of matched elements to all elements after a given position. + * The position of the element in the set of matched elements + * starts at 0 and goes to length - 1. + * + * @example $("p").gt(0) + * @beforeThis is just a test.
So is this
+ * @result [So is this
] + * + * @name gt + * @type jQuery + * @param Number pos Reduce the set to all elements after this position. + * @cat Core + */ + + /** + * Filter the set of elements to those that contain the specified text. + * + * @example $("p").contains("test") + * @beforeThis is just a test.
So is this
+ * @result [This is just a test.
] + * + * @name contains + * @type jQuery + * @param String str The string that will be contained within the text of an element. + * @cat DOM/Traversing + */ filter: [ "eq", "lt", "gt", "contains" ], @@ -2383,11 +2703,23 @@ jQuery.macros = { * @param String expr An expression to filter the child Elements with * @cat DOM/Traversing */ - children: "a.childNodes" + children: "jQuery.sibling(a.firstChild)" }, each: { + /** + * Remove an attribute from each of the matched elements. + * + * @example $("input").removeAttr("disabled") + * @before + * @result + * + * @name removeAttr + * @type jQuery + * @param String name The name of the attribute to remove. + * @cat DOM + */ removeAttr: function( key ) { this.removeAttribute( key ); }, @@ -2453,7 +2785,7 @@ jQuery.macros = { * @cat Effects */ toggle: function(){ - $(this)[ $(this).is(":hidden") ? "show" : "hide" ].apply( $(this), arguments ); + jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ].apply( jQuery(this), arguments ); }, /** @@ -2549,7 +2881,7 @@ jQuery.macros = { * @cat DOM/Manipulation */ remove: function(a){ - if ( !a || jQuery.filter( [this], a ).r ) + if ( !a || jQuery.filter( a, [this] ).r ) this.parentNode.removeChild( this ); }, @@ -2597,7 +2929,7 @@ jQuery.macros = { */ bind: function( type, fn ) { if ( fn.constructor == String ) - fn = new Function("e", ( !fn.indexOf(".") ? "$(this)" : "return " ) + fn); + fn = new Function("e", ( !fn.indexOf(".") ? "jQuery(this)" : "return " ) + fn); jQuery.event.add( this, type, fn ); },