Made a bunch of changes to the way that the $() compatability code is handled.
[jquery.git] / jquery / jquery.js
index 97fa48e..66a3af8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * jQuery
+ * jQuery - New Wave Javascript
  *
  * Copyright (c) 2006 John Resig (jquery.com)
  * Licensed under the MIT License:
 // Global undefined variable
 window.undefined = window.undefined;
 
+// Map over the $ in case of overwrite
+if ( $ ) var ._$ = $;
+
 /**
  * Create a new jQuery Object
  * @constructor
  */
-function jQuery(a,c) {
+var $ = jQuery = function(a,c) {
+       /*
+       * Handle support for overriding other $() functions. Way too many libraries
+       * provide this function to simply ignore it and overwrite it.
+       */
+
+       // Check to see if this is a possible collision case
+       if ( _$ && !c && ( a.constructor == String && 
+      
+               // Make sure that the expression is a colliding one
+               !/[^a-zA-Z0-9_-]/.test(a) &&
+        
+               // and that there are no elements that match it
+               // (this is the one truly ambiguous case)
+               !document.getElementsByTagName(a).length ) ||
+
+               // Watch for an array being passed in (Prototype 1.5)
+               a.constructor == Array )
+
+                       // Use the default method, in case it works some voodoo
+                       return _$( a );
+
+       // Watch for when a jQuery object is passed in as an arg
+       if ( a && a.jquery )
+               return a;
+       
+       // If the context is global, return a new object
        if ( window == this )
                return new jQuery(a,c);
        
+       // Find the matching elements and save them for later
        this.cur = jQuery.Select(
                a || jQuery.context || document,
                c && c.jquery && c.get(0) || c
        );
 }
 
-/**
- * The jQuery query object.
- */
-var $ = jQuery;
-
 jQuery.fn = jQuery.prototype = {
        /**
         * The current SVN version of jQuery.
@@ -67,7 +92,7 @@ jQuery.fn = jQuery.prototype = {
        },
        set: function(a,b) {
                return this.each(function(){
-                       if ( b == undefined )
+                       if ( b === undefined )
                                for ( var j in a )
                                        jQuery.attr(this,j,a[j]);
                        else
@@ -94,9 +119,9 @@ jQuery.fn = jQuery.prototype = {
        },
        
        css: function(a,b) {
-               return  a.constructor != String || b ?
+               return a.constructor != String || b ?
                        this.each(function(){
-                               if ( !b )
+                               if ( b === undefined )
                                        for ( var j in a )
                                                jQuery.attr(this.style,j,a[j]);
                                else
@@ -457,9 +482,9 @@ jQuery.g = {
                empty: "!a.childNodes.length",
                root: "a==(a.ownerDocument||document).documentElement",
                contains: "(a.innerText||a.innerHTML).indexOf(m[3])!=-1",
-               visible: "(!a.type||a.type!='hidden')&&(jQuery.css(a,'display')!= 'none'&&jQuery.css(a,'visibility')!= 'hidden')",
-               hidden: "(a.type&&a.type == 'hidden')||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')== 'hidden'",
-               enabled: "a.disabled==false",
+               visible: "(!a.type||a.type!='hidden')&&(jQuery.css(a,'display')!='none'&&jQuery.css(a,'visibility')!= 'hidden')",
+               hidden: "(a.type&&a.type=='hidden')||jQuery.css(a,'display')=='none'||jQuery.css(a,'visibility')== 'hidden'",
+               enabled: "!a.disabled",
                disabled: "a.disabled",
                checked: "a.checked"
        },
@@ -493,7 +518,8 @@ jQuery.token = [
 
 jQuery.Select = function( t, context ) {
        context = context || jQuery.context || document;
-       if ( t.constructor != String ) return [t];
+       if ( t.constructor != String )
+               return t.constructor == Array ? t : [t];
 
        if ( !t.indexOf("//") ) {
                context = context.documentElement;