1 /* MIT/X Consortium License
3 * Copyright (c) 2011-2012 Stefan Bolte <portix@gmx.net>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 MouseAutoScroll
= (function() {
25 const SCROLL_ICON
="transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAi5QTFRFAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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sjKpoCcXAR5+RRQUIigqJhUS0rLyisQVFZV19TygLr6hsYmBM0trW3tHWzQCf/W1c0GPb1/e18/7yMGBn/70PAI4ZmjY9w+PjFJ/ObUNPaZ2TnyHeYXFr/60vIK5VDM6to6wMbmFkPd9s4u7O0zfHZweHTMCLYPkhas1aCqNgQAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTEtMDQtMDdUMTE6Mjk6MzcrMDI6MDB8AZWGAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDExLTA0LTA3VDExOjI5OjM3KzAyOjAwDVwtOgAAAABJRU5ErkJggg==) no-repeat scroll center";
29 Math
.sign = function(x
) { return x
>=0 ? 1 : -1; };
35 var cursorStyle
= null;
36 function startTimer() {
37 timerId
= window
.setInterval(timer
, 40);
39 function stopTimer () {
40 window
.clearInterval(timerId
);
45 var scrollY
= (ev
.y
- y
);
46 var scrollX
= (ev
.x
- x
);
48 && doc
.documentElement
.scrollHeight
== (window
.innerHeight
+ window
.pageYOffset
);
50 && doc
.documentElement
.scrollWidth
== (window
.innerWidth
+ window
.pageXOffset
);
51 var l
= scrollX
< 0 && window
.pageXOffset
== 0;
52 var t
= scrollY
< 0 && window
.pageYOffset
== 0;
53 var offX
= Math
.abs(scrollX
) < OFFSET
;
54 var offY
= Math
.abs(scrollY
) < OFFSET
;
56 && (( b
&& r
) || ( b
&& l
) || ( b
&& offX
)
57 || ( t
&& r
) || ( t
&& l
) || ( t
&& offX
)
58 || (offY
&& r
) || (offY
&& l
) )) {
62 window
.scrollBy(scrollX
- Math
.sign(scrollX
) * OFFSET
,
63 scrollY
- Math
.sign(scrollY
) * OFFSET
);
66 function mouseMove (e
) {
73 doc
= e
.target
.ownerDocument
;
74 if (window
.innerHeight
>= doc
.documentElement
.scrollHeight
75 && window
.innerWidth
>= doc
.documentElement
.scrollWidth
) {
78 span
= doc
.createElement("div");
79 span
.style
.width
= SIZE
+ "px";
80 span
.style
.height
= SIZE
+ "px";
81 span
.style
.background
= SCROLL_ICON
;
82 span
.style
.left
= e
.x
- (SIZE
/ 2) + "px";
83 span
.style
.top
= e
.y
- (SIZE
/ 2) + "px";
84 span
.style
.position
= "fixed";
85 span
.style
.fontSize
= SIZE
+ "px";
86 span
.style
.opacity
= 0.6;
87 cursorStyle
= doc
.defaultView
.getComputedStyle(doc
.body
, null).cursor
;
88 doc
.body
.style
.cursor
= "move";
89 doc
.body
.appendChild(span
);
90 doc
.addEventListener('mousemove', mouseMove
, false);
94 doc
.body
.style
.cursor
= cursorStyle
;
95 span
.parentNode
.removeChild(span
);
96 doc
.removeEventListener('mousemove', mouseMove
, false);
103 function mouseUp (e
) { /* Simulate click, click event does not work during scrolling */
104 if (Math
.abs(e
.x
- x
) < 5 && Math
.abs(e
.y
- y
) < 5) {
106 window
.removeEventListener('mouseup', mouseUp
, false);
109 function mouseDown (e
) {
115 } else if (e
.button
== 1) {
119 else if (!t
.hasAttribute("href")
120 && !t
.hasAttribute("onmousedown")
121 && !(t
.hasAttribute("onclick"))) {
124 window
.addEventListener('mouseup', mouseUp
, false);
128 window
.addEventListener('mousedown', mouseDown
, false);