X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fjquery%2Fjquery.js;h=d9292ed697c36396cd2b8f6f1b9e1b73985a8f3d;hb=ff4f265bc0273bda0c8873d470aefa20170abc41;hp=c22c12c6159614fe1e50ba835a4f8ca821ce2054;hpb=5c54a4b8ee5cfea3aff55a1122b187b731319e61;p=jquery.git diff --git a/src/jquery/jquery.js b/src/jquery/jquery.js index c22c12c..d9292ed 100644 --- a/src/jquery/jquery.js +++ b/src/jquery/jquery.js @@ -26,37 +26,8 @@ var jQuery = function(a,c) { // If the context is global, return a new object if ( window == this ) return new jQuery(a,c); - - // Make sure that a selection was provided - a = a || document; - - // HANDLE: $(function) - // Shortcut for document ready - if ( jQuery.isFunction(a) ) - return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a ); - - // Handle HTML strings - if ( typeof a == "string" ) { - // HANDLE: $(html) -> $(array) - var m = /^[^<]*(<(.|\s)+>)[^>]*$/.exec(a); - if ( m ) - a = jQuery.clean( [ m[1] ] ); - - // HANDLE: $(expr) - else - return new jQuery( c ).find( a ); - } - return this.setArray( - // HANDLE: $(array) - a.constructor == Array && a || - - // HANDLE: $(arraylike) - // Watch for when an array-like object is passed as the selector - (a.jquery || a.length && a != window && !a.nodeType && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) || - - // HANDLE: $(*) - [ a ] ); + return this.init(a,c); }; // Map over the $ in case of overwrite @@ -170,6 +141,48 @@ var $ = jQuery; jQuery.fn = jQuery.prototype = { /** + * Initialize a new jQuery object + * + * @private + * @name init + * @param String|Function|Element|Array|jQuery a selector + * @param jQuery|Element|Array c context + * @cat Core + */ + init: function(a,c) { + // Make sure that a selection was provided + a = a || document; + + // HANDLE: $(function) + // Shortcut for document ready + if ( jQuery.isFunction(a) ) + return new jQuery(document)[ jQuery.fn.ready ? "ready" : "load" ]( a ); + + // Handle HTML strings + if ( typeof a == "string" ) { + // HANDLE: $(html) -> $(array) + var m = /^[^<]*(<(.|\s)+>)[^>]*$/.exec(a); + if ( m ) + a = jQuery.clean( [ m[1] ] ); + + // HANDLE: $(expr) + else + return new jQuery( c ).find( a ); + } + + return this.setArray( + // HANDLE: $(array) + a.constructor == Array && a || + + // HANDLE: $(arraylike) + // Watch for when an array-like object is passed as the selector + (a.jquery || a.length && a != window && (!a.nodeType || (jQuery.browser.msie && a.elements)) && a[0] != undefined && a[0].nodeType) && jQuery.makeArray( a ) || + + // HANDLE: $(*) + [ a ] ); + }, + + /** * The current version of jQuery. * * @private @@ -1336,7 +1349,7 @@ jQuery.extend({ // internal only, use removeClass("class") remove: function( elem, c ){ - elem.className = c ? + elem.className = c != undefined ? jQuery.grep( elem.className.split(/\s+/), function(cur){ return !jQuery.className.has( c, cur ); }).join(" ") : ""; @@ -1510,7 +1523,7 @@ jQuery.extend({ if ( 0 === arg.length && !jQuery(arg).is("form, select") ) return; - if ( arg[0] == undefined || jQuery(arg).is("form, select") ) + if ( arg[0] == undefined || jQuery.nodeName(arg, "form") || arg.options ) r.push( arg ); else r = jQuery.merge( r, arg ); @@ -1786,7 +1799,7 @@ new function() { // Figure out what browser is being used jQuery.browser = { - version: b.match(/.+[xiae][\/ ]([\d.]+)/)[1], + version: b.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)[1], safari: /webkit/.test(b), opera: /opera/.test(b), msie: /msie/.test(b) && !/opera/.test(b),