Ticket #1731: 1731.2.diff
File 1731.2.diff, 6.5 KB (added by , 15 years ago) |
---|
-
src/core.js
1246 1246 1247 1247 remove: function( selector ) { 1248 1248 if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) { 1249 jQuery.removeData( this ); 1249 // Prevent memory leaks 1250 jQuery( "*", this ).add(this).each(function(){ 1251 jQuery.event.remove(this); 1252 jQuery.removeData(this); 1253 }); 1250 1254 this.parentNode.removeChild( this ); 1251 1255 } 1252 1256 }, 1253 1257 1254 1258 empty: function() { 1255 // Clean up the cache 1256 jQuery( "*", this ).each(function(){ 1257 jQuery.removeData(this); 1258 }); 1259 1259 // Remove element nodes and prevent memory leaks 1260 jQuery( ">*", this ).remove(); 1261 1262 // Remove any remaining nodes 1260 1263 while ( this.firstChild ) 1261 1264 this.removeChild( this.firstChild ); 1262 1265 } -
src/event.js
43 43 // Init the element's event structure 44 44 var events = jQuery.data(element, "events") || jQuery.data(element, "events", {}); 45 45 46 var handle = jQuery.data(element, "handle" , function(){46 var handle = jQuery.data(element, "handle") || jQuery.data(element, "handle", function(){ 47 47 // returned undefined or false 48 48 var val; 49 49 … … 149 149 } else { 150 150 var val, ret, fn = jQuery.isFunction( element[ type ] || null ), 151 151 // Check to see if we need to provide a fake event, or not 152 ev t = !data[0] || !data[0].preventDefault;152 event = !data[0] || !data[0].preventDefault; 153 153 154 154 // Pass along a fake event 155 if ( ev t )155 if ( event ) 156 156 data.unshift( this.fix({ type: type, target: element }) ); 157 157 158 158 // Enforce the right trigger type … … 167 167 val = false; 168 168 169 169 // Extra functions don't get the custom event object 170 if ( ev t )170 if ( event ) 171 171 data.shift(); 172 172 173 173 // Handle triggering of extra function … … 197 197 var parts = event.type.split("."); 198 198 event.type = parts[0]; 199 199 200 var c= jQuery.data(this, "events") && jQuery.data(this, "events")[event.type], args = Array.prototype.slice.call( arguments, 1 );200 var handlers = jQuery.data(this, "events") && jQuery.data(this, "events")[event.type], args = Array.prototype.slice.call( arguments, 1 ); 201 201 args.unshift( event ); 202 202 203 for ( var j in c ) { 203 for ( var j in handlers ) { 204 var handler = handlers[j]; 204 205 // Pass in a reference to the handler function itself 205 206 // So that we can later remove it 206 args[0].handler = c[j];207 args[0].data = c[j].data;207 args[0].handler = handler; 208 args[0].data = handler.data; 208 209 209 210 // Filter the functions by class 210 if ( !parts[1] || c[j].type == parts[1] ) {211 var tmp = c[j].apply( this, args );211 if ( !parts[1] || handler.type == parts[1] ) { 212 var ret = handler.apply( this, args ); 212 213 213 214 if ( val !== false ) 214 val = tmp;215 val = ret; 215 216 216 if ( tmp=== false ) {217 if ( ret === false ) { 217 218 event.preventDefault(); 218 219 event.stopPropagation(); 219 220 } … … 265 266 266 267 // Calculate pageX/Y if missing and clientX/Y available 267 268 if ( event.pageX == null && event.clientX != null ) { 268 var e = document.documentElement, b= document.body;269 event.pageX = event.clientX + ( e && e.scrollLeft || b && b.scrollLeft || 0);270 event.pageY = event.clientY + ( e && e.scrollTop || b && b.scrollTop || 0);269 var doc = document.documentElement, body = document.body; 270 event.pageX = event.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0); 271 event.pageY = event.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0); 271 272 } 272 273 273 274 // Add which for key events … … 322 323 323 324 toggle: function() { 324 325 // Save reference to arguments for access in closure 325 var a = arguments;326 var args = arguments; 326 327 327 return this.click(function(e ) {328 return this.click(function(event) { 328 329 // Figure out which function to execute 329 330 this.lastToggle = 0 == this.lastToggle ? 1 : 0; 330 331 331 332 // Make sure that clicks stop 332 e .preventDefault();333 event.preventDefault(); 333 334 334 335 // and execute the function 335 return a [this.lastToggle].apply( this, [e] ) || false;336 return args[this.lastToggle].apply( this, [event] ) || false; 336 337 }); 337 338 }, 338 339 339 hover: function(f ,g) {340 hover: function(fnOver, fnOut) { 340 341 341 342 // A private function for handling mouse 'hovering' 342 function handleHover(e ) {343 function handleHover(event) { 343 344 // Check if mouse(over|out) are still within the same parent element 344 var p = e.relatedTarget;345 var parent = event.relatedTarget; 345 346 346 347 // Traverse up the tree 347 while ( p && p != this ) try { p = p.parentNode; } catch(e) { p= this; };348 while ( parent && parent != this ) try { parent = parent.parentNode; } catch(error) { parent = this; }; 348 349 349 350 // If we actually just moused on to a sub-element, ignore it 350 if ( p == this ) return false;351 if ( parent == this ) return false; 351 352 352 353 // Execute the right function 353 return (e .type == "mouseover" ? f : g).apply(this, [e]);354 return (event.type == "mouseover" ? fnOver : fnOut).apply(this, [event]); 354 355 } 355 356 356 357 // Bind the function to the two event listeners 357 358 return this.mouseover(handleHover).mouseout(handleHover); 358 359 }, 359 360 360 ready: function(f ) {361 ready: function(fn) { 361 362 // Attach the listeners 362 363 bindReady(); 363 364 364 365 // If the DOM is already ready 365 366 if ( jQuery.isReady ) 366 367 // Execute the function immediately 367 f .apply( document, [jQuery] );368 fn.apply( document, [jQuery] ); 368 369 369 370 // Otherwise, remember the function for later 370 371 else 371 372 // Add the function to the wait list 372 jQuery.readyList.push( function() { return f .apply(this, [jQuery]); } );373 jQuery.readyList.push( function() { return fn.apply(this, [jQuery]); } ); 373 374 374 375 return this; 375 376 } … … 409 410 410 411 jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," + 411 412 "mousedown,mouseup,mousemove,mouseover,mouseout,change,select," + 412 "submit,keydown,keypress,keyup,error").split(","), function(i, o){413 "submit,keydown,keypress,keyup,error").split(","), function(i, name){ 413 414 414 415 // Handle event binding 415 jQuery.fn[ o] = function(f){416 return f ? this.bind(o, f) : this.trigger(o);416 jQuery.fn[name] = function(fn){ 417 return fn ? this.bind(name, fn) : this.trigger(name); 417 418 }; 418 419 }); 419 420 … … 451 452 // A fallback to window.onload, that will always work 452 453 jQuery.event.add( window, "load", jQuery.ready ); 453 454 } 455 456 // Prevent memory leaks in IE 457 if ( jQuery.browser.msie ) 458 jQuery(window).bind("unload", function() { 459 $("*").add([document, window]).unbind(); 460 });