X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=554726e3dfbbc7c86c947def5df11aa156ad3eef;hb=18e330741f7e80aaa38ca700ab8a5884d6e671eb;hp=883bc38549224ea7107b3f1eb50692b2f5091a28;hpb=ef1ee513d314123017fce770e8fe0a9c85b9eb87;p=jquery.git
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index 883bc38..554726e 100644
--- a/src/jquery/jquery.js
+++ b/src/jquery/jquery.js
@@ -22,12 +22,12 @@ window.undefined = window.undefined;
*/
var jQuery = function(a,c) {
- // Shortcut for document ready (because $(document).each() is silly)
+ // Shortcut for document ready
if ( a && typeof a == "function" && jQuery.fn.ready && !a.nodeType && a[0] == undefined ) // Safari reports typeof on DOM NodeLists as a function
return jQuery(document).ready(a);
// Make sure that a selection was provided
- a = a || jQuery.context || document;
+ a = a || document;
// Watch for when a jQuery object is passed as the selector
if ( a.jquery )
@@ -48,7 +48,7 @@ var jQuery = function(a,c) {
}
// Watch for when an array is passed in
- this.get( a.constructor == Array || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType ?
+ this.set( a.constructor == Array || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType ?
// Assume that it is an array of DOM Elements
jQuery.merge( a, [] ) :
@@ -73,17 +73,14 @@ if ( typeof $ != "undefined" )
var $ = 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.
+ * This function accepts a string containing a CSS or
+ * basic XPath selector which is then used to match a set of elements.
*
* 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.
+ * elements.
*
* By default, $() looks for DOM elements within the context of the
* current HTML document.
@@ -93,29 +90,36 @@ var $ = jQuery;
* @before
one
three
* @result [ two
]
*
- * @example $("").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.
- * It is therefore both quite flexible and limited.
+ * @example $("input:radio", document.forms[0])
+ * @desc Searches for all inputs of type radio within the first form in the document
+ *
+ * @example $("div", xml.responseXML)
+ * @desc This finds all div elements within the specified XML document.
*
* @name $
- * @param String expr An expression to search with, or a string of HTML to create on the fly.
+ * @param String expr An expression to search with
+ * @param Element context (optional) A DOM Element, or Document, representing the base context.
* @cat Core
* @type jQuery
+ * @see $(Element)
+ * @see $(Element)
*/
-
+
/**
- * This function accepts a string containing a CSS selector, or
- * basic XPath, which is then used to match a set of elements with the
- * context of the specified DOM element, or document
+ * This function accepts a string of raw HTML.
*
- * @example $("div", xml.responseXML)
- * @desc This finds all div elements within the specified XML document.
+ * 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.
+ *
+ * @example $("").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.
+ * It is therefore both quite flexible and limited.
*
* @name $
- * @param String expr An expression to search with.
- * @param Element context A DOM Element, or Document, representing the base context.
+ * @param String html A string of HTML to create on the fly.
* @cat Core
* @type jQuery
*/
@@ -251,37 +255,34 @@ jQuery.fn = jQuery.prototype = {
* @param Number num Access the element in the Nth position.
* @cat Core
*/
+ get: function( num ) {
+ return num == undefined ?
+ // Return a 'clean' array
+ jQuery.merge( this, [] ) :
+
+ // Return just the object
+ this[num];
+ },
+
/**
* Set the jQuery object to an array of elements.
*
- * @example $("img").get([ document.body ]);
- * @result $("img").get() == [ document.body ]
+ * @example $("img").set([ document.body ]);
+ * @result $("img").set() == [ document.body ]
*
* @private
- * @name get
+ * @name set
* @type jQuery
* @param Elements elems An array of elements
* @cat Core
*/
- get: function( num ) {
- // Watch for when an array (of elements) is passed in
- if ( num && num.constructor == Array ) {
-
- // Use a tricky hack to make the jQuery object
- // look and feel like an array
- this.length = 0;
- [].push.apply( this, num );
-
- return this;
- } else
- return num == undefined ?
-
- // Return a 'clean' array
- jQuery.merge( this, [] ) :
-
- // Return just the object
- this[num];
+ set: function( array ) {
+ // Use a tricky hack to make the jQuery object
+ // look and feel like an array
+ this.length = 0;
+ [].push.apply( this, array );
+ return this;
},
/**
@@ -294,17 +295,12 @@ jQuery.fn = jQuery.prototype = {
* argument representing the position of the element in the matched
* set.
*
- * @example $("img").each(function(){
- * this.src = "test.jpg";
- * });
- * @before
- * @result
- *
* @example $("img").each(function(i){
- * alert( "Image #" + i + " is " + this );
+ * this.src = "test" + i + ".jpg";
* });
* @before
- * @result
+ * @result
+ * @desc Iterates over two images and sets their src property
*
* @name each
* @type jQuery
@@ -378,6 +374,10 @@ jQuery.fn = jQuery.prototype = {
/**
* Set a single property to a value, on all matched elements.
*
+ * 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.
+ *
* @example $("img").attr("src","test.jpg");
* @before
* @result
@@ -390,7 +390,7 @@ jQuery.fn = jQuery.prototype = {
*/
attr: function( key, value, type ) {
// Check to see if we're setting style values
- return key.constructor != String || value != undefined ?
+ return typeof key != "string" || value != undefined ?
this.each(function(){
// See if we're setting a hash of styles
if ( value == undefined )
@@ -773,7 +773,7 @@ jQuery.fn = jQuery.prototype = {
end: function() {
if( !(this.stack && this.stack.length) )
return this;
- return this.get( this.stack.pop() );
+ return this.set( this.stack.pop() );
},
/**
@@ -957,8 +957,8 @@ jQuery.fn = jQuery.prototype = {
/**
* Checks the current selection against an expression and returns true,
- * if the selection fits the given expression. Does return false, if the
- * selection does not fit or the expression is not valid.
+ * if at least one element of the selection fits the given expression.
+ * Does return false, if no element fits or the expression is not valid.
*
* @example $("input[@type='checkbox']").parent().is("form")
* @before
@@ -985,13 +985,11 @@ jQuery.fn = jQuery.prototype = {
},
/**
- *
- *
* @private
* @name domManip
* @param Array args
* @param Boolean table
- * @param Number int
+ * @param Number dir
* @param Function fn The function doing the DOM manipulation.
* @type jQuery
* @cat Core
@@ -1040,15 +1038,15 @@ jQuery.fn = jQuery.prototype = {
if ( !fn ) {
if ( !this.stack ) this.stack = [];
this.stack.push( this.get() );
- this.get( a );
+ this.set( a );
} else {
var old = this.get();
- this.get( a );
+ this.set( a );
if ( fn2 && a.length || !fn2 )
- this.each( fn2 || fn ).get( old );
+ this.each( fn2 || fn ).set( old );
else
- this.get( old ).each( fn );
+ this.set( old ).each( fn );
}
return this;
@@ -1207,6 +1205,7 @@ jQuery.extend({
* @type Object
* @cat Javascript
*/
+ // args is for internal usage only
each: function( obj, fn, args ) {
if ( obj.length == undefined )
for ( var i in obj )
@@ -1310,11 +1309,6 @@ jQuery.extend({
ret = elem.style[prop];
- } else if (elem.currentStyle) {
-
- 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) {
if (prop == "cssFloat" || prop == "styleFloat")
@@ -1329,9 +1323,15 @@ jQuery.extend({
ret = 'none';
else
jQuery.swap(elem, { display: 'block' }, function() {
- ret = document.defaultView.getComputedStyle(this,null).getPropertyValue(prop);
+ var c = document.defaultView.getComputedStyle(this, '');
+ ret = c && c.getPropertyValue(prop) || '';
});
+ } else if (elem.currentStyle) {
+
+ var newProp = prop.replace(/\-(\w)/g,function(m,c){return c.toUpperCase();});
+ ret = elem.currentStyle[prop] || elem.currentStyle[newProp];
+
}
return ret;
@@ -1454,9 +1454,9 @@ jQuery.extend({
context = null;
// Set the correct context (if none is provided)
- context = context || jQuery.context || document;
+ context = context || document;
- if ( t.constructor != String ) return [t];
+ if ( typeof t != "string" ) return [t];
if ( !t.indexOf("//") ) {
context = context.documentElement;
@@ -1645,7 +1645,7 @@ jQuery.extend({
// Otherwise, find the expression to execute
else {
var f = jQuery.expr[m[1]];
- if ( f.constructor != String )
+ if ( typeof f != "string" )
f = jQuery.expr[m[1]][m[2]];
// Build a custom macro to enclose it
@@ -2016,19 +2016,31 @@ jQuery.extend({
* This property is available before the DOM is ready, therefore you can
* use it to add ready events only for certain browsers.
*
- * See
- * jQBrowser plugin for advanced browser detection:
+ * There are situations where object detections is not reliable enough, in that
+ * cases it makes sense to use browser detection. Simply try to avoid both!
+ *
+ * A combination of browser and object detection yields quite reliable results.
*
* @example $.browser.msie
- * @desc returns true if the current useragent is some version of microsoft's internet explorer
+ * @desc Returns true if the current useragent is some version of microsoft's internet explorer
*
* @example if($.browser.safari) { $( function() { alert("this is safari!"); } ); }
* @desc Alerts "this is safari!" only for safari browsers
*
+ * @property
* @name $.browser
* @type Boolean
* @cat Javascript
*/
+
+/*
+ * Wheather the W3C compliant box model is being used.
+ *
+ * @property
+ * @name $.boxModel
+ * @type Boolean
+ * @cat Javascript
+ */
new function() {
var b = navigator.userAgent.toLowerCase();
@@ -2842,6 +2854,7 @@ jQuery.macros = {
* @cat DOM
*/
removeAttr: function( key ) {
+ jQuery.attr( this, key, "" );
this.removeAttribute( key );
},
@@ -2949,7 +2962,7 @@ jQuery.macros = {
* @cat DOM
*/
toggleClass: function( c ){
- jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this,c);
+ jQuery.className[ jQuery.className.has(this,c) ? "remove" : "add" ](this, c);
},
/**