comparison src/DML/VendorAssetsBundle/Resources/assets/jquery.preventMacBackScroll/modif/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 absX = Math.abs(x);
47 absY = Math.abs(y);
48
49 // If none of the parents can be scrolled left when we try to scroll left
50 prevent_left = (absY <= absX) && x < 0 && !_($(e.target).parents()).detect(function (el) {
51 return $(el).scrollLeft() > 0;
52 });
53
54 // If none of the parents can be scrolled up when we try to scroll up
55 prevent_up = (absX <= absY) && y > 0 && !_($(e.target).parents()).detect(function (el) {
56 return $(el).scrollTop() > 0;
57 });
58
59 // If none of the parents can be scrolled right when we try to scroll right
60 prevent_right = (absY <= absX) && x > 0 && !_($(e.target).parents()).detect(function (el) {
61 var $el = $(el);
62 if ($el.css("overflow") != "scroll") {
63 return false;
64 }
65 var scrollLeft = $el.scrollLeft();
66 var childrenOuterWidth = $el.children().outerWidth();
67 var ownWidth = el.clientWidth;
68 return ownWidth && childrenOuterWidth > ownWidth && childrenOuterWidth - scrollLeft > ownWidth;
69 });
70
71 // Prevent futile scroll, which would trigger the Back/Next page event
72 if (prevent_left || prevent_up || prevent_right) {
73 e.preventDefault();
74 }
75 });
76
77 }
78
79 }(jQuery));