Bug Tracker

Changeset 5985

Show
Ignore:
Timestamp:
12/21/08 21:22:44 (7 months ago)
Author:
jeresig
Message:

Added the new jQuery.support object and removed all uses of jQuery.browser from within jQuery itself (while simultaneously deprecating the use of jQuery.browser).

Location:
trunk/jquery
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/jquery/build.xml

    r5345 r5985  
    3636            <fileset dir="${SRC_DIR}" includes="intro.js" /> 
    3737            <fileset dir="${SRC_DIR}" includes="core.js" /> 
     38            <fileset dir="${SRC_DIR}" includes="support.js" /> 
    3839            <fileset dir="${SRC_DIR}" includes="selector.js" /> 
    3940            <fileset dir="${SRC_DIR}" includes="event.js" /> 
  • trunk/jquery/Makefile

    r5345 r5985  
    1010 
    1111BASE_FILES = ${SRC_DIR}/core.js\ 
     12    ${SRC_DIR}/support.js\ 
    1213    ${SRC_DIR}/selector.js\ 
    1314    ${SRC_DIR}/event.js\ 
  • trunk/jquery/src/ajax.js

    r5948 r5985  
    460460            // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450 
    461461            return !xhr.status && location.protocol == "file:" || 
    462                 ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223 || 
    463                 jQuery.browser.safari && xhr.status === undefined; 
     462                ( xhr.status >= 200 && xhr.status < 300 ) || xhr.status == 304 || xhr.status == 1223; 
    464463        } catch(e){} 
    465464        return false; 
     
    472471 
    473472            // Firefox always returns 200. check Last-Modified date 
    474             return xhr.status == 304 || xhrRes == jQuery.lastModified[url] || 
    475                 jQuery.browser.safari && xhr.status === undefined; 
     473            return xhr.status == 304 || xhrRes == jQuery.lastModified[url]; 
    476474        } catch(e){} 
    477475        return false; 
  • trunk/jquery/src/core.js

    r5984 r5985  
    286286        // Do the clone 
    287287        var ret = this.map(function(){ 
    288             if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) { 
     288            if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) { 
    289289                // IE copies events bound via attachEvent when 
    290290                // using cloneNode. Calling detachEvent on the 
     
    643643 
    644644            script.type = "text/javascript"; 
    645             if ( jQuery.browser.msie ) 
     645            if ( jQuery.support.scriptEval ) 
     646                script.appendChild( document.createTextNode( data ) ); 
     647            else 
    646648                script.text = data; 
    647             else 
    648                 script.appendChild( document.createTextNode( data ) ); 
    649649 
    650650            // Use insertBefore instead of appendChild  to circumvent an IE6 bug. 
     
    835835        var ret, style = elem.style; 
    836836 
    837         // A helper method for determining if an element's values are broken 
    838         function color( elem ) { 
    839             if ( !jQuery.browser.safari ) 
    840                 return false; 
    841  
    842             // defaultView is cached 
    843             var ret = defaultView.getComputedStyle( elem, null ); 
    844             return !ret || ret.getPropertyValue("color") == ""; 
    845         } 
    846  
    847837        // We need to handle opacity special in IE 
    848         if ( name == "opacity" && jQuery.browser.msie ) { 
     838        if ( name == "opacity" && !jQuery.support.opacity ) { 
    849839            ret = jQuery.attr( style, "opacity" ); 
    850840 
     
    853843                ret; 
    854844        } 
    855         // Opera sometimes will give the wrong display answer, this fixes it, see #2037 
    856         if ( jQuery.browser.opera && name == "display" ) { 
    857             var save = style.outline; 
    858             style.outline = "0 solid black"; 
    859             style.outline = save; 
    860         } 
    861845 
    862846        // Make sure we're using the right name for getting the float value 
     
    877861            var computedStyle = defaultView.getComputedStyle( elem, null ); 
    878862 
    879             if ( computedStyle && !color( elem ) ) 
     863            if ( computedStyle ) 
    880864                ret = computedStyle.getPropertyValue( name ); 
    881  
    882             // If the element isn't reporting its values properly in Safari 
    883             // then some display: none elements are involved 
    884             else { 
    885                 var swap = [], stack = [], a = elem, i = 0; 
    886  
    887                 // Locate all of the parent display: none elements 
    888                 for ( ; a && color(a); a = a.parentNode ) 
    889                     stack.unshift(a); 
    890  
    891                 // Go through and make them visible, but in reverse 
    892                 // (It would be better if we knew the exact display type that they had) 
    893                 for ( ; i < stack.length; i++ ) 
    894                     if ( color( stack[ i ] ) ) { 
    895                         swap[ i ] = stack[ i ].style.display; 
    896                         stack[ i ].style.display = "block"; 
    897                     } 
    898  
    899                 // Since we flip the display style, we have to handle that 
    900                 // one special, otherwise get the value 
    901                 ret = name == "display" && swap[ stack.length - 1 ] != null ? 
    902                     "none" : 
    903                     ( computedStyle && computedStyle.getPropertyValue( name ) ) || ""; 
    904  
    905                 // Finally, revert the display styles back 
    906                 for ( i = 0; i < swap.length; i++ ) 
    907                     if ( swap[ i ] != null ) 
    908                         stack[ i ].style.display = swap[ i ]; 
    909             } 
    910865 
    911866            // We should always get a number back from opacity 
     
    992947 
    993948                    // IE can't serialize <link> and <script> tags normally 
    994                     jQuery.browser.msie && 
     949                    !jQuery.support.htmlSerialize && 
    995950                    [ 1, "div<div>", "</div>" ] || 
    996951 
     
    1005960 
    1006961                // Remove IE's autoinserted <tbody> from table fragments 
    1007                 if ( jQuery.browser.msie ) { 
     962                if ( !jQuery.support.tbody ) { 
    1008963 
    1009964                    // String was a <table>, *may* have spurious <tbody> 
     
    1020975                            tbody[ j ].parentNode.removeChild( tbody[ j ] ); 
    1021976 
    1022                     // IE completely kills leading whitespace when innerHTML is used 
    1023                     if ( /^\s/.test( elem ) ) 
    1024                         div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild ); 
    1025  
    1026                 } 
     977                    } 
     978 
     979                // IE completely kills leading whitespace when innerHTML is used 
     980                if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) ) 
     981                    div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild ); 
    1027982                 
    1028983                if ( fragment ) { 
     
    10691024        var notxml = !jQuery.isXMLDoc( elem ), 
    10701025            // Whether we are setting (or getting) 
    1071             set = value !== undefined, 
    1072             msie = jQuery.browser.msie; 
     1026            set = value !== undefined; 
    10731027 
    10741028        // Try to normalize/fix the name 
     
    10841038            // Safari mis-reports the default selected property of a hidden option 
    10851039            // Accessing the parent's selectedIndex property fixes it 
    1086             if ( name == "selected" && jQuery.browser.safari ) 
     1040            if ( name == "selected" ) 
    10871041                elem.parentNode.selectedIndex; 
    10881042 
     
    11041058            } 
    11051059 
    1106             if ( msie && notxml &&  name == "style" ) 
     1060            if ( !jQuery.support.style && notxml &&  name == "style" ) 
    11071061                return jQuery.attr( elem.style, "cssText", value ); 
    11081062 
     
    11111065                elem.setAttribute( name, "" + value ); 
    11121066 
    1113             var attr = msie && notxml && special 
     1067            var attr = !jQuery.support.hrefNormalized && notxml && special 
    11141068                    // Some attributes require a special call on IE 
    11151069                    ? elem.getAttribute( name, 2 ) 
     
    11231077 
    11241078        // IE uses filters for opacity 
    1125         if ( msie && name == "opacity" ) { 
     1079        if ( !jQuery.support.opacity && name == "opacity" ) { 
    11261080            if ( set ) { 
    11271081                // IE has trouble with opacity if it does not have layout 
     
    11841138        // Also, we need to make sure that the correct elements are being returned 
    11851139        // (IE returns comment nodes in a '*' query) 
    1186         if ( jQuery.browser.msie ) { 
     1140        if ( !jQuery.support.getAll ) { 
    11871141            while ( (elem = second[ i++ ]) ) 
    11881142                if ( elem.nodeType != 8 ) 
     
    12441198    } 
    12451199}); 
     1200 
     1201// Use of jQuery.browser is deprecated. 
     1202// It's included for backwards compatibility and plugins, 
     1203// although they should work to migrate away. 
    12461204 
    12471205var userAgent = navigator.userAgent.toLowerCase(); 
     
    12561214}; 
    12571215 
    1258 var styleFloat = jQuery.browser.msie ? 
    1259     "styleFloat" : 
    1260     "cssFloat"; 
    1261  
    1262 jQuery.extend({ 
    1263     // Check to see if the W3C box model is being used 
    1264     boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat", 
    1265  
    1266     props: { 
    1267         "for": "htmlFor", 
    1268         "class": "className", 
    1269         "float": styleFloat, 
    1270         cssFloat: styleFloat, 
    1271         styleFloat: styleFloat, 
    1272         readonly: "readOnly", 
    1273         maxlength: "maxLength", 
    1274         cellspacing: "cellSpacing", 
    1275         rowspan: "rowSpan" 
    1276     } 
    1277 }); 
     1216// Check to see if the W3C box model is being used 
     1217jQuery.boxModel = !jQuery.browser.msie || document.compatMode == "CSS1Compat"; 
    12781218 
    12791219jQuery.each({ 
     
    13601300}); 
    13611301 
    1362 jQuery.each([ "Height", "Width" ], function(i, name){ 
    1363     var type = name.toLowerCase(); 
    1364  
    1365     jQuery.fn[ type ] = function( size ) { 
    1366         // Get window width or height 
    1367         return this[0] == window ? 
    1368             // Opera reports document.body.client[Width/Height] properly in both quirks and standards 
    1369             jQuery.browser.opera && document.body.parentNode[ "client" + name ] || 
    1370  
    1371             // Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths) 
    1372             jQuery.browser.safari && window[ "inner" + name ] || 
    1373  
    1374             // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode 
    1375             document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] : 
    1376  
    1377             // Get document width or height 
    1378             this[0] == document ? 
    1379                 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater 
    1380                 Math.max( 
    1381                     Math.max(document.body["scroll" + name], document.documentElement["scroll" + name]), 
    1382                     Math.max(document.body["offset" + name], document.documentElement["offset" + name]) 
    1383                 ) : 
    1384  
    1385                 // Get or set width or height on the element 
    1386                 size === undefined ? 
    1387                     // Get width or height on the element 
    1388                     (this.length ? jQuery.css( this[0], type ) : null) : 
    1389  
    1390                     // Set the width or height on the element (default to pixels if value is unitless) 
    1391                     this.css( type, typeof size === "string" ? size : size + "px" ); 
    1392     }; 
    1393 }); 
    1394  
    13951302// Helper function used by the dimensions and offset modules 
    13961303function num(elem, prop) { 
  • trunk/jquery/src/dimensions.js

    r5603 r5985  
    2020                num(this, "margin" + tl) + num(this, "margin" + br) : 0); 
    2121    }; 
     22     
     23    var type = name.toLowerCase(); 
     24 
     25    jQuery.fn[ type ] = function( size ) { 
     26        // Get window width or height 
     27        return this[0] == window ? 
     28            // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode 
     29            document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || 
     30            document.body[ "client" + name ] : 
     31 
     32            // Get document width or height 
     33            this[0] == document ? 
     34                // Either scroll[Width/Height] or offset[Width/Height], whichever is greater 
     35                Math.max( 
     36                    document.documentElement["client" + name], 
     37                    document.body["scroll" + name], document.documentElement["scroll" + name], 
     38                    document.body["offset" + name], document.documentElement["offset" + name] 
     39                ) : 
     40 
     41                // Get or set width or height on the element 
     42                size === undefined ? 
     43                    // Get width or height on the element 
     44                    (this.length ? jQuery.css( this[0], type ) : null) : 
     45 
     46                    // Set the width or height on the element (default to pixels if value is unitless) 
     47                    this.css( type, typeof size === "string" ? size : size + "px" ); 
     48    }; 
    2249 
    2350}); 
  • trunk/jquery/src/event.js

    r5978 r5985  
    1414        // For whatever reason, IE has trouble passing the window object 
    1515        // around, causing it to be cloned in the process 
    16         if ( jQuery.browser.msie && elem.setInterval ) 
     16        if ( elem.setInterval && elem != window ) 
    1717            elem = window; 
    1818 
     
    384384} 
    385385 
    386 if ( !jQuery.browser.msie ){     
    387     // Checks if an event happened on an element within another element 
    388     // Used in jQuery.event.special.mouseenter and mouseleave handlers 
    389     var withinElement = function(event) { 
    390         // Check if mouse(over|out) are still within the same parent element 
    391         var parent = event.relatedTarget; 
    392         // Traverse up the tree 
    393         while ( parent && parent != this ) 
    394             try { parent = parent.parentNode; } 
    395             catch(e) { parent = this; } 
    396          
    397         if( parent != this ){ 
    398             // set the correct event type 
    399             event.type = event.data; 
    400             // handle event if we actually just moused on to a non sub-element 
    401             jQuery.event.handle.apply( this, arguments ); 
    402         } 
    403     }; 
     386// Checks if an event happened on an element within another element 
     387// Used in jQuery.event.special.mouseenter and mouseleave handlers 
     388var withinElement = function(event) { 
     389    // Check if mouse(over|out) are still within the same parent element 
     390    var parent = event.relatedTarget; 
     391    // Traverse up the tree 
     392    while ( parent && parent != this ) 
     393        try { parent = parent.parentNode; } 
     394        catch(e) { parent = this; } 
    404395     
    405     jQuery.each({  
    406         mouseover: 'mouseenter',  
    407         mouseout: 'mouseleave' 
    408     }, function( orig, fix ){ 
    409         jQuery.event.special[ fix ] = { 
    410             setup: function(){ 
    411                 jQuery.event.add( this, orig, withinElement, fix ); 
    412             }, 
    413             teardown: function(){ 
    414                 jQuery.event.remove( this, orig, withinElement ); 
    415             } 
    416         };              
    417     }); 
    418 } 
     396    if( parent != this ){ 
     397        // set the correct event type 
     398        event.type = event.data; 
     399        // handle event if we actually just moused on to a non sub-element 
     400        jQuery.event.handle.apply( this, arguments ); 
     401    } 
     402}; 
     403     
     404jQuery.each({  
     405    mouseover: 'mouseenter',  
     406    mouseout: 'mouseleave' 
     407}, function( orig, fix ){ 
     408    jQuery.event.special[ fix ] = { 
     409        setup: function(){ 
     410            jQuery.event.add( this, orig, withinElement, fix ); 
     411        }, 
     412        teardown: function(){ 
     413            jQuery.event.remove( this, orig, withinElement ); 
     414        } 
     415    };              
     416}); 
    419417 
    420418jQuery.fn.extend({