Changeset 4132
- Timestamp:
- 12/13/07 02:00:33 (1 year ago)
- Location:
- branches/event_enhancements
- Files:
-
- 1 removed
- 16 modified
- 13 copied
-
build/speed/benchmarker.js (modified) (3 diffs)
-
build/speed/index.html (modified) (3 diffs)
-
build/speed/jquery-1.1.2.js (deleted)
-
build/speed/jquery-1.2.1.js (copied) (copied from trunk/jquery/build/speed/jquery-1.2.1.js)
-
build/speed/jquery-basis.js (copied) (copied from trunk/jquery/build/speed/jquery-basis.js)
-
src/ajax.js (modified) (5 diffs)
-
src/core.js (modified) (26 diffs)
-
src/event.js (modified) (9 diffs)
-
src/fx.js (modified) (8 diffs)
-
src/offset.js (modified) (5 diffs)
-
src/selector.js (modified) (6 diffs)
-
test/data/iframe.html (copied) (copied from trunk/jquery/test/data/iframe.html)
-
test/data/json_assigned_obj.js (copied) (copied from trunk/jquery/test/data/json_assigned_obj.js)
-
test/data/offset (copied) (copied from trunk/jquery/test/data/offset)
-
test/data/offset/absolute.html (copied) (copied from trunk/jquery/test/data/offset/absolute.html)
-
test/data/offset/fixed.html (copied) (copied from trunk/jquery/test/data/offset/fixed.html)
-
test/data/offset/relative.html (copied) (copied from trunk/jquery/test/data/offset/relative.html)
-
test/data/offset/scroll.html (copied) (copied from trunk/jquery/test/data/offset/scroll.html)
-
test/data/offset/static.html (copied) (copied from trunk/jquery/test/data/offset/static.html)
-
test/data/offset/table.html (copied) (copied from trunk/jquery/test/data/offset/table.html)
-
test/data/testrunner.js (modified) (1 diff)
-
test/data/testsuite.css (modified) (2 diffs)
-
test/index.html (modified) (3 diffs)
-
test/offset.html (copied) (copied from trunk/jquery/test/offset.html)
-
test/unit/ajax.js (modified) (15 diffs)
-
test/unit/core.js (modified) (36 diffs)
-
test/unit/event.js (modified) (11 diffs)
-
test/unit/fx.js (modified) (4 diffs)
-
test/unit/offset.js (copied) (copied from trunk/jquery/test/unit/offset.js)
-
version.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/event_enhancements/build/speed/benchmarker.js
r2194 r4132 21 21 } catch(e) { } 22 22 }) 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()); 25 25 jQuery.benchmarker.startingList = this.get(); 26 26 benchmark(this.get(), times, jQuery.benchmarker.libraries); … … 34 34 jQuery("td.test").before("<td><input type='checkbox' checked='checked' /></td>"); 35 35 jQuery("button.runTests").bind("click", function() { 36 jQuery('td [input:checked]+ td.test').benchmark();36 jQuery('td:has(input:checked) + td.test').benchmark(); 37 37 }); 38 38 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() }) 40 40 41 41 jQuery("button.selectAll").bind("click", function() { jQuery("input[@type=checkbox]").each(function() { this.checked = true }) }) … … 53 53 }) 54 54 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>" 57 58 }).join(""); 58 59 -
branches/event_enhancements/build/speed/index.html
r2194 r4132 6 6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 7 7 <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> 10 13 <link rel="stylesheet" href="benchmarker.css" type="text/css" media="screen" /> 11 14 </head> … … 16 19 <div id="badid"></div> 17 20 <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> 19 22 <p>NOTE: Number shown is an average.</p> 20 23 <div class="buttons"> … … 503 506 </div> 504 507 <script type="text/javascript" charset="utf-8"> 505 jQuery.benchmarker = {libraries: [" jQOld", "jQuery"]};508 jQuery.benchmarker = {libraries: ["$", "jQuery"]}; 506 509 </script> 507 510 -
branches/event_enhancements/src/ajax.js
r3840 r4132 53 53 res.responseText ); 54 54 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] ); 59 56 } 60 57 }); … … 201 198 s.cache = false; 202 199 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 } 205 207 206 208 // If data is available, append data to url for get requests … … 217 219 218 220 // 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" ) { 221 223 var head = document.getElementsByTagName("head")[0]; 222 224 var script = document.createElement("script"); … … 271 273 272 274 if ( s.global ) 273 jQuery.event.trigger("ajaxSend", [xml, s]);275 jQuery.event.trigger("ajaxSend", [xml, s]); 274 276 275 277 // Wait for a response to come back … … 398 400 httpSuccess: function( r ) { 399 401 try { 402 // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450 400 403 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 || 402 405 jQuery.browser.safari && r.status == undefined; 403 406 } catch(e){} -
branches/event_enhancements/src/core.js
r3856 r4132 15 15 16 16 var 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 ); 21 19 }; 22 20 … … 37 35 selector = selector || document; 38 36 37 // Handle $(DOMElement) 38 if ( selector.nodeType ) { 39 this[0] = selector; 40 this.length = 1; 41 return this; 42 39 43 // Handle HTML strings 40 if ( typeof selector== "string" ) {44 } else if ( typeof selector == "string" ) { 41 45 // Are we dealing with HTML string or an ID? 42 46 var match = quickExpr.exec( selector ); … … 189 193 190 194 css: function( key, value ) { 195 // ignore negative width and height values 196 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 ) 197 value = undefined; 191 198 return this.attr( key, value, "curCSS" ); 192 199 }, … … 194 201 text: function( text ) { 195 202 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 ) ); 197 204 198 205 var ret = ""; … … 243 250 append: function() { 244 251 return this.domManip(arguments, true, false, function(elem){ 245 this.appendChild( elem ); 252 if (this.nodeType == 1) 253 this.appendChild( elem ); 246 254 }); 247 255 }, … … 249 257 prepend: function() { 250 258 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 ); 252 261 }); 253 262 }, … … 282 291 // Do the clone 283 292 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); 287 310 }); 288 311 … … 332 355 333 356 add: function( selector ) { 334 return this.pushStack( jQuery.merge(357 return !selector ? this : this.pushStack( jQuery.merge( 335 358 this.get(), 336 359 selector.constructor == String ? … … 355 378 if ( this.length ) { 356 379 var elem = this[0]; 357 380 358 381 // We need to handle select boxes special 359 382 if ( jQuery.nodeName( elem, "select" ) ) { … … 388 411 // Everything else, we just grab the value 389 412 } else 390 return this[0].value.replace(/\r/g, "");413 return (this[0].value || "").replace(/\r/g, ""); 391 414 392 415 } … … 394 417 } else 395 418 return this.each(function(){ 419 if ( this.nodeType != 1 ) 420 return; 421 396 422 if ( value.constructor == Array && /radio|checkbox/.test( this.type ) ) 397 423 this.checked = (jQuery.inArray(this.value, value) >= 0 || … … 460 486 461 487 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") ); 463 489 464 490 var scripts = jQuery( [] ); … … 469 495 this; 470 496 497 // execute all scripts after the elements have been injected 471 498 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 ); 481 500 } else { 482 501 // Remove any inner scripts for later evaluation … … 493 512 } 494 513 }; 514 515 // Give the init function the jQuery prototype for later instantiation 516 jQuery.prototype.init.prototype = jQuery.prototype; 495 517 496 518 function evalScript( i, elem ) { … … 522 544 523 545 // 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" ) 525 547 target = {}; 526 548 … … 541 563 542 564 // 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 ) 544 566 target[ name ] = jQuery.extend( target[ name ], options[ name ] ); 545 567 … … 583 605 584 606 // Evalulates a script in a global context 585 // Evaluates Async. in Safari 2 :-(586 607 globalEval: function( data ) { 587 608 data = jQuery.trim( data ); … … 715 736 add: function( elem, classNames ) { 716 737 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 ) ) 718 739 elem.className += (elem.className ? " " : "") + className; 719 740 }); … … 722 743 // internal only, use removeClass("class") 723 744 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 ""; 729 751 }, 730 752 … … 750 772 }, 751 773 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; 800 789 } 801 802 return jQuery.curCSS( elem, name );790 791 return jQuery.curCSS( elem, name, force ); 803 792 }, 804 793 … … 910 899 var ret = []; 911 900 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; 912 904 913 905 jQuery.each(elems, function(i, elem){ … … 1004 996 1005 997 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 1006 1002 var fix = jQuery.isXMLDoc( elem ) ? 1007 1003 {} : … … 1034 1030 throw "type property can't be changed"; 1035 1031 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 ); 1037 1034 } 1038 1035 … … 1056 1053 } 1057 1054 1058 return elem.filter ?1055 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ? 1059 1056 (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() : 1060 1057 ""; … … 1256 1253 removeAttr: function( name ) { 1257 1254 jQuery.attr( this, name, "" ); 1258 this.removeAttribute( name ); 1255 if (this.nodeType == 1) 1256 this.removeAttribute( name ); 1259 1257 }, 1260 1258 … … 1316 1314 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater (Mozilla reports scrollWidth the same as offsetWidth) 1317 1315 Math.max( document.body[ "scroll" + name ], document.body[ "offset" + name ] ) : 1318 1316 1319 1317 // Get or set width or height on the element 1320 1318 size == undefined ? -
branches/event_enhancements/src/event.js
r3896 r4132 9 9 // Original by Dean Edwards 10 10 add: function(element, types, handler, data) { 11 if ( element.nodeType == 3 || element.nodeType == 8 ) 12 return; 13 11 14 // For whatever reason, IE has trouble passing the window object 12 15 // around, causing it to be cloned in the process … … 20 23 // if data is passed, bind to handler 21 24 if( data != undefined ) { 22 // Create temporary function pointer to original handler25 // Create temporary function pointer to original handler 23 26 var fn = handler; 24 27 … … 88 91 // Detach an event or set of events from an element 89 92 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 90 97 var events = jQuery.data(element, "events"), ret, index; 91 98 … … 159 166 // Handle triggering a single element 160 167 } else { 168 // don't do events on text and comment nodes 169 if ( element.nodeType == 3 || element.nodeType == 8 ) 170 return; 171 161 172 var val, ret, fn = jQuery.isFunction( element[ type ] || null ), 162 173 // Check to see if we need to provide a fake event, or not … … 183 194 184 195 // 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 } 187 203 188 204 // Trigger the native events (except for clicks on links) 189 205 if ( fn && donative !== false && val !== false && !(jQuery.nodeName(element, 'a') && type == "click") ) { 190 206 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) {} 192 211 } 193 212 … … 280 299 var doc = document.documentElement, body = document.body; 281 300 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); 283 302 } 284 303 … … 503 522 504 523 // and execute the function 505 return args[this.lastToggle].apply( this, [event]) || false;524 return args[this.lastToggle].apply( this, arguments ) || false; 506 525 }); 507 526 }, … …
