Fixed the issue with jQuery conflicting with windows/IFrames.
[jquery.git] / src / jquery / jquery.js
index 303350a..93ebe20 100644 (file)
@@ -31,7 +31,7 @@ window.undefined = window.undefined;
 var jQuery = function(a,c) {
 
        // Shortcut for document ready (because $(document).each() is silly)
-       if ( a && typeof a == "function" && jQuery.fn.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
@@ -56,7 +56,7 @@ var jQuery = function(a,c) {
        }
 
        // Watch for when an array is passed in
-       this.get( a.constructor == Array || a.length && !a.nodeType && a[0] != undefined && a[0].nodeType ?
+       this.get( 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, [] ) :
 
@@ -944,12 +944,15 @@ jQuery.fn = jQuery.prototype = {
         * @result $("p").find("span").end() == [ <p>...</p> ]
         *
         * @test ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
+        * ok( $('#yahoo').end(), 'Check for end with nothing to end' );
         *
         * @name end
         * @type jQuery
         * @cat DOM/Traversing
         */
        end: function() {
+               if( !(this.stack && this.stack.length) )
+                       return this;
                return this.get( this.stack.pop() );
        },
 
@@ -1548,9 +1551,10 @@ jQuery.extend({
        clean: function(a) {
                var r = [];
                for ( var i = 0; i < a.length; i++ ) {
-                       if ( a[i].constructor == String ) { // Convert html string into DOM nodes
+                       var arg = a[i];
+                       if ( arg.constructor == String ) { // Convert html string into DOM nodes
                                // Trim whitespace, otherwise indexOf won't work as expected
-                               var s = jQuery.trim(a[i]), div = document.createElement("div"), wrap = [0,"",""];
+                               var s = jQuery.trim(arg), div = document.createElement("div"), wrap = [0,"",""];
 
                                if ( !s.indexOf("<opt") ) // option or optgroup
                                        wrap = [1, "<select>", "</select>"];
@@ -1564,14 +1568,15 @@ jQuery.extend({
                                // Go to html and back, then peel off extra wrappers
                                div.innerHTML = wrap[1] + s + wrap[2];
                                while ( wrap[0]-- ) div = div.firstChild;
-                               a[i] = div.childNodes;
-                       }
-
-                       if ( a[i].length != undefined && !a[i].nodeType ) // Handles Array, jQuery, DOM NodeList collections
-                               for ( var n=0; n < a[i].length; n++ )
-                                       r.push(a[i][n]);
-                       else if ( a[i] !== null )
-                               r.push( a[i].nodeType ? a[i] : document.createTextNode(a[i].toString()) );
+                               arg = div.childNodes;
+                       } 
+                       
+                       
+                       if ( arg.length != undefined && ( (jQuery.browser.safari && typeof arg == 'function') || !arg.nodeType ) ) // Safari reports typeof on a DOM NodeList to be a function
+                               for ( var n = 0; n < arg.length; n++ ) // Handles Array, jQuery, DOM NodeList collections
+                                       r.push(arg[n]);
+                       else
+                               r.push( arg.nodeType ? arg : document.createTextNode(arg.toString()) );
                }
 
                return r;
@@ -1691,10 +1696,6 @@ jQuery.extend({
         * t( "Attribute Exists", "a[@title]", ["google"] );
         * t( "Attribute Exists", "*[@title]", ["google"] );
         * t( "Attribute Exists", "[@title]", ["google"] );
-        * 
-        * t( "Non-existing part of attribute", "[@name*=bla]", [] ); 
-        * t( "Non-existing start of attribute", "[@name^=bla]", [] ); 
-        * t( "Non-existing end of attribute", "[@name$=bla]", [] ); 
         *
         * t( "Attribute Equals", "a[@rel='bookmark']", ["simon1"] );
         * t( "Attribute Equals", 'a[@rel="bookmark"]', ["simon1"] );
@@ -1730,8 +1731,8 @@ jQuery.extend({
         * t( "Attribute Exists", "//a[@title]", ["google"] );
         * t( "Attribute Equals", "//a[@rel='bookmark']", ["simon1"] );
         * t( "Parent Axis", "//p/..", ["main","foo"] );
-        * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
-        * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","sndp","en","sap"] );
+        * t( "Sibling Axis", "//p/../", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );
+        * t( "Sibling Axis", "//p/../*", ["firstp","ap","foo","first","firstUL","empty","form","floatTest","sndp","en","sap"] );
         * t( "Has Children", "//p[a]", ["firstp","ap","en","sap"] );
         *
         * t( "nth Element", "p:nth(1)", ["ap"] );
@@ -1902,7 +1903,7 @@ jQuery.extend({
                        return elem[fix[name]];
                } else if( value == undefined && jQuery.browser.msie && elem.nodeName && elem.nodeName.toUpperCase() == 'FORM' && (name == 'action' || name == 'method') ) {
                        return elem.getAttributeNode(name).nodeValue;
-               } else if ( elem.getAttribute != undefined && elem.tagName ) { // IE elem.getAttribute passes even for style
+               } else if ( (jQuery.browser.msie || elem.getAttribute != undefined) && elem.tagName ) { // IE elem.getAttribute passes even for style; Do not "call" elem.getAttribute in IE <- weird crap
                        if ( value != undefined ) elem.setAttribute( name, value );
                        return elem.getAttribute( name );
                } else {
@@ -2267,7 +2268,7 @@ jQuery.extend({
                handle: function(event) {
                        if ( typeof jQuery == "undefined" ) return false;
 
-                       event = event || jQuery.event.fix( window.event );
+                       event = jQuery.event.fix( event || window.event || {} ); // Empty object is for triggered events with no data
 
                        // If no correct event was found, fail
                        if ( !event ) return false;
@@ -2287,23 +2288,39 @@ jQuery.extend({
                                }
                        }
 
+                       // Clean up added properties in IE to prevent memory leak
+                       if (jQuery.browser.msie) event.target = event.preventDefault = event.stopPropagation = null;
+
                        return returnValue;
                },
 
                fix: function(event) {
-                       if ( event ) {
+                       // check IE
+                       if(jQuery.browser.msie) {
+                               // fix target property
+                               event.target = event.srcElement;
+                               
+                       // check safari and if target is a textnode
+                       } else if(jQuery.browser.safari && event.target.nodeType == 3) {
+                               // target is readonly, clone the event object
+                               event = jQuery.extend({}, event);
+                               // get parentnode from textnode
+                               event.target = event.target.parentNode;
+                       }
+                       
+                       // fix preventDefault and stopPropagation
+                       if (!event.preventDefault)
                                event.preventDefault = function() {
                                        this.returnValue = false;
                                };
-
+                               
+                       if (!event.stopPropagation)
                                event.stopPropagation = function() {
                                        this.cancelBubble = true;
                                };
-                       }
-
+                       
                        return event;
                }
-
        }
 });
 
@@ -3082,7 +3099,7 @@ jQuery.macros = {
                 *
                 * It only returns the immediately previous sibling, not all previous siblings.
                 *
-                * @example $("p").previous(".selected")
+                * @example $("p").prev(".selected")
                 * @before <div><span>Hello</span></div><p class="selected">Hello Again</p><p>And Again</p>
                 * @result [ <div><span>Hello</span></div> ]
                 *