Moved from the old JSMin to using YUIMin for compressing the jQuery source. Additiona...
[jquery.git] / src / core.js
index ff8114b..8c4c09b 100644 (file)
@@ -9,6 +9,9 @@
  * $Rev$
  */
 
+// Will speed up references to window, and allows munging its name.
+var window = this;
+
 // Map over jQuery in case of overwrite
 var _jQuery = window.jQuery,
 // Map over the $ in case of overwrite
@@ -24,7 +27,7 @@ var jQuery = window.jQuery = window.$ = function( selector, context ) {
 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
 
 // Is it a simple selector
-       isSimple = /^.[^:#\[\.]*$/,
+       isSimple = /^.[^:#\[\.,]*$/,
 
 // Will speed up references to undefined, and allows munging its name.
        undefined;
@@ -81,7 +84,7 @@ jQuery.fn = jQuery.prototype = {
                // HANDLE: $(function)
                // Shortcut for document ready
                } else if ( jQuery.isFunction( selector ) )
-                       return jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );
+                       return jQuery( document ).ready( selector );
 
                return this.setArray(jQuery.makeArray(selector));
        },
@@ -151,8 +154,6 @@ jQuery.fn = jQuery.prototype = {
        // Determine the position of an element within
        // the matched set of elements
        index: function( elem ) {
-               var ret = -1;
-
                // Locate the position of the desired element
                return jQuery.inArray(
                        // If it receives a jQuery object, the first element is used
@@ -485,31 +486,6 @@ jQuery.fn = jQuery.prototype = {
                return this.add( this.prevObject );
        },
 
-       data: function( key, value ){
-               var parts = key.split(".");
-               parts[1] = parts[1] ? "." + parts[1] : "";
-
-               if ( value === undefined ) {
-                       var data = this.triggerHandler("getData" + parts[1] + "!", [parts[0]]);
-
-                       if ( data === undefined && this.length )
-                               data = jQuery.data( this[0], key );
-
-                       return data == null && parts[1] ?
-                               this.data( parts[0] ) :
-                               data;
-               } else
-                       return this.trigger("setData" + parts[1] + "!", [parts[0], value]).each(function(){
-                               jQuery.data( this, key, value );
-                       });
-       },
-
-       removeData: function( key ){
-               return this.each(function(){
-                       jQuery.removeData( this, key );
-               });
-       },
-
        domManip: function( args, table, callback ) {
                if ( this[0] ) {
                        var fragment = this[0].ownerDocument.createDocumentFragment(),
@@ -608,9 +584,8 @@ jQuery.extend = jQuery.fn.extend = function() {
        return target;
 };
 
-var expando = "jQuery" + now(), uuid = 0, windowData = {},
-       // exclude the following css properties to add px
-       exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
+// exclude the following css properties to add px
+var    exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
        // cache defaultView
        defaultView = document.defaultView || {},
        toString = Object.prototype.toString;
@@ -669,74 +644,6 @@ jQuery.extend({
                return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();
        },
 
-       cache: {},
-
-       data: function( elem, name, data ) {
-               elem = elem == window ?
-                       windowData :
-                       elem;
-
-               var id = elem[ expando ];
-
-               // Compute a unique ID for the element
-               if ( !id )
-                       id = elem[ expando ] = ++uuid;
-
-               // Only generate the data cache if we're
-               // trying to access or manipulate it
-               if ( name && !jQuery.cache[ id ] )
-                       jQuery.cache[ id ] = {};
-
-               // Prevent overriding the named cache with undefined values
-               if ( data !== undefined )
-                       jQuery.cache[ id ][ name ] = data;
-
-               // Return the named cache data, or the ID for the element
-               return name ?
-                       jQuery.cache[ id ][ name ] || null :
-                       id;
-       },
-
-       removeData: function( elem, name ) {
-               elem = elem == window ?
-                       windowData :
-                       elem;
-
-               var id = elem[ expando ];
-
-               // If we want to remove a specific section of the element's data
-               if ( name ) {
-                       if ( jQuery.cache[ id ] ) {
-                               // Remove the section of cache data
-                               delete jQuery.cache[ id ][ name ];
-
-                               // If we've removed all the data, remove the element's cache
-                               name = "";
-
-                               for ( name in jQuery.cache[ id ] )
-                                       break;
-
-                               if ( !name )
-                                       jQuery.removeData( elem );
-                       }
-
-               // Otherwise, we want to remove all of the element's data
-               } else {
-                       // Clean up the element expando
-                       try {
-                               delete elem[ expando ];
-                       } catch(e){
-                               // IE has trouble directly removing the expando
-                               // but it's ok with using removeAttribute
-                               if ( elem.removeAttribute )
-                                       elem.removeAttribute( expando );
-                       }
-
-                       // Completely remove the data cache
-                       delete jQuery.cache[ id ];
-               }
-       },
-
        // args is for internal usage only
        each: function( object, callback, args ) {
                var name, i = 0, length = object.length;
@@ -909,13 +816,22 @@ jQuery.extend({
        },
 
        clean: function( elems, context, fragment ) {
-               var ret = [], scripts = [];
                context = context || document;
 
                // !context.createElement fails in IE with an error but returns typeof 'object'
                if ( typeof context.createElement === "undefined" )
                        context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
 
+               // If a single string is passed in and it's a single tag
+               // just do a createElement and skip the rest
+               if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
+                       var match = /^<(\w+)\/?>$/.exec(elems[0]);
+                       if ( match )
+                               return [ context.createElement( match[1] ) ];
+               }
+
+               var ret = [], scripts = [], div = context.createElement("div");
+
                jQuery.each(elems, function(i, elem){
                        if ( typeof elem === "number" )
                                elem += '';
@@ -933,7 +849,7 @@ jQuery.extend({
                                });
 
                                // Trim whitespace, otherwise indexOf won't work as expected
-                               var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");
+                               var tags = jQuery.trim( elem ).toLowerCase();
 
                                var wrap =
                                        // option or optgroup
@@ -1009,15 +925,17 @@ jQuery.extend({
                                ret = jQuery.merge( ret, elem );
 
                });
-               
+
                if ( fragment ) {
                        for ( var i = 0; ret[i]; i++ ) {
-                               if ( jQuery.nodeName( ret[i], "script" ) ) {
-                                       ret[i].parentNode.removeChild( ret[i] );
+                               var node = ret[i];
+                               if ( jQuery.nodeName( node, "script" ) ) {
+                                       if( node.parentNode )
+                                               node.parentNode.removeChild( node );
                                } else {
-                                       if ( ret[i].nodeType === 1 )
-                                               ret = jQuery.merge( ret, ret[i].getElementsByTagName("script"));
-                                       fragment.appendChild( ret[i] );
+                                       if ( node.nodeType === 1 )
+                                               ret = jQuery.merge( ret, node.getElementsByTagName("script"));
+                                       fragment.appendChild( node );
                                }
                        }
                        
@@ -1149,12 +1067,12 @@ jQuery.extend({
                // Also, we need to make sure that the correct elements are being returned
                // (IE returns comment nodes in a '*' query)
                if ( !jQuery.support.getAll ) {
-                       while ( (elem = second[ i++ ]) )
+                       while ( (elem = second[ i++ ]) != null )
                                if ( elem.nodeType != 8 )
                                        first[ pos++ ] = elem;
 
                } else
-                       while ( (elem = second[ i++ ]) )
+                       while ( (elem = second[ i++ ]) != null )
                                first[ pos++ ] = elem;
 
                return first;
@@ -1280,8 +1198,10 @@ jQuery.each({
                jQuery.className.remove( this, classNames );
        },
 
-       toggleClass: function( classNames ) {
-               jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );
+       toggleClass: function( classNames, state ) {
+               if( typeof state !== "boolean" )
+                       state = !jQuery.className.has( this, classNames );
+               jQuery.className[ state ? "add" : "remove" ]( this, classNames );
        },
 
        remove: function( selector ) {