front_idill/lib/jquery.mousewheel-2.0.0.js
author bastiena
Mon, 23 Jul 2012 16:59:35 +0200
changeset 52 277c94533395
permissions -rw-r--r--
Front IDILL : doc updated swipe factorized search bug fixed : when a search is not complete
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
     1
/* Copyright (c) 2011 Brandon Aaron (http://brandonaaron.net)
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
     2
 * Licensed under the MIT License (LICENSE.txt).
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
     3
 *
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
     4
 * Thanks to: Andrew Cobby (@andrewcobby http://github.com/cobbweb)
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
     5
 *              - Refactored for jQuery 1.7+ only
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
     6
 *              - Use MozMousePixelScroll for new Gecko browsers
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
     7
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
     8
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
     9
 * Thanks to: Seamus Leahy for adding deltaX and deltaY
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    10
 *
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    11
 * Version: 2.0.0
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    12
 *
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    13
 * Recommended for jQuery 1.7+
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    14
 * Should work with older versions though
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    15
 */
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    16
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    17
(function($,undefined) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    18
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    19
    var types = ['DOMMouseScroll', 'mousewheel', 'MozMousePixelScroll'];
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    20
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    21
    if ($.event.fixHooks) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    22
        for (var i=types.length; i;) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    23
            $.event.fixHooks[types[--i]] = $.event.mouseHooks;
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    24
        }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    25
    }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    26
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    27
    $.event.special.mousewheel = {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    28
        setup: function() {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    29
            if (this.addEventListener) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    30
                for (var i=types.length; i;) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    31
                    this.addEventListener(types[--i], handler, false);
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    32
                }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    33
            } else {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    34
                this.onmousewheel = handler;
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    35
            }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    36
        },
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    37
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    38
        teardown: function() {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    39
            if (this.removeEventListener) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    40
                for (var i=types.length; i;) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    41
                    this.removeEventListener(types[--i], handler, false);
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    42
                }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    43
            } else {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    44
                this.onmousewheel = null;
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    45
            }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    46
        }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    47
    };
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    48
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    49
    function handler(event) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    50
        var orgEvent = event || window.event, args = [].slice.call(arguments, 1), delta = 0, deltaX = 0, deltaY = 0;
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    51
        event = $.event.fix(orgEvent);
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    52
        event.type = "mousewheel";
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    53
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    54
        // Old school scrollwheel delta
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    55
        if (orgEvent.wheelDelta) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    56
            delta = orgEvent.wheelDelta / 120;
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    57
        }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    58
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    59
        if (orgEvent.detail) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    60
            if (orgEvent.type == types[2]) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    61
                // Firefox 4+, unbind old DOMMouseScroll event
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    62
                this.removeEventListener(types[0], handler, false);
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    63
                delta = -orgEvent.detail / 42;
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    64
            } else {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    65
                delta = -orgEvent.detail / 3;
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    66
            }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    67
        }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    68
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    69
        // New school multidimensional scroll (touchpads) deltas
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    70
        deltaY = delta;
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    71
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    72
        // Gecko
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    73
        if (orgEvent.axis !== undefined && orgEvent.axis === orgEvent.HORIZONTAL_AXIS) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    74
            deltaY = 0;
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    75
            deltaX = -1 * delta;
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    76
        }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    77
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    78
        // Webkit
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    79
        if (orgEvent.wheelDeltaY !== undefined) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    80
            deltaY = orgEvent.wheelDeltaY / 120;
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    81
        }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    82
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    83
        if (orgEvent.wheelDeltaX !== undefined) {
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    84
            deltaX = -1 * orgEvent.wheelDeltaX / 120;
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    85
        }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    86
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    87
        // Add event and delta to the front of the arguments
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    88
        args.unshift(event, delta, deltaX, deltaY);
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    89
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    90
        return ($.event.dispatch || $.event.handle).apply(this, args);
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    91
    }
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    92
277c94533395 Front IDILL :
bastiena
parents:
diff changeset
    93
})(jQuery);