X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=554726e3dfbbc7c86c947def5df11aa156ad3eef;hb=18e330741f7e80aaa38ca700ab8a5884d6e671eb;hp=1efda2126f50fcb85c8ee0a5bbe2d595cc7ed984;hpb=94e59e287a9fde9425cd96713e8130aef06bc431;p=jquery.git
diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js
index 1efda21..554726e 100644
--- a/src/jquery/jquery.js
+++ b/src/jquery/jquery.js
@@ -22,7 +22,7 @@ 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);
@@ -55,6 +55,13 @@ var jQuery = function(a,c) {
// Find the matching elements and save them for later
jQuery.find( a, c ) );
+ // See if an extra function was provided
+ var fn = arguments[ arguments.length - 1 ];
+
+ // If so, execute it in context
+ if ( fn && typeof fn == "function" )
+ this.each(fn);
+
return this;
};
@@ -367,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
@@ -379,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 )
@@ -785,7 +796,7 @@ jQuery.fn = jQuery.prototype = {
find: function(t) {
return this.pushStack( jQuery.map( this, function(a){
return jQuery.find(t,a);
- }));
+ }), arguments );
},
/**
@@ -806,7 +817,7 @@ jQuery.fn = jQuery.prototype = {
clone: function(deep) {
return this.pushStack( jQuery.map( this, function(a){
return a.cloneNode( deep != undefined ? deep : true );
- }));
+ }), arguments );
},
/**
@@ -861,7 +872,7 @@ jQuery.fn = jQuery.prototype = {
typeof t == "function" &&
jQuery.grep( this, t ) ||
- jQuery.filter(t,this).r );
+ jQuery.filter(t,this).r, arguments );
},
/**
@@ -895,7 +906,7 @@ jQuery.fn = jQuery.prototype = {
not: function(t) {
return this.pushStack( typeof t == "string" ?
jQuery.filter(t,this,false).r :
- jQuery.grep(this,function(a){ return a != t; }) );
+ jQuery.grep(this,function(a){ return a != t; }), arguments );
},
/**
@@ -941,7 +952,7 @@ jQuery.fn = jQuery.prototype = {
*/
add: function(t) {
return this.pushStack( jQuery.merge( this, typeof t == "string" ?
- jQuery.find(t) : t.constructor == Array ? t : [t] ) );
+ jQuery.find(t) : t.constructor == Array ? t : [t] ), arguments );
},
/**
@@ -1017,11 +1028,28 @@ jQuery.fn = jQuery.prototype = {
* @type jQuery
* @cat Core
*/
- pushStack: function(a) {
- if ( !this.stack )
- this.stack = [];
- this.stack.push( this.get() );
- return this.set( a );
+ pushStack: function(a,args) {
+ var fn = args && args[args.length-1];
+ var fn2 = args && args[args.length-2];
+
+ if ( fn && fn.constructor != Function ) fn = null;
+ if ( fn2 && fn2.constructor != Function ) fn2 = null;
+
+ if ( !fn ) {
+ if ( !this.stack ) this.stack = [];
+ this.stack.push( this.get() );
+ this.set( a );
+ } else {
+ var old = this.get();
+ this.set( a );
+
+ if ( fn2 && a.length || !fn2 )
+ this.each( fn2 || fn ).set( old );
+ else
+ this.set( old ).each( fn );
+ }
+
+ return this;
}
};
@@ -1281,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")
@@ -1300,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;
@@ -1427,7 +1456,7 @@ jQuery.extend({
// Set the correct context (if none is provided)
context = context || document;
- if ( t.constructor != String ) return [t];
+ if ( typeof t != "string" ) return [t];
if ( !t.indexOf("//") ) {
context = context.documentElement;
@@ -1616,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
@@ -1987,6 +2016,11 @@ jQuery.extend({
* This property is available before the DOM is ready, therefore you can
* use it to add ready events only for certain browsers.
*
+ * 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
*