Bug Tracker

Changeset 4132

Show
Ignore:
Timestamp:
12/13/07 02:00:33 (1 year ago)
Author:
brandon.aaron
Message:

Updating events_enhancement branch to latest version of trunk

Location:
branches/event_enhancements
Files:
1 removed
16 modified
13 copied

Legend:

Unmodified
Added
Removed
  • branches/event_enhancements/build/speed/benchmarker.js

    r2194 r4132  
    2121      } catch(e) { } 
    2222    }) 
    23     var times = 5; 
    24     jQuery("#times").html(times); 
     23    // set # times to run the test in index.html 
     24    var times = parseInt(jQuery("#times").val()); 
    2525    jQuery.benchmarker.startingList = this.get(); 
    2626    benchmark(this.get(), times, jQuery.benchmarker.libraries); 
     
    3434    jQuery("td.test").before("<td><input type='checkbox' checked='checked' /></td>"); 
    3535    jQuery("button.runTests").bind("click", function() { 
    36       jQuery('td[input:checked] + td.test').benchmark(); 
     36      jQuery('td:has(input:checked) + td.test').benchmark(); 
    3737    }); 
    3838 
    39     jQuery("button.retryTies").bind("click", function() { jQuery("tr[td.tie] td.test").benchmark() }) 
     39    jQuery("button.retryTies").bind("click", function() { jQuery("tr:has(td.tie) td.test").benchmark() }) 
    4040 
    4141    jQuery("button.selectAll").bind("click", function() { jQuery("input[@type=checkbox]").each(function() { this.checked = true }) }) 
     
    5353    }) 
    5454 
    55     var headers = jQuery.map(jQuery.benchmarker.libraries, function(i) { 
    56       return "<th>" + i + "</th>" 
     55    var headers = jQuery.map(jQuery.benchmarker.libraries, function(i,n) { 
     56      var extra = n == 0 ? "basis - " : ""; 
     57      return "<th>" + extra + i + "</th>" 
    5758    }).join(""); 
    5859 
  • branches/event_enhancements/build/speed/index.html

    r2194 r4132  
    66    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
    77    <title>Speed Test</title> 
    8     <script src="../dist/jquery.js" type="text/javascript"></script> 
    9     <script src="jquery-1.1.2.js" type="text/javascript"></script> 
     8    <script src="jquery-basis.js" type="text/javascript"></script> 
     9    <script src="../../dist/jquery.js" type="text/javascript"></script> 
     10  <script type="text/javascript"> 
     11     jQuery.noConflict(); 
     12  </script> 
    1013    <link rel="stylesheet" href="benchmarker.css" type="text/css" media="screen" /> 
    1114</head> 
     
    1619<div id="badid"></div> 
    1720<div id="time-test"> 
    18 <p>Using the following selector expressions (<span id="times">5</span> times each):</p> 
     21<p>Using the following selector expressions (<input type="text" id="times" maxlength="5" size="5" value="20"/> times each):</p> 
    1922<p>NOTE: Number shown is an average.</p> 
    2023<div class="buttons"> 
     
    503506</div> 
    504507    <script type="text/javascript" charset="utf-8"> 
    505             jQuery.benchmarker = {libraries: ["jQOld", "jQuery"]}; 
     508            jQuery.benchmarker = {libraries: ["$", "jQuery"]}; 
    506509    </script> 
    507510 
  • branches/event_enhancements/src/ajax.js

    r3840 r4132  
    5353                        res.responseText ); 
    5454 
    55                 // Add delay to account for Safari's delay in globalEval 
    56                 setTimeout(function(){ 
    57                     self.each( callback, [res.responseText, status, res] ); 
    58                 }, 13); 
     55                self.each( callback, [res.responseText, status, res] ); 
    5956            } 
    6057        }); 
     
    201198            s.cache = false; 
    202199 
    203         if ( s.cache === false && s.type.toLowerCase() == "get" ) 
    204             s.url += (s.url.match(/\?/) ? "&" : "?") + "_=" + (new Date()).getTime(); 
     200        if ( s.cache === false && s.type.toLowerCase() == "get" ) { 
     201            var ts = (new Date()).getTime(); 
     202            // try replacing _= if it is there 
     203            var ret = s.url.replace(/(\?|&)_=.*?(&|$)/, "$1_=" + ts + "$2"); 
     204            // if nothing was replaced, add timestamp to the end 
     205            s.url = ret + ((ret == s.url) ? (s.url.match(/\?/) ? "&" : "?") + "_=" + ts : ""); 
     206        } 
    205207 
    206208        // If data is available, append data to url for get requests 
     
    217219 
    218220        // If we're requesting a remote document 
    219         // and trying to load JSON or Script 
    220         if ( !s.url.indexOf("http") && s.dataType == "script" ) { 
     221        // and trying to load JSON or Script with a GET 
     222        if ( (!s.url.indexOf("http") || !s.url.indexOf("//")) && ( s.dataType == "script" || s.dataType =="json" ) && s.type.toLowerCase() == "get" ) { 
    221223            var head = document.getElementsByTagName("head")[0]; 
    222224            var script = document.createElement("script"); 
     
    271273             
    272274        if ( s.global ) 
    273             jQuery.event.trigger("ajaxSend", [xml, s]); 
     275            jQuery.event.trigger("ajaxSend", [xml, s]); 
    274276 
    275277        // Wait for a response to come back 
     
    398400    httpSuccess: function( r ) { 
    399401        try { 
     402            // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450 
    400403            return !r.status && location.protocol == "file:" || 
    401                 ( r.status >= 200 && r.status < 300 ) || r.status == 304 || 
     404                ( r.status >= 200 && r.status < 300 ) || r.status == 304 || r.status == 1223 || 
    402405                jQuery.browser.safari && r.status == undefined; 
    403406        } catch(e){} 
  • branches/event_enhancements/src/core.js

    r3856 r4132  
    1515 
    1616var jQuery = window.jQuery = function( selector, context ) { 
    17     // If the context is a namespace object, return a new object 
    18     return this instanceof jQuery ? 
    19         this.init( selector, context ) : 
    20         new jQuery( selector, context ); 
     17    // The jQuery object is actually just the init constructor 'enhanced' 
     18    return new jQuery.prototype.init( selector, context ); 
    2119}; 
    2220 
     
    3735        selector = selector || document; 
    3836 
     37        // Handle $(DOMElement) 
     38        if ( selector.nodeType ) { 
     39            this[0] = selector; 
     40            this.length = 1; 
     41            return this; 
     42 
    3943        // Handle HTML strings 
    40         if ( typeof selector == "string" ) { 
     44        } else if ( typeof selector == "string" ) { 
    4145            // Are we dealing with HTML string or an ID? 
    4246            var match = quickExpr.exec( selector ); 
     
    189193 
    190194    css: function( key, value ) { 
     195        // ignore negative width and height values 
     196        if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 ) 
     197            value = undefined; 
    191198        return this.attr( key, value, "curCSS" ); 
    192199    }, 
     
    194201    text: function( text ) { 
    195202        if ( typeof text != "object" && text != null ) 
    196             return this.empty().append( document.createTextNode( text ) ); 
     203            return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); 
    197204 
    198205        var ret = ""; 
     
    243250    append: function() { 
    244251        return this.domManip(arguments, true, false, function(elem){ 
    245             this.appendChild( elem ); 
     252            if (this.nodeType == 1) 
     253                this.appendChild( elem ); 
    246254        }); 
    247255    }, 
     
    249257    prepend: function() { 
    250258        return this.domManip(arguments, true, true, function(elem){ 
    251             this.insertBefore( elem, this.firstChild ); 
     259            if (this.nodeType == 1) 
     260                this.insertBefore( elem, this.firstChild ); 
    252261        }); 
    253262    }, 
     
    282291        // Do the clone 
    283292        var ret = this.map(function(){ 
    284             return this.outerHTML ? 
    285                 jQuery( this.outerHTML )[0] : 
    286                 this.cloneNode( true ); 
     293            if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) { 
     294                // IE copies events bound via attachEvent when 
     295                // using cloneNode. Calling detachEvent on the 
     296                // clone will also remove the events from the orignal 
     297                // In order to get around this, we use innerHTML. 
     298                // Unfortunately, this means some modifications to  
     299                // attributes in IE that are actually only stored  
     300                // as properties will not be copied (such as the 
     301                // the name attribute on an input). 
     302                var clone = this.cloneNode(true), 
     303                    container = document.createElement("div"), 
     304                    container2 = document.createElement("div"); 
     305                container.appendChild(clone); 
     306                container2.innerHTML = container.innerHTML; 
     307                return container2.firstChild; 
     308            } else 
     309                return this.cloneNode(true); 
    287310        }); 
    288311 
     
    332355 
    333356    add: function( selector ) { 
    334         return this.pushStack( jQuery.merge(  
     357        return !selector ? this : this.pushStack( jQuery.merge(  
    335358            this.get(), 
    336359            selector.constructor == String ?  
     
    355378            if ( this.length ) { 
    356379                var elem = this[0]; 
    357                  
     380 
    358381                // We need to handle select boxes special 
    359382                if ( jQuery.nodeName( elem, "select" ) ) { 
     
    388411                // Everything else, we just grab the value 
    389412                } else 
    390                     return this[0].value.replace(/\r/g, ""); 
     413                    return (this[0].value || "").replace(/\r/g, ""); 
    391414 
    392415            } 
     
    394417        } else 
    395418            return this.each(function(){ 
     419                if ( this.nodeType != 1 ) 
     420                    return; 
     421 
    396422                if ( value.constructor == Array && /radio|checkbox/.test( this.type ) ) 
    397423                    this.checked = (jQuery.inArray(this.value, value) >= 0 || 
     
    460486 
    461487            if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) ) 
    462                 obj = this.getElementsByTagName("tbody")[0] || this.appendChild( document.createElement("tbody") ); 
     488                obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") ); 
    463489 
    464490            var scripts = jQuery( [] ); 
     
    469495                    this; 
    470496 
     497                // execute all scripts after the elements have been injected 
    471498                if ( jQuery.nodeName( elem, "script" ) ) { 
    472  
    473                     // If scripts are waiting to be executed, wait on this script as well 
    474                     if ( scripts.length ) 
    475                         scripts = scripts.add( elem ); 
    476  
    477                     // If nothing is waiting to be executed, run immediately 
    478                     else 
    479                         evalScript( 0, elem ); 
    480  
     499                    scripts = scripts.add( elem ); 
    481500                } else { 
    482501                    // Remove any inner scripts for later evaluation 
     
    493512    } 
    494513}; 
     514 
     515// Give the init function the jQuery prototype for later instantiation 
     516jQuery.prototype.init.prototype = jQuery.prototype; 
    495517 
    496518function evalScript( i, elem ) { 
     
    522544 
    523545    // Handle case when target is a string or something (possible in deep copy) 
    524     if ( typeof target != "object" ) 
     546    if ( typeof target != "object" && typeof target != "function" ) 
    525547        target = {}; 
    526548 
     
    541563 
    542564                // Recurse if we're merging object values 
    543                 if ( deep && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType ) 
     565                if ( deep && options[ name ] && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType ) 
    544566                    target[ name ] = jQuery.extend( target[ name ], options[ name ] ); 
    545567 
     
    583605 
    584606    // Evalulates a script in a global context 
    585     // Evaluates Async. in Safari 2 :-( 
    586607    globalEval: function( data ) { 
    587608        data = jQuery.trim( data ); 
     
    715736        add: function( elem, classNames ) { 
    716737            jQuery.each((classNames || "").split(/\s+/), function(i, className){ 
    717                 if ( !jQuery.className.has( elem.className, className ) ) 
     738                if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) ) 
    718739                    elem.className += (elem.className ? " " : "") + className; 
    719740            }); 
     
    722743        // internal only, use removeClass("class") 
    723744        remove: function( elem, classNames ) { 
    724             elem.className = classNames != undefined ? 
    725                 jQuery.grep(elem.className.split(/\s+/), function(className){ 
    726                     return !jQuery.className.has( classNames, className );   
    727                 }).join(" ") : 
    728                 ""; 
     745            if (elem.nodeType == 1) 
     746                elem.className = classNames != undefined ? 
     747                    jQuery.grep(elem.className.split(/\s+/), function(className){ 
     748                        return !jQuery.className.has( classNames, className );   
     749                    }).join(" ") : 
     750                    ""; 
    729751        }, 
    730752 
     
    750772    }, 
    751773 
    752     css: function( elem, name ) { 
    753         if ( name == "height" || name == "width" ) { 
    754             var old = {}, height, width; 
    755  
    756             // Revert the padding and border widths to get the 
    757             // correct height/width values 
    758             jQuery.each([ "Top", "Bottom", "Right", "Left" ], function(){ 
    759                 old[ "padding" + this ] = 0; 
    760                 old[ "border" + this + "Width" ] = 0; 
    761             }); 
    762  
    763             // Swap out the padding/border values temporarily 
    764             jQuery.swap( elem, old, function() { 
    765  
    766                 // If the element is visible, then the calculation is easy 
    767                 if ( jQuery( elem ).is(":visible") ) { 
    768                     height = elem.offsetHeight; 
    769                     width = elem.offsetWidth; 
    770  
    771                 // Otherwise, we need to flip out more values 
    772                 } else { 
    773                     elem = jQuery( elem.cloneNode(true) ) 
    774                         .find(":radio").removeAttr("checked").removeAttr("defaultChecked").end() 
    775                         .css({ 
    776                             visibility: "hidden", 
    777                             position: "absolute", 
    778                             display: "block", 
    779                             right: "0", 
    780                             left: "0" 
    781                         }).appendTo( elem.parentNode )[0]; 
    782  
    783                     var position = jQuery.css( elem.parentNode, "position" ) || "static"; 
    784                     if ( position == "static" ) 
    785                         elem.parentNode.style.position = "relative"; 
    786  
    787                     height = elem.clientHeight; 
    788                     width = elem.clientWidth; 
    789  
    790                     if ( position == "static" ) 
    791                         elem.parentNode.style.position = "static"; 
    792  
    793                     elem.parentNode.removeChild( elem ); 
    794                 } 
    795             }); 
    796  
    797             return name == "height" ? 
    798                 height : 
    799                 width; 
     774    css: function( elem, name, force ) { 
     775        if ( name == "width" || name == "height" ) { 
     776            var width, height, props = { position: "absolute", visibility: "hidden", display:"block" }; 
     777         
     778            function getWH() { 
     779                width = elem.clientWidth; 
     780                height = elem.clientHeight; 
     781            } 
     782         
     783            if ( jQuery(elem).is(":visible") ) 
     784                getWH(); 
     785            else 
     786                jQuery.swap( elem, props, getWH ); 
     787 
     788            return name == "width" ? width : height; 
    800789        } 
    801  
    802         return jQuery.curCSS( elem, name ); 
     790         
     791        return jQuery.curCSS( elem, name, force ); 
    803792    }, 
    804793 
     
    910899        var ret = []; 
    911900        context = context || document; 
     901        // !context.createElement fails in IE with an error but returns typeof 'object' 
     902        if (typeof context.createElement == 'undefined')  
     903            context = context.ownerDocument || context[0] && context[0].ownerDocument || document; 
    912904 
    913905        jQuery.each(elems, function(i, elem){ 
     
    1004996     
    1005997    attr: function( elem, name, value ) { 
     998        // don't set attributes on text and comment nodes 
     999        if (!elem || elem.nodeType == 3 || elem.nodeType == 8) 
     1000            return undefined; 
     1001 
    10061002        var fix = jQuery.isXMLDoc( elem ) ? 
    10071003            {} : 
     
    10341030                    throw "type property can't be changed"; 
    10351031 
    1036                 elem.setAttribute( name, value ); 
     1032                // convert the value to a string (all browsers do this but IE) see #1070 
     1033                elem.setAttribute( name, "" + value ); 
    10371034            } 
    10381035 
     
    10561053                } 
    10571054     
    1058                 return elem.filter ?  
     1055                return elem.filter && elem.filter.indexOf("opacity=") >= 0 ? 
    10591056                    (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() : 
    10601057                    ""; 
     
    12561253    removeAttr: function( name ) { 
    12571254        jQuery.attr( this, name, "" ); 
    1258         this.removeAttribute( name ); 
     1255        if (this.nodeType == 1)  
     1256            this.removeAttribute( name ); 
    12591257    }, 
    12601258 
     
    13161314                // Either scroll[Width/Height] or offset[Width/Height], whichever is greater (Mozilla reports scrollWidth the same as offsetWidth) 
    13171315                Math.max( document.body[ "scroll" + name ], document.body[ "offset" + name ] ) : 
    1318          
     1316 
    13191317                // Get or set width or height on the element 
    13201318                size == undefined ? 
  • branches/event_enhancements/src/event.js

    r3896 r4132  
    99    // Original by Dean Edwards 
    1010    add: function(element, types, handler, data) { 
     11        if ( element.nodeType == 3 || element.nodeType == 8 ) 
     12            return; 
     13 
    1114        // For whatever reason, IE has trouble passing the window object 
    1215        // around, causing it to be cloned in the process 
     
    2023        // if data is passed, bind to handler  
    2124        if( data != undefined ) {  
    22             // Create temporary function pointer to original handler  
     25            // Create temporary function pointer to original handler  
    2326            var fn = handler;  
    2427 
     
    8891    // Detach an event or set of events from an element 
    8992    remove: function(element, types, handler) { 
     93        // don't do events on text and comment nodes 
     94        if ( element.nodeType == 3 || element.nodeType == 8 ) 
     95            return; 
     96 
    9097        var events = jQuery.data(element, "events"), ret, index; 
    9198 
     
    159166        // Handle triggering a single element 
    160167        } else { 
     168            // don't do events on text and comment nodes 
     169            if ( element.nodeType == 3 || element.nodeType == 8 ) 
     170                return; 
     171 
    161172            var val, ret, fn = jQuery.isFunction( element[ type ] || null ), 
    162173                // Check to see if we need to provide a fake event, or not 
     
    183194 
    184195            // Handle triggering of extra function 
    185             if ( extra && extra.apply( element, data ) === false ) 
    186                 val = false; 
     196            if ( extra ) { 
     197                // call the extra function and tack the current return value on the end for possible inspection 
     198                var ret = extra.apply( element, data.concat( val ) ); 
     199                // if anything is returned, give it precedence and have it overwrite the previous value 
     200                if (ret !== undefined) 
     201                    val = ret; 
     202            } 
    187203 
    188204            // Trigger the native events (except for clicks on links) 
    189205            if ( fn && donative !== false && val !== false && !(jQuery.nodeName(element, 'a') && type == "click") ) { 
    190206                this.triggered = true; 
    191                 element[ type ](); 
     207                try { 
     208                    element[ type ](); 
     209                // prevent IE from throwing an error for some hidden elements 
     210                } catch (e) {} 
    192211            } 
    193212 
     
    280299            var doc = document.documentElement, body = document.body; 
    281300            event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0) - (doc.clientLeft || 0); 
    282             event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop  || 0) - (doc.clientLeft || 0); 
     301            event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0) - (doc.clientTop || 0); 
    283302        } 
    284303             
     
    503522             
    504523            // and execute the function 
    505             return args[this.lastToggle].apply( this, [event] ) || false; 
     524            return args[this.lastToggle].apply( this, arguments ) || false; 
    506525        }); 
    507526    },