Bug Tracker

Ticket #4402: mousewheel.patch

File mousewheel.patch, 1.6 KB (added by brandon, 14 years ago)

Patch to add mousewheel plugin support to jQuery

  • event.js

     
    464464        };                         
    465465});
    466466
     467var mousewheelTypes = ['DOMMouseScroll', 'mousewheel'];
     468function mousewheelHandler(event) {
     469        var args = [].slice.call( arguments, 1 ), delta = 0, returnValue = true;
     470       
     471        event = jQuery.event.fix(event || window.event);
     472        event.type = "mousewheel";
     473       
     474        if ( event.wheelDelta ) delta = event.wheelDelta/120;
     475        if ( event.detail     ) delta = -event.detail/3;
     476       
     477        // Add events and delta to the front of the arguments
     478        args.unshift(event, delta);
     479
     480        return jQuery.event.handle.apply(this, args);
     481};
     482jQuery.event.special.mousewheel = {
     483        setup: function() {
     484                if ( this.addEventListener )
     485                        for ( var i=types.length; i; )
     486                                this.addEventListener( types[--i], handler, false );
     487                else
     488                        this.onmousewheel = handler;
     489        },
     490       
     491        teardown: function() {
     492                if ( this.removeEventListener )
     493                        for ( var i=types.length; i; )
     494                                this.removeEventListener( types[--i], handler, false );
     495                else
     496                        this.onmousewheel = null;
     497        }
     498};
     499
    467500jQuery.fn.extend({
    468501        bind: function( type, data, fn ) {
    469502                return type == "unload" ? this.one(type, data, fn) : this.each(function(){
     
    665698}
    666699
    667700jQuery.each( ("blur,focus,load,resize,scroll,unload,click,dblclick," +
    668         "mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave," +
     701        "mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,mouseleave,mousewheel" +
    669702        "change,select,submit,keydown,keypress,keyup,error").split(","), function(i, name){
    670703
    671704        // Handle event binding