LaravelTest
221 строка · 8.1 Кб
1/*!
2* jQuery Mousewheel 3.1.13
3*
4* Copyright jQuery Foundation and other contributors
5* Released under the MIT license
6* http://jquery.org/license
7*/
8
9(function (factory) {10if ( typeof define === 'function' && define.amd ) {11// AMD. Register as an anonymous module.12define(['jquery'], factory);13} else if (typeof exports === 'object') {14// Node/CommonJS style for Browserify15module.exports = factory;16} else {17// Browser globals18factory(jQuery);19}20}(function ($) {21
22var toFix = ['wheel', 'mousewheel', 'DOMMouseScroll', 'MozMousePixelScroll'],23toBind = ( 'onwheel' in document || document.documentMode >= 9 ) ?24['wheel'] : ['mousewheel', 'DomMouseScroll', 'MozMousePixelScroll'],25slice = Array.prototype.slice,26nullLowestDeltaTimeout, lowestDelta;27
28if ( $.event.fixHooks ) {29for ( var i = toFix.length; i; ) {30$.event.fixHooks[ toFix[--i] ] = $.event.mouseHooks;31}32}33
34var special = $.event.special.mousewheel = {35version: '3.1.12',36
37setup: function() {38if ( this.addEventListener ) {39for ( var i = toBind.length; i; ) {40this.addEventListener( toBind[--i], handler, false );41}42} else {43this.onmousewheel = handler;44}45// Store the line height and page height for this particular element46$.data(this, 'mousewheel-line-height', special.getLineHeight(this));47$.data(this, 'mousewheel-page-height', special.getPageHeight(this));48},49
50teardown: function() {51if ( this.removeEventListener ) {52for ( var i = toBind.length; i; ) {53this.removeEventListener( toBind[--i], handler, false );54}55} else {56this.onmousewheel = null;57}58// Clean up the data we added to the element59$.removeData(this, 'mousewheel-line-height');60$.removeData(this, 'mousewheel-page-height');61},62
63getLineHeight: function(elem) {64var $elem = $(elem),65$parent = $elem['offsetParent' in $.fn ? 'offsetParent' : 'parent']();66if (!$parent.length) {67$parent = $('body');68}69return parseInt($parent.css('fontSize'), 10) || parseInt($elem.css('fontSize'), 10) || 16;70},71
72getPageHeight: function(elem) {73return $(elem).height();74},75
76settings: {77adjustOldDeltas: true, // see shouldAdjustOldDeltas() below78normalizeOffset: true // calls getBoundingClientRect for each event79}80};81
82$.fn.extend({83mousewheel: function(fn) {84return fn ? this.bind('mousewheel', fn) : this.trigger('mousewheel');85},86
87unmousewheel: function(fn) {88return this.unbind('mousewheel', fn);89}90});91
92
93function handler(event) {94var orgEvent = event || window.event,95args = slice.call(arguments, 1),96delta = 0,97deltaX = 0,98deltaY = 0,99absDelta = 0,100offsetX = 0,101offsetY = 0;102event = $.event.fix(orgEvent);103event.type = 'mousewheel';104
105// Old school scrollwheel delta106if ( 'detail' in orgEvent ) { deltaY = orgEvent.detail * -1; }107if ( 'wheelDelta' in orgEvent ) { deltaY = orgEvent.wheelDelta; }108if ( 'wheelDeltaY' in orgEvent ) { deltaY = orgEvent.wheelDeltaY; }109if ( 'wheelDeltaX' in orgEvent ) { deltaX = orgEvent.wheelDeltaX * -1; }110
111// Firefox < 17 horizontal scrolling related to DOMMouseScroll event112if ( 'axis' in orgEvent && orgEvent.axis === orgEvent.HORIZONTAL_AXIS ) {113deltaX = deltaY * -1;114deltaY = 0;115}116
117// Set delta to be deltaY or deltaX if deltaY is 0 for backwards compatabilitiy118delta = deltaY === 0 ? deltaX : deltaY;119
120// New school wheel delta (wheel event)121if ( 'deltaY' in orgEvent ) {122deltaY = orgEvent.deltaY * -1;123delta = deltaY;124}125if ( 'deltaX' in orgEvent ) {126deltaX = orgEvent.deltaX;127if ( deltaY === 0 ) { delta = deltaX * -1; }128}129
130// No change actually happened, no reason to go any further131if ( deltaY === 0 && deltaX === 0 ) { return; }132
133// Need to convert lines and pages to pixels if we aren't already in pixels134// There are three delta modes:135// * deltaMode 0 is by pixels, nothing to do136// * deltaMode 1 is by lines137// * deltaMode 2 is by pages138if ( orgEvent.deltaMode === 1 ) {139var lineHeight = $.data(this, 'mousewheel-line-height');140delta *= lineHeight;141deltaY *= lineHeight;142deltaX *= lineHeight;143} else if ( orgEvent.deltaMode === 2 ) {144var pageHeight = $.data(this, 'mousewheel-page-height');145delta *= pageHeight;146deltaY *= pageHeight;147deltaX *= pageHeight;148}149
150// Store lowest absolute delta to normalize the delta values151absDelta = Math.max( Math.abs(deltaY), Math.abs(deltaX) );152
153if ( !lowestDelta || absDelta < lowestDelta ) {154lowestDelta = absDelta;155
156// Adjust older deltas if necessary157if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {158lowestDelta /= 40;159}160}161
162// Adjust older deltas if necessary163if ( shouldAdjustOldDeltas(orgEvent, absDelta) ) {164// Divide all the things by 40!165delta /= 40;166deltaX /= 40;167deltaY /= 40;168}169
170// Get a whole, normalized value for the deltas171delta = Math[ delta >= 1 ? 'floor' : 'ceil' ](delta / lowestDelta);172deltaX = Math[ deltaX >= 1 ? 'floor' : 'ceil' ](deltaX / lowestDelta);173deltaY = Math[ deltaY >= 1 ? 'floor' : 'ceil' ](deltaY / lowestDelta);174
175// Normalise offsetX and offsetY properties176if ( special.settings.normalizeOffset && this.getBoundingClientRect ) {177var boundingRect = this.getBoundingClientRect();178offsetX = event.clientX - boundingRect.left;179offsetY = event.clientY - boundingRect.top;180}181
182// Add information to the event object183event.deltaX = deltaX;184event.deltaY = deltaY;185event.deltaFactor = lowestDelta;186event.offsetX = offsetX;187event.offsetY = offsetY;188// Go ahead and set deltaMode to 0 since we converted to pixels189// Although this is a little odd since we overwrite the deltaX/Y190// properties with normalized deltas.191event.deltaMode = 0;192
193// Add event and delta to the front of the arguments194args.unshift(event, delta, deltaX, deltaY);195
196// Clearout lowestDelta after sometime to better197// handle multiple device types that give different198// a different lowestDelta199// Ex: trackpad = 3 and mouse wheel = 120200if (nullLowestDeltaTimeout) { clearTimeout(nullLowestDeltaTimeout); }201nullLowestDeltaTimeout = setTimeout(nullLowestDelta, 200);202
203return ($.event.dispatch || $.event.handle).apply(this, args);204}205
206function nullLowestDelta() {207lowestDelta = null;208}209
210function shouldAdjustOldDeltas(orgEvent, absDelta) {211// If this is an older event and the delta is divisable by 120,212// then we are assuming that the browser is treating this as an213// older mouse wheel event and that we should divide the deltas214// by 40 to try and get a more usable deltaFactor.215// Side note, this actually impacts the reported scroll distance216// in older browsers and can cause scrolling to be slower than native.217// Turn this off by setting $.event.special.mousewheel.settings.adjustOldDeltas to false.218return special.settings.adjustOldDeltas && orgEvent.type === 'mousewheel' && absDelta % 120 === 0;219}220
221}));222