6

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);
}
MJ Khan
  • 1,696
  • 3
  • 21
  • 36
  • 2
    Sounds like you were using something undocumented and internal, and it changed. We might be able to help you if you said what it was you wanted to do (as we won't all be familiar with the undocumented and internal thing you used to use). – T.J. Crowder Mar 27 '13 at 07:47
  • Perhaps you want `$().trigger` – John Dvorak Mar 27 '13 at 07:51
  • @T.J.Crowder .. Thanks for reply... Please have a look at the edits.. – MJ Khan Mar 27 '13 at 08:01
  • 1
    @JanDvorak.. $().trigger is causing error "TypeError: type.indexOf is not a function" at line 2922 (ucompressed jquery.js).. – MJ Khan Mar 27 '13 at 08:08

5 Answers5

10

or you can try:

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

6

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!

2C-B
  • 3,457
  • 1
  • 18
  • 22
  • 1
    Thanks for answering... But I am no longer working on this... so I can not test whether it works... I don't know if I should leave this question as it is, or mark it as closed anyway?!! – MJ Khan Dec 29 '13 at 08:29
  • 1
    tried this in another plugin - did the trick there too. I only wish I knew what it meant :-) – commonpike Mar 04 '15 at 13:03
  • Confirmed swapping dispatch for handle works with this mousewheel mod. Thanks! – Dss Aug 13 '18 at 18:14
0

As you will see here this plugin wasn't longer developped. But it the end of this discussion you have a way to solve some problem :

On line 642 of the plugin js file I have this:

event.type = 'lastclick';
$.event.handle.apply(Me, [event,clicks])

I just changed those two to this:

event.type = 'lastclick';
event.isPropagationStopped = function() { return false };
$.event.handle.apply(Me, [event,clicks])

So, I just reseted the isPropagationStopped and sudently it started working fine!

I hope this will help you.

Francois Borgies
  • 2,378
  • 31
  • 38
0

i Found solution here , i test it and it work fine
Get mouse wheel events in jQuery?

$(document).ready(function(){
    $('#foo').bind('mousewheel', function(e){
        if(e.originalEvent.wheelDelta /120 > 0) {
            $(this).text('scrolling up !');
        }
        else{
           $(this).text('scrolling down !');
        }
    });
});
Community
  • 1
  • 1
msm2020
  • 180
  • 1
  • 10
-3

change this line:

return $.event.handle.apply(this, args);

to:

return jQuery.event.handle.apply(this, args);