Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery.event.handle is undocumented and deprecated

I am using a plugin that has this block of code. However i am getting this error

   JQMIGRATE: jQuery.event.handle is undocumented and deprecated

*Cause: jQuery.event.handle was never documented, and deprecated with jQuery 1.7 (see http://forum.jquery.com/topic/deprecated-event-properties-used-in-jquery). As of jQuery 1.9, it has been removed.

Solution: Use documented jQuery APIs, such as .trigger.*

handler: function( event, execAsap ) {
    // Save the context
    var context = this,
        args    = arguments;

    // set correct event type
    event.type = "smartresize";

    if ( resizeTimeout ) { clearTimeout( resizeTimeout ); }
    resizeTimeout = setTimeout(function() {
        jQuery.event.handle.apply( context, args ); //here
    }, execAsap === "execAsap"? 0 : 50 );
}

So, this line will be changed to what?

jQuery.event.handle.apply( context, args );
like image 583
anvd Avatar asked Jun 13 '13 22:06

anvd


2 Answers

I'm guessing context must be the element and args the arguments passed into that custom event, so maybe something like this should work:

$(this).trigger(event, [args]);

I would suggest refactoring the whole thing to use on instead of bind. Then you can trigger custom events defined with on very easily, I don't think using this approach you need to define a custom event so you could make the code a bit smaller.

http://api.jquery.com/on/

like image 94
elclanrs Avatar answered Oct 03 '22 06:10

elclanrs


you could try this: instead of

  jQuery.event.handle.apply( context, args );
  to use

jQuery.event.dispatch.apply( context, args );

this will work fine...

like image 20
venkey Avatar answered Oct 03 '22 06:10

venkey