X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=1d96eacf61990c6ffb75fe5dac0022e651d1c778;hb=6850c4b29017bcb31e16f0d6c94110a8b8a82304;hp=e58f895df21d94f54b2dc5cbfe92120c5f5dfde4;hpb=495ecb70b2b097e7d4a1ffe46d44562210cdc051;p=jquery.git
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index e58f895..1d96eac 100644
--- a/src/jquery/jquery.js
+++ b/src/jquery/jquery.js
@@ -76,8 +76,12 @@ var $ = jQuery;
* (usually consisting of CSS or XPath), which then finds all matching
* elements.
*
- * By default, $() looks for DOM elements within the context of the
- * current HTML document.
+ * By default, if no context is specified, $() looks for DOM elements within the context of the
+ * current HTML document. If you do specify a context, such as a DOM
+ * element or jQuery object, the expression will be matched against
+ * the contents of that context.
+ *
+ * See [[DOM/Traversing/Selectors]] for the allowed CSS/XPath syntax for expressions.
*
* @example $("div > p")
* @desc Finds all p elements that are children of a div element.
@@ -102,10 +106,10 @@ var $ = jQuery;
/**
* Create DOM elements on-the-fly from the provided String of raw HTML.
*
- * @example $("
Hello
").appendTo("#body")
+ * @example $("
Hello
").appendTo("body")
* @desc Creates a div element (and all of its contents) dynamically,
- * and appends it to the element with the ID of body. Internally, an
- * element is created and it's innerHTML property set to the given markup.
+ * and appends it to the body element. Internally, an
+ * element is created and its innerHTML property set to the given markup.
* It is therefore both quite flexible and limited.
*
* @name $
@@ -121,7 +125,7 @@ var $ = jQuery;
* This function also accepts XML Documents and Window objects
* as valid arguments (even though they are not DOM Elements).
*
- * @example $(document.body).background( "black" );
+ * @example $(document.body).css( "background", "black" );
* @desc Sets the background color of the page to black.
*
* @example $( myForm.elements ).hide()
@@ -137,8 +141,10 @@ var $ = jQuery;
* A shorthand for $(document).ready(), allowing you to bind a function
* to be executed when the DOM document has finished loading. This function
* behaves just like $(document).ready(), in that it should be used to wrap
- * all of the other $() operations on your page. While this function is,
- * technically, chainable - there really isn't much use for chaining against it.
+ * other $() operations on your page that depend on the DOM being ready to be
+ * operated on. While this function is, technically, chainable - there really
+ * isn't much use for chaining against it.
+ *
* You can have as many $(document).ready events on your page as you like.
*
* See ready(Function) for details about the ready event.
@@ -175,7 +181,7 @@ jQuery.fn = jQuery.prototype = {
jquery: "@VERSION",
/**
- * The number of elements currently matched.
+ * The number of elements currently matched. The size function will return the same value.
*
* @example $("img").length;
* @before
@@ -188,7 +194,8 @@ jQuery.fn = jQuery.prototype = {
*/
/**
- * The number of elements currently matched.
+ * Get the number of elements currently matched. This returns the same
+ * number as the 'length' property of the jQuery object.
*
* @example $("img").size();
* @before
@@ -205,10 +212,12 @@ jQuery.fn = jQuery.prototype = {
length: 0,
/**
- * Access all matched elements. This serves as a backwards-compatible
+ * Access all matched DOM elements. This serves as a backwards-compatible
* way of accessing all matched elements (other than the jQuery object
* itself, which is, in fact, an array of elements).
*
+ * It is useful if you need to operate on the DOM elements themselves instead of using built-in jQuery functions.
+ *
* @example $("img").get();
* @before
* @result [ ]
@@ -220,12 +229,13 @@ jQuery.fn = jQuery.prototype = {
*/
/**
- * Access a single matched element. num is used to access the
- * Nth element matched.
+ * Access a single matched DOM element at a specified index in the matched set.
+ * This allows you to extract the actual DOM element and operate on it
+ * directly without necessarily using jQuery functionality on it.
*
* @example $("img").get(0);
* @before
- * @result [ ]
+ * @result
* @desc Selects all images in the document and returns the first one
*
* @name get
@@ -286,11 +296,11 @@ jQuery.fn = jQuery.prototype = {
* Execute a function within the context of every matched element.
* This means that every time the passed-in function is executed
* (which is once for every element matched) the 'this' keyword
- * points to the specific element.
+ * points to the specific DOM element.
*
* Additionally, the function, when executed, is passed a single
* argument representing the position of the element in the matched
- * set.
+ * set (integer, zero-index).
*
* @example $("img").each(function(i){
* this.src = "test" + i + ".jpg";
@@ -346,6 +356,9 @@ jQuery.fn = jQuery.prototype = {
* This method makes it easy to retrieve a property value
* from the first matched element.
*
+ * If the element does not have an attribute with such a
+ * name, undefined is returned.
+ *
* @example $("img").attr("src");
* @before
* @result test.jpg
@@ -377,8 +390,6 @@ jQuery.fn = jQuery.prototype = {
/**
* Set a single property to a value, on all matched elements.
*
- * Can compute values provided as ${formula}, see second example.
- *
* Note that you can't set the name property of input elements in IE.
* Use $(html) or .append(html) or .html(html) to create elements
* on the fly including the name property.
@@ -388,11 +399,6 @@ jQuery.fn = jQuery.prototype = {
* @result
* @desc Sets src attribute to all images.
*
- * @example $("img").attr("title", "${this.src}");
- * @before
- * @result
- * @desc Sets title attribute from src attribute, a shortcut for attr(String,Function)
- *
* @name attr
* @type jQuery
* @param String key The name of the property to set.
@@ -403,7 +409,9 @@ jQuery.fn = jQuery.prototype = {
/**
* Set a single property to a computed value, on all matched elements.
*
- * Instead of a value, a function is provided, that computes the value.
+ * Instead of supplying a string value as described
+ * [[DOM/Attributes#attr.28_key.2C_value_.29|above]],
+ * a function is provided that computes the value.
*
* @example $("img").attr("title", function() { return this.src });
* @before
@@ -824,7 +832,9 @@ jQuery.fn = jQuery.prototype = {
*/
clone: function(deep) {
return this.pushStack( jQuery.map( this, function(a){
- return a.cloneNode( deep != undefined ? deep : true );
+ var a = a.cloneNode( deep != undefined ? deep : true );
+ a.$events = null; // drop $events expando to avoid firing incorrect events
+ return a;
}) );
},
@@ -1020,7 +1030,14 @@ jQuery.fn = jQuery.prototype = {
},
/**
- * Get the current value of the first matched element.
+ * Get the content of the value attribute of the first matched element.
+ *
+ * Use caution when relying on this function to check the value of
+ * multiple-select elements and checkboxes in a form. While it will
+ * still work as intended, it may not accurately represent the value
+ * the server will receive because these elements may send an array
+ * of values. For more robust handling of field values, see the
+ * [http://www.malsup.com/jquery/form/#fields fieldValue function of the Form Plugin].
*
* @example $("input").val();
* @before
@@ -1032,7 +1049,7 @@ jQuery.fn = jQuery.prototype = {
*/
/**
- * Set the value of every matched element.
+ * Set the value attribute of every matched element.
*
* @example $("input").val("test");
* @before
@@ -1113,7 +1130,7 @@ jQuery.fn = jQuery.prototype = {
/**
* Extends the jQuery object itself. Can be used to add functions into
- * the jQuery namespace and to add plugin methods (plugins).
+ * the jQuery namespace and to [[Plugins/Authoring|add plugin methods]] (plugins).
*
* @example jQuery.fn.extend({
* check: function() {
@@ -1225,7 +1242,7 @@ jQuery.extend({
// This may seem like some crazy code, but trust me when I say that this
// is the only cross-browser way to do this. --John
isFunction: function( fn ) {
- return !!fn && typeof fn != "string" &&
+ return !!fn && typeof fn != "string" && !fn.nodeName &&
typeof fn[0] == "undefined" && /function/i.test( fn + "" );
},
@@ -1280,7 +1297,7 @@ jQuery.extend({
prop: function(elem, value, type, index, prop){
// Handle executable functions
if ( jQuery.isFunction( value ) )
- return value.call( elem, [index] );
+ value = value.call( elem, [index] );
// exclude the following css properties to add px
var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;
@@ -1311,6 +1328,8 @@ jQuery.extend({
// internal only, use is(".class")
has: function( t, c ) {
t = t.className || t;
+ // escape regex characters
+ c = c.replace(/([\.\\\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, "\\$1");
return t && new RegExp("(^|\\s)" + c + "(\\s|$)").test( t );
}
},
@@ -1467,10 +1486,10 @@ jQuery.extend({
arg = div.childNodes;
}
- if ( arg.length === 0 )
+ if ( arg.length === 0 && !jQuery.nodeName(arg, "form") )
return;
- if ( arg[0] == undefined )
+ if ( arg[0] == undefined || jQuery.nodeName(arg, "form") )
r.push( arg );
else
r = jQuery.merge( r, arg );
@@ -1513,7 +1532,6 @@ jQuery.extend({
if ( name == "opacity" && jQuery.browser.mozilla && value == 1 )
value = 0.9999;
- //
// Certain attributes only work when accessed via the old DOM 0 way
if ( fix[name] ) {
@@ -1525,10 +1543,12 @@ jQuery.extend({
// IE elem.getAttribute passes even for style
else if ( elem.tagName ) {
- if ( value != undefined )
- elem.setAttribute( name, value );
+ if ( value != undefined ) elem.setAttribute( name, value );
+ if ( jQuery.browser.msie && /href|src/.test(name) && !jQuery.isXMLDoc(elem) )
+ return elem.getAttribute( name, 2 );
return elem.getAttribute( name );
+ // elem is actually elem.style ... set the style
} else {
name = name.replace(/-([a-z])/ig,function(z,b){return b.toUpperCase();});
if ( value != undefined ) elem[name] = value;