comparison src/DML/VendorAssetsBundle/Resources/assets/jquery.preventMacBackScroll/dev/jquery.preventMacBackScroll.js @ 0:493bcb69166c

added public content
author Daniel Wolff
date Tue, 09 Feb 2016 20:54:02 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:493bcb69166c
1 //
2 // Prevent horizontal scroll for Back page in Mac 10.7+
3 //
4 // Mac OSX Lion introduces a nasty behavior: when you are scrolling and
5 // the element (or its parents) are no longer scrollable, then horizontal
6 // scrolling with two fingers will trigger back page or next page.
7 //
8 // For now this plugin provides a way to prevent that behavior for Chrome
9 // in the case you're scrolling up or left where you can't scroll anymore,
10 // which triggers back/next page.
11 //
12 // Supported browsers: Mac OSX Chrome, Mac OSX Safari, Mac OSX Firefox
13 // On all other browsers this script won't do anything
14 //
15 // Depends on: jquery.mousewheel.js
16 //
17 // by Pablo Villalba for http://teambox.com
18 //
19 // Licensed under the MIT License
20 //
21
22 (function ($) {
23
24 // This code is only valid for Mac
25 if (!navigator.userAgent.match(/Macintosh/)) {
26 return;
27 }
28
29 // Detect browsers
30 // http://stackoverflow.com/questions/5899783/detect-safari-using-jquery
31 var is_chrome = navigator.userAgent.indexOf('Chrome') > -1;
32 var is_safari = navigator.userAgent.indexOf("Safari") > -1;
33 var is_firefox = navigator.userAgent.indexOf('Firefox') > -1;
34
35 // Handle scroll events in Chrome, Safari, and Firefox
36 if (is_chrome || is_safari || is_firefox) {
37
38 // TODO: This only prevents scroll when reaching the topmost or leftmost
39 // positions of a container. It doesn't handle rightmost or bottom,
40 // and Lion scroll can be triggered by scrolling right (or bottom) and then
41 // scrolling left without raising your fingers from the scroll position.
42 $(window).mousewheel(function (e, d, x, y) {
43
44 var prevent_left, prevent_up;
45
46 // If none of the parents can be scrolled left when we try to scroll left
47 prevent_left = x < 0 && !_($(e.target).parents()).detect(function (el) {
48 return $(el).scrollLeft() > 0;
49 });
50
51 // If none of the parents can be scrolled up when we try to scroll up
52 prevent_up = y > 0 && !_($(e.target).parents()).detect(function (el) {
53 return $(el).scrollTop() > 0;
54 });
55
56 // Prevent futile scroll, which would trigger the Back/Next page event
57 if (prevent_left || prevent_up) {
58 e.preventDefault();
59 }
60 });
61
62 }
63
64 }(jQuery));