Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery 1.9.1 $.event.handle.apply alternative

Tags:

jquery

upgrade

I recently updated one of my project to jQuery 1.9.1, and I can no longer use $.event.handle.apply() method. I've searched and found, that I can place jquery.migrate.js. I just want to confirm if there is any other option? My google-fu is failing here...

--EDIT-- Here is the code (not mine... copied from the plugin) that is causing the issue...

// Event handler function
function mouseWheelHandler(event)
{
    var sentEvent = event || window.event,
        orgEvent = sentEvent.originalEvent || sentEvent,
        args = [].slice.call( arguments, 1 ),
        delta = 0,
        deltaX = 0,
        deltaY = 0;
        event = $.event.fix(orgEvent);
        event.type = "mousewheel";

    // Old school scrollwheel delta
    if ( orgEvent.wheelDelta ) { delta = orgEvent.wheelDelta/120; }
    if ( orgEvent.detail     ) { delta = -orgEvent.detail/3; }

    // New school multidimensional scroll (touchpads) deltas
    deltaY = delta;

    // Gecko
    if ( orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {
        deltaY = 0;
        deltaX = -1*delta;
    }

    // Webkit
    if ( orgEvent.wheelDeltaY !== undefined ) { deltaY = orgEvent.wheelDeltaY/120; }
    if ( orgEvent.wheelDeltaX !== undefined ) { deltaX = -1*orgEvent.wheelDeltaX/120; }

    // Add event and delta to the front of the arguments
    args.unshift(event, delta, deltaX, deltaY);

    return $.event.handle.apply(this, args);
}
like image 266
MJ Khan Avatar asked Mar 27 '13 07:03

MJ Khan


2 Answers

I found this topic while looking for a solution for Infinite Scroll which does not work with jQuery 1.9.* and causes the same error as from the original post.

JQNinja's comment provided a suitable solution: changing the single instance of $.event.handle.apply to $.event.dispatch.apply in the plugin fixes Infinite Scroll. I am assuming it will also fix the original poster's problem.

I understand that modifying a plugin is not ideal, but since it is no longer maintained at the time of writing, I probably don't have to concern myself with updates -- and let's assume that, should maintenance be resumed, this problem will be fixed as well!

like image 29
2C-B Avatar answered Nov 09 '22 19:11

2C-B


or you can try:

$.event.dispatch.call( obj, event );

like image 108
Steve Betonio Avatar answered Nov 09 '22 21:11

Steve Betonio