Version Description
- tested on WP 5.0
- updated scrolling script
Download this release
Release Info
Developer | kubiq |
Plugin | MouseWheel Smooth Scroll |
Version | 5.0 |
Comparing to | |
See all releases |
Code changes from version 4.0 to 5.0
- js/SmoothScroll.js +783 -0
- js/SmoothScroll.min.js +1 -0
- js/wpmss.min.js +1 -1
- languages/wpmss.pot +35 -30
- mousewheel-smooth-scroll.php +276 -211
- readme.txt +45 -41
js/SmoothScroll.js
ADDED
@@ -0,0 +1,783 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
//
|
2 |
+
// SmoothScroll for websites v1.4.8 (Balazs Galambosi)
|
3 |
+
// http://www.smoothscroll.net/
|
4 |
+
// https://github.com/gblazex/smoothscroll-for-websites
|
5 |
+
//
|
6 |
+
// Licensed under the terms of the MIT license.
|
7 |
+
//
|
8 |
+
// You may use it in your theme if you credit me.
|
9 |
+
// It is also free to use on any individual website.
|
10 |
+
//
|
11 |
+
// Exception:
|
12 |
+
// The only restriction is to not publish any
|
13 |
+
// extension for browsers or native application
|
14 |
+
// without getting a written permission first.
|
15 |
+
//
|
16 |
+
|
17 |
+
(function () {
|
18 |
+
|
19 |
+
// Scroll Variables (tweakable)
|
20 |
+
var defaultOptions = {
|
21 |
+
|
22 |
+
// Scrolling Core
|
23 |
+
frameRate : 150, // [Hz]
|
24 |
+
animationTime : 400, // [ms]
|
25 |
+
stepSize : 100, // [px]
|
26 |
+
|
27 |
+
// Pulse (less tweakable)
|
28 |
+
// ratio of "tail" to "acceleration"
|
29 |
+
pulseAlgorithm : true,
|
30 |
+
pulseScale : 4,
|
31 |
+
pulseNormalize : 1,
|
32 |
+
|
33 |
+
// Acceleration
|
34 |
+
accelerationDelta : 50, // 50
|
35 |
+
accelerationMax : 3, // 3
|
36 |
+
|
37 |
+
// Keyboard Settings
|
38 |
+
keyboardSupport : true, // option
|
39 |
+
arrowScroll : 50, // [px]
|
40 |
+
|
41 |
+
// Other
|
42 |
+
fixedBackground : true,
|
43 |
+
excluded : ''
|
44 |
+
};
|
45 |
+
|
46 |
+
var options = defaultOptions;
|
47 |
+
|
48 |
+
|
49 |
+
// Other Variables
|
50 |
+
var isExcluded = false;
|
51 |
+
var isFrame = false;
|
52 |
+
var direction = { x: 0, y: 0 };
|
53 |
+
var initDone = false;
|
54 |
+
var root = document.documentElement;
|
55 |
+
var activeElement;
|
56 |
+
var observer;
|
57 |
+
var refreshSize;
|
58 |
+
var deltaBuffer = [];
|
59 |
+
var deltaBufferTimer;
|
60 |
+
var isMac = /^Mac/.test(navigator.platform);
|
61 |
+
|
62 |
+
var key = { left: 37, up: 38, right: 39, down: 40, spacebar: 32,
|
63 |
+
pageup: 33, pagedown: 34, end: 35, home: 36 };
|
64 |
+
var arrowKeys = { 37: 1, 38: 1, 39: 1, 40: 1 };
|
65 |
+
|
66 |
+
/***********************************************
|
67 |
+
* INITIALIZE
|
68 |
+
***********************************************/
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Tests if smooth scrolling is allowed. Shuts down everything if not.
|
72 |
+
*/
|
73 |
+
function initTest() {
|
74 |
+
if (options.keyboardSupport) {
|
75 |
+
addEvent('keydown', keydown);
|
76 |
+
}
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Sets up scrolls array, determines if frames are involved.
|
81 |
+
*/
|
82 |
+
function init() {
|
83 |
+
|
84 |
+
if (initDone || !document.body) return;
|
85 |
+
|
86 |
+
initDone = true;
|
87 |
+
|
88 |
+
var body = document.body;
|
89 |
+
var html = document.documentElement;
|
90 |
+
var windowHeight = window.innerHeight;
|
91 |
+
var scrollHeight = body.scrollHeight;
|
92 |
+
|
93 |
+
// check compat mode for root element
|
94 |
+
root = (document.compatMode.indexOf('CSS') >= 0) ? html : body;
|
95 |
+
activeElement = body;
|
96 |
+
|
97 |
+
initTest();
|
98 |
+
|
99 |
+
// Checks if this script is running in a frame
|
100 |
+
if (top != self) {
|
101 |
+
isFrame = true;
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Safari 10 fixed it, Chrome fixed it in v45:
|
106 |
+
* This fixes a bug where the areas left and right to
|
107 |
+
* the content does not trigger the onmousewheel event
|
108 |
+
* on some pages. e.g.: html, body { height: 100% }
|
109 |
+
*/
|
110 |
+
else if (isOldSafari &&
|
111 |
+
scrollHeight > windowHeight &&
|
112 |
+
(body.offsetHeight <= windowHeight ||
|
113 |
+
html.offsetHeight <= windowHeight)) {
|
114 |
+
|
115 |
+
var fullPageElem = document.createElement('div');
|
116 |
+
fullPageElem.style.cssText = 'position:absolute; z-index:-10000; ' +
|
117 |
+
'top:0; left:0; right:0; height:' +
|
118 |
+
root.scrollHeight + 'px';
|
119 |
+
document.body.appendChild(fullPageElem);
|
120 |
+
|
121 |
+
// DOM changed (throttled) to fix height
|
122 |
+
var pendingRefresh;
|
123 |
+
refreshSize = function () {
|
124 |
+
if (pendingRefresh) return; // could also be: clearTimeout(pendingRefresh);
|
125 |
+
pendingRefresh = setTimeout(function () {
|
126 |
+
if (isExcluded) return; // could be running after cleanup
|
127 |
+
fullPageElem.style.height = '0';
|
128 |
+
fullPageElem.style.height = root.scrollHeight + 'px';
|
129 |
+
pendingRefresh = null;
|
130 |
+
}, 500); // act rarely to stay fast
|
131 |
+
};
|
132 |
+
|
133 |
+
setTimeout(refreshSize, 10);
|
134 |
+
|
135 |
+
addEvent('resize', refreshSize);
|
136 |
+
|
137 |
+
// TODO: attributeFilter?
|
138 |
+
var config = {
|
139 |
+
attributes: true,
|
140 |
+
childList: true,
|
141 |
+
characterData: false
|
142 |
+
// subtree: true
|
143 |
+
};
|
144 |
+
|
145 |
+
observer = new MutationObserver(refreshSize);
|
146 |
+
observer.observe(body, config);
|
147 |
+
|
148 |
+
if (root.offsetHeight <= windowHeight) {
|
149 |
+
var clearfix = document.createElement('div');
|
150 |
+
clearfix.style.clear = 'both';
|
151 |
+
body.appendChild(clearfix);
|
152 |
+
}
|
153 |
+
}
|
154 |
+
|
155 |
+
// disable fixed background
|
156 |
+
if (!options.fixedBackground && !isExcluded) {
|
157 |
+
body.style.backgroundAttachment = 'scroll';
|
158 |
+
html.style.backgroundAttachment = 'scroll';
|
159 |
+
}
|
160 |
+
}
|
161 |
+
|
162 |
+
/**
|
163 |
+
* Removes event listeners and other traces left on the page.
|
164 |
+
*/
|
165 |
+
function cleanup() {
|
166 |
+
observer && observer.disconnect();
|
167 |
+
removeEvent(wheelEvent, wheel);
|
168 |
+
removeEvent('mousedown', mousedown);
|
169 |
+
removeEvent('keydown', keydown);
|
170 |
+
removeEvent('resize', refreshSize);
|
171 |
+
removeEvent('load', init);
|
172 |
+
}
|
173 |
+
|
174 |
+
|
175 |
+
/************************************************
|
176 |
+
* SCROLLING
|
177 |
+
************************************************/
|
178 |
+
|
179 |
+
var que = [];
|
180 |
+
var pending = false;
|
181 |
+
var lastScroll = Date.now();
|
182 |
+
|
183 |
+
/**
|
184 |
+
* Pushes scroll actions to the scrolling queue.
|
185 |
+
*/
|
186 |
+
function scrollArray(elem, left, top) {
|
187 |
+
|
188 |
+
directionCheck(left, top);
|
189 |
+
|
190 |
+
if (options.accelerationMax != 1) {
|
191 |
+
var now = Date.now();
|
192 |
+
var elapsed = now - lastScroll;
|
193 |
+
if (elapsed < options.accelerationDelta) {
|
194 |
+
var factor = (1 + (50 / elapsed)) / 2;
|
195 |
+
if (factor > 1) {
|
196 |
+
factor = Math.min(factor, options.accelerationMax);
|
197 |
+
left *= factor;
|
198 |
+
top *= factor;
|
199 |
+
}
|
200 |
+
}
|
201 |
+
lastScroll = Date.now();
|
202 |
+
}
|
203 |
+
|
204 |
+
// push a scroll command
|
205 |
+
que.push({
|
206 |
+
x: left,
|
207 |
+
y: top,
|
208 |
+
lastX: (left < 0) ? 0.99 : -0.99,
|
209 |
+
lastY: (top < 0) ? 0.99 : -0.99,
|
210 |
+
start: Date.now()
|
211 |
+
});
|
212 |
+
|
213 |
+
// don't act if there's a pending queue
|
214 |
+
if (pending) {
|
215 |
+
return;
|
216 |
+
}
|
217 |
+
|
218 |
+
var scrollRoot = getScrollRoot();
|
219 |
+
var isWindowScroll = (elem === scrollRoot || elem === document.body);
|
220 |
+
|
221 |
+
// if we haven't already fixed the behavior,
|
222 |
+
// and it needs fixing for this sesh
|
223 |
+
if (elem.$scrollBehavior == null && isScrollBehaviorSmooth(elem)) {
|
224 |
+
elem.$scrollBehavior = elem.style.scrollBehavior;
|
225 |
+
elem.style.scrollBehavior = 'auto';
|
226 |
+
}
|
227 |
+
|
228 |
+
var step = function (time) {
|
229 |
+
|
230 |
+
var now = Date.now();
|
231 |
+
var scrollX = 0;
|
232 |
+
var scrollY = 0;
|
233 |
+
|
234 |
+
for (var i = 0; i < que.length; i++) {
|
235 |
+
|
236 |
+
var item = que[i];
|
237 |
+
var elapsed = now - item.start;
|
238 |
+
var finished = (elapsed >= options.animationTime);
|
239 |
+
|
240 |
+
// scroll position: [0, 1]
|
241 |
+
var position = (finished) ? 1 : elapsed / options.animationTime;
|
242 |
+
|
243 |
+
// easing [optional]
|
244 |
+
if (options.pulseAlgorithm) {
|
245 |
+
position = pulse(position);
|
246 |
+
}
|
247 |
+
|
248 |
+
// only need the difference
|
249 |
+
var x = (item.x * position - item.lastX) >> 0;
|
250 |
+
var y = (item.y * position - item.lastY) >> 0;
|
251 |
+
|
252 |
+
// add this to the total scrolling
|
253 |
+
scrollX += x;
|
254 |
+
scrollY += y;
|
255 |
+
|
256 |
+
// update last values
|
257 |
+
item.lastX += x;
|
258 |
+
item.lastY += y;
|
259 |
+
|
260 |
+
// delete and step back if it's over
|
261 |
+
if (finished) {
|
262 |
+
que.splice(i, 1); i--;
|
263 |
+
}
|
264 |
+
}
|
265 |
+
|
266 |
+
// scroll left and top
|
267 |
+
if (isWindowScroll) {
|
268 |
+
window.scrollBy(scrollX, scrollY);
|
269 |
+
}
|
270 |
+
else {
|
271 |
+
if (scrollX) elem.scrollLeft += scrollX;
|
272 |
+
if (scrollY) elem.scrollTop += scrollY;
|
273 |
+
}
|
274 |
+
|
275 |
+
// clean up if there's nothing left to do
|
276 |
+
if (!left && !top) {
|
277 |
+
que = [];
|
278 |
+
}
|
279 |
+
|
280 |
+
if (que.length) {
|
281 |
+
requestFrame(step, elem, (1000 / options.frameRate + 1));
|
282 |
+
} else {
|
283 |
+
pending = false;
|
284 |
+
// restore default behavior at the end of scrolling sesh
|
285 |
+
if (elem.$scrollBehavior != null) {
|
286 |
+
elem.style.scrollBehavior = elem.$scrollBehavior;
|
287 |
+
elem.$scrollBehavior = null;
|
288 |
+
}
|
289 |
+
}
|
290 |
+
};
|
291 |
+
|
292 |
+
// start a new queue of actions
|
293 |
+
requestFrame(step, elem, 0);
|
294 |
+
pending = true;
|
295 |
+
}
|
296 |
+
|
297 |
+
|
298 |
+
/***********************************************
|
299 |
+
* EVENTS
|
300 |
+
***********************************************/
|
301 |
+
|
302 |
+
/**
|
303 |
+
* Mouse wheel handler.
|
304 |
+
* @param {Object} event
|
305 |
+
*/
|
306 |
+
function wheel(event) {
|
307 |
+
|
308 |
+
if (!initDone) {
|
309 |
+
init();
|
310 |
+
}
|
311 |
+
|
312 |
+
var target = event.target;
|
313 |
+
|
314 |
+
// leave early if default action is prevented
|
315 |
+
// or it's a zooming event with CTRL
|
316 |
+
if (event.defaultPrevented || event.ctrlKey) {
|
317 |
+
return true;
|
318 |
+
}
|
319 |
+
|
320 |
+
// leave embedded content alone (flash & pdf)
|
321 |
+
if (isNodeName(activeElement, 'embed') ||
|
322 |
+
(isNodeName(target, 'embed') && /\.pdf/i.test(target.src)) ||
|
323 |
+
isNodeName(activeElement, 'object') ||
|
324 |
+
target.shadowRoot) {
|
325 |
+
return true;
|
326 |
+
}
|
327 |
+
|
328 |
+
var deltaX = -event.wheelDeltaX || event.deltaX || 0;
|
329 |
+
var deltaY = -event.wheelDeltaY || event.deltaY || 0;
|
330 |
+
|
331 |
+
if (isMac) {
|
332 |
+
if (event.wheelDeltaX && isDivisible(event.wheelDeltaX, 120)) {
|
333 |
+
deltaX = -120 * (event.wheelDeltaX / Math.abs(event.wheelDeltaX));
|
334 |
+
}
|
335 |
+
if (event.wheelDeltaY && isDivisible(event.wheelDeltaY, 120)) {
|
336 |
+
deltaY = -120 * (event.wheelDeltaY / Math.abs(event.wheelDeltaY));
|
337 |
+
}
|
338 |
+
}
|
339 |
+
|
340 |
+
// use wheelDelta if deltaX/Y is not available
|
341 |
+
if (!deltaX && !deltaY) {
|
342 |
+
deltaY = -event.wheelDelta || 0;
|
343 |
+
}
|
344 |
+
|
345 |
+
// line based scrolling (Firefox mostly)
|
346 |
+
if (event.deltaMode === 1) {
|
347 |
+
deltaX *= 40;
|
348 |
+
deltaY *= 40;
|
349 |
+
}
|
350 |
+
|
351 |
+
var overflowing = overflowingAncestor(target);
|
352 |
+
|
353 |
+
// nothing to do if there's no element that's scrollable
|
354 |
+
if (!overflowing) {
|
355 |
+
// except Chrome iframes seem to eat wheel events, which we need to
|
356 |
+
// propagate up, if the iframe has nothing overflowing to scroll
|
357 |
+
if (isFrame && isChrome) {
|
358 |
+
// change target to iframe element itself for the parent frame
|
359 |
+
Object.defineProperty(event, "target", {value: window.frameElement});
|
360 |
+
return parent.wheel(event);
|
361 |
+
}
|
362 |
+
return true;
|
363 |
+
}
|
364 |
+
|
365 |
+
// check if it's a touchpad scroll that should be ignored
|
366 |
+
if (isTouchpad(deltaY)) {
|
367 |
+
return true;
|
368 |
+
}
|
369 |
+
|
370 |
+
// scale by step size
|
371 |
+
// delta is 120 most of the time
|
372 |
+
// synaptics seems to send 1 sometimes
|
373 |
+
if (Math.abs(deltaX) > 1.2) {
|
374 |
+
deltaX *= options.stepSize / 120;
|
375 |
+
}
|
376 |
+
if (Math.abs(deltaY) > 1.2) {
|
377 |
+
deltaY *= options.stepSize / 120;
|
378 |
+
}
|
379 |
+
|
380 |
+
scrollArray(overflowing, deltaX, deltaY);
|
381 |
+
event.preventDefault();
|
382 |
+
scheduleClearCache();
|
383 |
+
}
|
384 |
+
|
385 |
+
/**
|
386 |
+
* Keydown event handler.
|
387 |
+
* @param {Object} event
|
388 |
+
*/
|
389 |
+
function keydown(event) {
|
390 |
+
|
391 |
+
var target = event.target;
|
392 |
+
var modifier = event.ctrlKey || event.altKey || event.metaKey ||
|
393 |
+
(event.shiftKey && event.keyCode !== key.spacebar);
|
394 |
+
|
395 |
+
// our own tracked active element could've been removed from the DOM
|
396 |
+
if (!document.body.contains(activeElement)) {
|
397 |
+
activeElement = document.activeElement;
|
398 |
+
}
|
399 |
+
|
400 |
+
// do nothing if user is editing text
|
401 |
+
// or using a modifier key (except shift)
|
402 |
+
// or in a dropdown
|
403 |
+
// or inside interactive elements
|
404 |
+
var inputNodeNames = /^(textarea|select|embed|object)$/i;
|
405 |
+
var buttonTypes = /^(button|submit|radio|checkbox|file|color|image)$/i;
|
406 |
+
if ( event.defaultPrevented ||
|
407 |
+
inputNodeNames.test(target.nodeName) ||
|
408 |
+
isNodeName(target, 'input') && !buttonTypes.test(target.type) ||
|
409 |
+
isNodeName(activeElement, 'video') ||
|
410 |
+
isInsideYoutubeVideo(event) ||
|
411 |
+
target.isContentEditable ||
|
412 |
+
modifier ) {
|
413 |
+
return true;
|
414 |
+
}
|
415 |
+
|
416 |
+
// [spacebar] should trigger button press, leave it alone
|
417 |
+
if ((isNodeName(target, 'button') ||
|
418 |
+
isNodeName(target, 'input') && buttonTypes.test(target.type)) &&
|
419 |
+
event.keyCode === key.spacebar) {
|
420 |
+
return true;
|
421 |
+
}
|
422 |
+
|
423 |
+
// [arrwow keys] on radio buttons should be left alone
|
424 |
+
if (isNodeName(target, 'input') && target.type == 'radio' &&
|
425 |
+
arrowKeys[event.keyCode]) {
|
426 |
+
return true;
|
427 |
+
}
|
428 |
+
|
429 |
+
var shift, x = 0, y = 0;
|
430 |
+
var overflowing = overflowingAncestor(activeElement);
|
431 |
+
|
432 |
+
if (!overflowing) {
|
433 |
+
// Chrome iframes seem to eat key events, which we need to
|
434 |
+
// propagate up, if the iframe has nothing overflowing to scroll
|
435 |
+
return (isFrame && isChrome) ? parent.keydown(event) : true;
|
436 |
+
}
|
437 |
+
|
438 |
+
var clientHeight = overflowing.clientHeight;
|
439 |
+
|
440 |
+
if (overflowing == document.body) {
|
441 |
+
clientHeight = window.innerHeight;
|
442 |
+
}
|
443 |
+
|
444 |
+
switch (event.keyCode) {
|
445 |
+
case key.up:
|
446 |
+
y = -options.arrowScroll;
|
447 |
+
break;
|
448 |
+
case key.down:
|
449 |
+
y = options.arrowScroll;
|
450 |
+
break;
|
451 |
+
case key.spacebar: // (+ shift)
|
452 |
+
shift = event.shiftKey ? 1 : -1;
|
453 |
+
y = -shift * clientHeight * 0.9;
|
454 |
+
break;
|
455 |
+
case key.pageup:
|
456 |
+
y = -clientHeight * 0.9;
|
457 |
+
break;
|
458 |
+
case key.pagedown:
|
459 |
+
y = clientHeight * 0.9;
|
460 |
+
break;
|
461 |
+
case key.home:
|
462 |
+
if (overflowing == document.body && document.scrollingElement)
|
463 |
+
overflowing = document.scrollingElement;
|
464 |
+
y = -overflowing.scrollTop;
|
465 |
+
break;
|
466 |
+
case key.end:
|
467 |
+
var scroll = overflowing.scrollHeight - overflowing.scrollTop;
|
468 |
+
var scrollRemaining = scroll - clientHeight;
|
469 |
+
y = (scrollRemaining > 0) ? scrollRemaining + 10 : 0;
|
470 |
+
break;
|
471 |
+
case key.left:
|
472 |
+
x = -options.arrowScroll;
|
473 |
+
break;
|
474 |
+
case key.right:
|
475 |
+
x = options.arrowScroll;
|
476 |
+
break;
|
477 |
+
default:
|
478 |
+
return true; // a key we don't care about
|
479 |
+
}
|
480 |
+
|
481 |
+
scrollArray(overflowing, x, y);
|
482 |
+
event.preventDefault();
|
483 |
+
scheduleClearCache();
|
484 |
+
}
|
485 |
+
|
486 |
+
/**
|
487 |
+
* Mousedown event only for updating activeElement
|
488 |
+
*/
|
489 |
+
function mousedown(event) {
|
490 |
+
activeElement = event.target;
|
491 |
+
}
|
492 |
+
|
493 |
+
|
494 |
+
/***********************************************
|
495 |
+
* OVERFLOW
|
496 |
+
***********************************************/
|
497 |
+
|
498 |
+
var uniqueID = (function () {
|
499 |
+
var i = 0;
|
500 |
+
return function (el) {
|
501 |
+
return el.uniqueID || (el.uniqueID = i++);
|
502 |
+
};
|
503 |
+
})();
|
504 |
+
|
505 |
+
var cacheX = {}; // cleared out after a scrolling session
|
506 |
+
var cacheY = {}; // cleared out after a scrolling session
|
507 |
+
var clearCacheTimer;
|
508 |
+
var smoothBehaviorForElement = {};
|
509 |
+
|
510 |
+
//setInterval(function () { cache = {}; }, 10 * 1000);
|
511 |
+
|
512 |
+
function scheduleClearCache() {
|
513 |
+
clearTimeout(clearCacheTimer);
|
514 |
+
clearCacheTimer = setInterval(function () {
|
515 |
+
cacheX = cacheY = smoothBehaviorForElement = {};
|
516 |
+
}, 1*1000);
|
517 |
+
}
|
518 |
+
|
519 |
+
function setCache(elems, overflowing, x) {
|
520 |
+
var cache = x ? cacheX : cacheY;
|
521 |
+
for (var i = elems.length; i--;)
|
522 |
+
cache[uniqueID(elems[i])] = overflowing;
|
523 |
+
return overflowing;
|
524 |
+
}
|
525 |
+
|
526 |
+
function getCache(el, x) {
|
527 |
+
return (x ? cacheX : cacheY)[uniqueID(el)];
|
528 |
+
}
|
529 |
+
|
530 |
+
// (body) (root)
|
531 |
+
// | hidden | visible | scroll | auto |
|
532 |
+
// hidden | no | no | YES | YES |
|
533 |
+
// visible | no | YES | YES | YES |
|
534 |
+
// scroll | no | YES | YES | YES |
|
535 |
+
// auto | no | YES | YES | YES |
|
536 |
+
|
537 |
+
function overflowingAncestor(el) {
|
538 |
+
var elems = [];
|
539 |
+
var body = document.body;
|
540 |
+
var rootScrollHeight = root.scrollHeight;
|
541 |
+
do {
|
542 |
+
var cached = getCache(el, false);
|
543 |
+
if (cached) {
|
544 |
+
return setCache(elems, cached);
|
545 |
+
}
|
546 |
+
elems.push(el);
|
547 |
+
if (rootScrollHeight === el.scrollHeight) {
|
548 |
+
var topOverflowsNotHidden = overflowNotHidden(root) && overflowNotHidden(body);
|
549 |
+
var isOverflowCSS = topOverflowsNotHidden || overflowAutoOrScroll(root);
|
550 |
+
if (isFrame && isContentOverflowing(root) ||
|
551 |
+
!isFrame && isOverflowCSS) {
|
552 |
+
return setCache(elems, getScrollRoot());
|
553 |
+
}
|
554 |
+
} else if (isContentOverflowing(el) && overflowAutoOrScroll(el)) {
|
555 |
+
return setCache(elems, el);
|
556 |
+
}
|
557 |
+
} while ((el = el.parentElement));
|
558 |
+
}
|
559 |
+
|
560 |
+
function isContentOverflowing(el) {
|
561 |
+
return (el.clientHeight + 10 < el.scrollHeight);
|
562 |
+
}
|
563 |
+
|
564 |
+
// typically for <body> and <html>
|
565 |
+
function overflowNotHidden(el) {
|
566 |
+
var overflow = getComputedStyle(el, '').getPropertyValue('overflow-y');
|
567 |
+
return (overflow !== 'hidden');
|
568 |
+
}
|
569 |
+
|
570 |
+
// for all other elements
|
571 |
+
function overflowAutoOrScroll(el) {
|
572 |
+
var overflow = getComputedStyle(el, '').getPropertyValue('overflow-y');
|
573 |
+
return (overflow === 'scroll' || overflow === 'auto');
|
574 |
+
}
|
575 |
+
|
576 |
+
// for all other elements
|
577 |
+
function isScrollBehaviorSmooth(el) {
|
578 |
+
var id = uniqueID(el);
|
579 |
+
if (smoothBehaviorForElement[id] == null) {
|
580 |
+
var scrollBehavior = getComputedStyle(el, '')['scroll-behavior'];
|
581 |
+
smoothBehaviorForElement[id] = ('smooth' == scrollBehavior);
|
582 |
+
}
|
583 |
+
return smoothBehaviorForElement[id];
|
584 |
+
}
|
585 |
+
|
586 |
+
|
587 |
+
/***********************************************
|
588 |
+
* HELPERS
|
589 |
+
***********************************************/
|
590 |
+
|
591 |
+
function addEvent(type, fn) {
|
592 |
+
window.addEventListener(type, fn, false);
|
593 |
+
}
|
594 |
+
|
595 |
+
function removeEvent(type, fn) {
|
596 |
+
window.removeEventListener(type, fn, false);
|
597 |
+
}
|
598 |
+
|
599 |
+
function isNodeName(el, tag) {
|
600 |
+
return el && (el.nodeName||'').toLowerCase() === tag.toLowerCase();
|
601 |
+
}
|
602 |
+
|
603 |
+
function directionCheck(x, y) {
|
604 |
+
x = (x > 0) ? 1 : -1;
|
605 |
+
y = (y > 0) ? 1 : -1;
|
606 |
+
if (direction.x !== x || direction.y !== y) {
|
607 |
+
direction.x = x;
|
608 |
+
direction.y = y;
|
609 |
+
que = [];
|
610 |
+
lastScroll = 0;
|
611 |
+
}
|
612 |
+
}
|
613 |
+
|
614 |
+
if (window.localStorage && localStorage.SS_deltaBuffer) {
|
615 |
+
try { // #46 Safari throws in private browsing for localStorage
|
616 |
+
deltaBuffer = localStorage.SS_deltaBuffer.split(',');
|
617 |
+
} catch (e) { }
|
618 |
+
}
|
619 |
+
|
620 |
+
function isTouchpad(deltaY) {
|
621 |
+
if (!deltaY) return;
|
622 |
+
if (!deltaBuffer.length) {
|
623 |
+
deltaBuffer = [deltaY, deltaY, deltaY];
|
624 |
+
}
|
625 |
+
deltaY = Math.abs(deltaY);
|
626 |
+
deltaBuffer.push(deltaY);
|
627 |
+
deltaBuffer.shift();
|
628 |
+
clearTimeout(deltaBufferTimer);
|
629 |
+
deltaBufferTimer = setTimeout(function () {
|
630 |
+
try { // #46 Safari throws in private browsing for localStorage
|
631 |
+
localStorage.SS_deltaBuffer = deltaBuffer.join(',');
|
632 |
+
} catch (e) { }
|
633 |
+
}, 1000);
|
634 |
+
var dpiScaledWheelDelta = deltaY > 120 && allDeltasDivisableBy(deltaY); // win64
|
635 |
+
return !allDeltasDivisableBy(120) && !allDeltasDivisableBy(100) && !dpiScaledWheelDelta;
|
636 |
+
}
|
637 |
+
|
638 |
+
function isDivisible(n, divisor) {
|
639 |
+
return (Math.floor(n / divisor) == n / divisor);
|
640 |
+
}
|
641 |
+
|
642 |
+
function allDeltasDivisableBy(divisor) {
|
643 |
+
return (isDivisible(deltaBuffer[0], divisor) &&
|
644 |
+
isDivisible(deltaBuffer[1], divisor) &&
|
645 |
+
isDivisible(deltaBuffer[2], divisor));
|
646 |
+
}
|
647 |
+
|
648 |
+
function isInsideYoutubeVideo(event) {
|
649 |
+
var elem = event.target;
|
650 |
+
var isControl = false;
|
651 |
+
if (document.URL.indexOf ('www.youtube.com/watch') != -1) {
|
652 |
+
do {
|
653 |
+
isControl = (elem.classList &&
|
654 |
+
elem.classList.contains('html5-video-controls'));
|
655 |
+
if (isControl) break;
|
656 |
+
} while ((elem = elem.parentNode));
|
657 |
+
}
|
658 |
+
return isControl;
|
659 |
+
}
|
660 |
+
|
661 |
+
var requestFrame = (function () {
|
662 |
+
return (window.requestAnimationFrame ||
|
663 |
+
window.webkitRequestAnimationFrame ||
|
664 |
+
window.mozRequestAnimationFrame ||
|
665 |
+
function (callback, element, delay) {
|
666 |
+
window.setTimeout(callback, delay || (1000/60));
|
667 |
+
});
|
668 |
+
})();
|
669 |
+
|
670 |
+
var MutationObserver = (window.MutationObserver ||
|
671 |
+
window.WebKitMutationObserver ||
|
672 |
+
window.MozMutationObserver);
|
673 |
+
|
674 |
+
var getScrollRoot = (function() {
|
675 |
+
var SCROLL_ROOT = document.scrollingElement;
|
676 |
+
return function() {
|
677 |
+
if (!SCROLL_ROOT) {
|
678 |
+
var dummy = document.createElement('div');
|
679 |
+
dummy.style.cssText = 'height:10000px;width:1px;';
|
680 |
+
document.body.appendChild(dummy);
|
681 |
+
var bodyScrollTop = document.body.scrollTop;
|
682 |
+
var docElScrollTop = document.documentElement.scrollTop;
|
683 |
+
window.scrollBy(0, 3);
|
684 |
+
if (document.body.scrollTop != bodyScrollTop)
|
685 |
+
(SCROLL_ROOT = document.body);
|
686 |
+
else
|
687 |
+
(SCROLL_ROOT = document.documentElement);
|
688 |
+
window.scrollBy(0, -3);
|
689 |
+
document.body.removeChild(dummy);
|
690 |
+
}
|
691 |
+
return SCROLL_ROOT;
|
692 |
+
};
|
693 |
+
})();
|
694 |
+
|
695 |
+
|
696 |
+
/***********************************************
|
697 |
+
* PULSE (by Michael Herf)
|
698 |
+
***********************************************/
|
699 |
+
|
700 |
+
/**
|
701 |
+
* Viscous fluid with a pulse for part and decay for the rest.
|
702 |
+
* - Applies a fixed force over an interval (a damped acceleration), and
|
703 |
+
* - Lets the exponential bleed away the velocity over a longer interval
|
704 |
+
* - Michael Herf, http://stereopsis.com/stopping/
|
705 |
+
*/
|
706 |
+
function pulse_(x) {
|
707 |
+
var val, start, expx;
|
708 |
+
// test
|
709 |
+
x = x * options.pulseScale;
|
710 |
+
if (x < 1) { // acceleartion
|
711 |
+
val = x - (1 - Math.exp(-x));
|
712 |
+
} else { // tail
|
713 |
+
// the previous animation ended here:
|
714 |
+
start = Math.exp(-1);
|
715 |
+
// simple viscous drag
|
716 |
+
x -= 1;
|
717 |
+
expx = 1 - Math.exp(-x);
|
718 |
+
val = start + (expx * (1 - start));
|
719 |
+
}
|
720 |
+
return val * options.pulseNormalize;
|
721 |
+
}
|
722 |
+
|
723 |
+
function pulse(x) {
|
724 |
+
if (x >= 1) return 1;
|
725 |
+
if (x <= 0) return 0;
|
726 |
+
|
727 |
+
if (options.pulseNormalize == 1) {
|
728 |
+
options.pulseNormalize /= pulse_(1);
|
729 |
+
}
|
730 |
+
return pulse_(x);
|
731 |
+
}
|
732 |
+
|
733 |
+
|
734 |
+
/***********************************************
|
735 |
+
* FIRST RUN
|
736 |
+
***********************************************/
|
737 |
+
|
738 |
+
var userAgent = window.navigator.userAgent;
|
739 |
+
var isEdge = /Edge/.test(userAgent); // thank you MS
|
740 |
+
var isChrome = /chrome/i.test(userAgent) && !isEdge;
|
741 |
+
var isSafari = /safari/i.test(userAgent) && !isEdge;
|
742 |
+
var isMobile = /mobile/i.test(userAgent);
|
743 |
+
var isIEWin7 = /Windows NT 6.1/i.test(userAgent) && /rv:11/i.test(userAgent);
|
744 |
+
var isOldSafari = isSafari && (/Version\/8/i.test(userAgent) || /Version\/9/i.test(userAgent));
|
745 |
+
var isEnabledForBrowser = !isMobile;
|
746 |
+
|
747 |
+
var wheelEvent;
|
748 |
+
if ('onwheel' in document.createElement('div'))
|
749 |
+
wheelEvent = 'wheel';
|
750 |
+
else if ('onmousewheel' in document.createElement('div'))
|
751 |
+
wheelEvent = 'mousewheel';
|
752 |
+
|
753 |
+
if (wheelEvent && isEnabledForBrowser) {
|
754 |
+
addEvent(wheelEvent, wheel);
|
755 |
+
addEvent('mousedown', mousedown);
|
756 |
+
addEvent('load', init);
|
757 |
+
}
|
758 |
+
|
759 |
+
|
760 |
+
/***********************************************
|
761 |
+
* PUBLIC INTERFACE
|
762 |
+
***********************************************/
|
763 |
+
|
764 |
+
function SmoothScroll(optionsToSet) {
|
765 |
+
for (var key in optionsToSet)
|
766 |
+
if (defaultOptions.hasOwnProperty(key))
|
767 |
+
options[key] = optionsToSet[key];
|
768 |
+
}
|
769 |
+
SmoothScroll.destroy = cleanup;
|
770 |
+
|
771 |
+
if (window.SmoothScrollOptions) // async API
|
772 |
+
SmoothScroll(window.SmoothScrollOptions);
|
773 |
+
|
774 |
+
if (typeof define === 'function' && define.amd)
|
775 |
+
define(function() {
|
776 |
+
return SmoothScroll;
|
777 |
+
});
|
778 |
+
else if ('object' == typeof exports)
|
779 |
+
module.exports = SmoothScroll;
|
780 |
+
else
|
781 |
+
window.SmoothScroll = SmoothScroll;
|
782 |
+
|
783 |
+
})();
|
js/SmoothScroll.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
!function(){function e(){L.keyboardSupport&&w("keydown",a)}function t(){if(!A&&document.body){A=!0;var t=document.body,o=document.documentElement,n=window.innerHeight,r=t.scrollHeight;if(N=document.compatMode.indexOf("CSS")>=0?o:t,E=t,e(),top!=self)X=!0;else if(re&&r>n&&(t.offsetHeight<=n||o.offsetHeight<=n)){var a=document.createElement("div");a.style.cssText="position:absolute; z-index:-10000; top:0; left:0; right:0; height:"+N.scrollHeight+"px",document.body.appendChild(a);var i;B=function(){i||(i=setTimeout(function(){O||(a.style.height="0",a.style.height=N.scrollHeight+"px",i=null)},500))},setTimeout(B,10),w("resize",B);var l={attributes:!0,childList:!0,characterData:!1};if(T=new J(B),T.observe(t,l),N.offsetHeight<=n){var c=document.createElement("div");c.style.clear="both",t.appendChild(c)}}L.fixedBackground||O||(t.style.backgroundAttachment="scroll",o.style.backgroundAttachment="scroll")}}function o(){T&&T.disconnect(),p(U,r),p("mousedown",i),p("keydown",a),p("resize",B),p("load",t)}function n(e,t,o){if(y(t,o),1!=L.accelerationMax){var n=Date.now(),r=n-V;if(r<L.accelerationDelta){var a=(1+50/r)/2;a>1&&(a=Math.min(a,L.accelerationMax),t*=a,o*=a)}V=Date.now()}if(j.push({x:t,y:o,lastX:t<0?.99:-.99,lastY:o<0?.99:-.99,start:Date.now()}),!q){var i=Q(),l=e===i||e===document.body;null==e.$scrollBehavior&&h(e)&&(e.$scrollBehavior=e.style.scrollBehavior,e.style.scrollBehavior="auto");var c=function(n){for(var r=Date.now(),a=0,i=0,u=0;u<j.length;u++){var s=j[u],d=r-s.start,f=d>=L.animationTime,m=f?1:d/L.animationTime;L.pulseAlgorithm&&(m=D(m));var h=s.x*m-s.lastX>>0,w=s.y*m-s.lastY>>0;a+=h,i+=w,s.lastX+=h,s.lastY+=w,f&&(j.splice(u,1),u--)}l?window.scrollBy(a,i):(a&&(e.scrollLeft+=a),i&&(e.scrollTop+=i)),t||o||(j=[]),j.length?G(c,e,1e3/L.frameRate+1):(q=!1,null!=e.$scrollBehavior&&(e.style.scrollBehavior=e.$scrollBehavior,e.$scrollBehavior=null))};G(c,e,0),q=!0}}function r(e){A||t();var o=e.target;if(e.defaultPrevented||e.ctrlKey)return!0;if(v(E,"embed")||v(o,"embed")&&/\.pdf/i.test(o.src)||v(E,"object")||o.shadowRoot)return!0;var r=-e.wheelDeltaX||e.deltaX||0,a=-e.wheelDeltaY||e.deltaY||0;$&&(e.wheelDeltaX&&g(e.wheelDeltaX,120)&&(r=-120*(e.wheelDeltaX/Math.abs(e.wheelDeltaX))),e.wheelDeltaY&&g(e.wheelDeltaY,120)&&(a=-120*(e.wheelDeltaY/Math.abs(e.wheelDeltaY)))),r||a||(a=-e.wheelDelta||0),1===e.deltaMode&&(r*=40,a*=40);var i=s(o);return i?!!b(a)||(Math.abs(r)>1.2&&(r*=L.stepSize/120),Math.abs(a)>1.2&&(a*=L.stepSize/120),n(i,r,a),e.preventDefault(),void l()):!X||!te||(Object.defineProperty(e,"target",{value:window.frameElement}),parent.wheel(e))}function a(e){var t=e.target,o=e.ctrlKey||e.altKey||e.metaKey||e.shiftKey&&e.keyCode!==P.spacebar;document.body.contains(E)||(E=document.activeElement);var r=/^(textarea|select|embed|object)$/i,a=/^(button|submit|radio|checkbox|file|color|image)$/i;if(e.defaultPrevented||r.test(t.nodeName)||v(t,"input")&&!a.test(t.type)||v(E,"video")||x(e)||t.isContentEditable||o)return!0;if((v(t,"button")||v(t,"input")&&a.test(t.type))&&e.keyCode===P.spacebar)return!0;if(v(t,"input")&&"radio"==t.type&&R[e.keyCode])return!0;var i,c=0,u=0,d=s(E);if(!d)return!X||!te||parent.keydown(e);var f=d.clientHeight;switch(d==document.body&&(f=window.innerHeight),e.keyCode){case P.up:u=-L.arrowScroll;break;case P.down:u=L.arrowScroll;break;case P.spacebar:i=e.shiftKey?1:-1,u=-i*f*.9;break;case P.pageup:u=.9*-f;break;case P.pagedown:u=.9*f;break;case P.home:d==document.body&&document.scrollingElement&&(d=document.scrollingElement),u=-d.scrollTop;break;case P.end:var m=d.scrollHeight-d.scrollTop,h=m-f;u=h>0?h+10:0;break;case P.left:c=-L.arrowScroll;break;case P.right:c=L.arrowScroll;break;default:return!0}n(d,c,u),e.preventDefault(),l()}function i(e){E=e.target}function l(){clearTimeout(H),H=setInterval(function(){I=_=W={}},1e3)}function c(e,t,o){for(var n=o?I:_,r=e.length;r--;)n[F(e[r])]=t;return t}function u(e,t){return(t?I:_)[F(e)]}function s(e){var t=[],o=document.body,n=N.scrollHeight;do{var r=u(e,!1);if(r)return c(t,r);if(t.push(e),n===e.scrollHeight){var a=f(N)&&f(o),i=a||m(N);if(X&&d(N)||!X&&i)return c(t,Q())}else if(d(e)&&m(e))return c(t,e)}while(e=e.parentElement)}function d(e){return e.clientHeight+10<e.scrollHeight}function f(e){var t=getComputedStyle(e,"").getPropertyValue("overflow-y");return"hidden"!==t}function m(e){var t=getComputedStyle(e,"").getPropertyValue("overflow-y");return"scroll"===t||"auto"===t}function h(e){var t=F(e);if(null==W[t]){var o=getComputedStyle(e,"")["scroll-behavior"];W[t]="smooth"==o}return W[t]}function w(e,t){window.addEventListener(e,t,!1)}function p(e,t){window.removeEventListener(e,t,!1)}function v(e,t){return e&&(e.nodeName||"").toLowerCase()===t.toLowerCase()}function y(e,t){e=e>0?1:-1,t=t>0?1:-1,Y.x===e&&Y.y===t||(Y.x=e,Y.y=t,j=[],V=0)}function b(e){if(e){K.length||(K=[e,e,e]),e=Math.abs(e),K.push(e),K.shift(),clearTimeout(C),C=setTimeout(function(){try{localStorage.SS_deltaBuffer=K.join(",")}catch(e){}},1e3);var t=e>120&&S(e);return!S(120)&&!S(100)&&!t}}function g(e,t){return Math.floor(e/t)==e/t}function S(e){return g(K[0],e)&&g(K[1],e)&&g(K[2],e)}function x(e){var t=e.target,o=!1;if(document.URL.indexOf("www.youtube.com/watch")!=-1)do if(o=t.classList&&t.classList.contains("html5-video-controls"))break;while(t=t.parentNode);return o}function k(e){var t,o,n;return e*=L.pulseScale,e<1?t=e-(1-Math.exp(-e)):(o=Math.exp(-1),e-=1,n=1-Math.exp(-e),t=o+n*(1-o)),t*L.pulseNormalize}function D(e){return e>=1?1:e<=0?0:(1==L.pulseNormalize&&(L.pulseNormalize/=k(1)),k(e))}function M(e){for(var t in e)z.hasOwnProperty(t)&&(L[t]=e[t])}var E,T,B,C,H,z={frameRate:150,animationTime:400,stepSize:100,pulseAlgorithm:!0,pulseScale:4,pulseNormalize:1,accelerationDelta:50,accelerationMax:3,keyboardSupport:!0,arrowScroll:50,fixedBackground:!0,excluded:""},L=z,O=!1,X=!1,Y={x:0,y:0},A=!1,N=document.documentElement,K=[],$=/^Mac/.test(navigator.platform),P={left:37,up:38,right:39,down:40,spacebar:32,pageup:33,pagedown:34,end:35,home:36},R={37:1,38:1,39:1,40:1},j=[],q=!1,V=Date.now(),F=function(){var e=0;return function(t){return t.uniqueID||(t.uniqueID=e++)}}(),I={},_={},W={};if(window.localStorage&&localStorage.SS_deltaBuffer)try{K=localStorage.SS_deltaBuffer.split(",")}catch(e){}var U,G=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(e,t,o){window.setTimeout(e,o||1e3/60)}}(),J=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver,Q=function(){var e=document.scrollingElement;return function(){if(!e){var t=document.createElement("div");t.style.cssText="height:10000px;width:1px;",document.body.appendChild(t);var o=document.body.scrollTop;document.documentElement.scrollTop;window.scrollBy(0,3),e=document.body.scrollTop!=o?document.body:document.documentElement,window.scrollBy(0,-3),document.body.removeChild(t)}return e}}(),Z=window.navigator.userAgent,ee=/Edge/.test(Z),te=/chrome/i.test(Z)&&!ee,oe=/safari/i.test(Z)&&!ee,ne=/mobile/i.test(Z),re=(/Windows NT 6.1/i.test(Z)&&/rv:11/i.test(Z),oe&&(/Version\/8/i.test(Z)||/Version\/9/i.test(Z))),ae=!ne;"onwheel"in document.createElement("div")?U="wheel":"onmousewheel"in document.createElement("div")&&(U="mousewheel"),U&&ae&&(w(U,r),w("mousedown",i),w("load",t)),M.destroy=o,window.SmoothScrollOptions&&M(window.SmoothScrollOptions),"function"==typeof define&&define.amd?define(function(){return M}):"object"==typeof exports?module.exports=M:window.SmoothScroll=M}();
|
js/wpmss.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
|
1 |
+
SmoothScroll({frameRate:150,animationTime:1000,stepSize:100,pulseAlgorithm:1,pulseScale:4,pulseNormalize:1,accelerationDelta:50,accelerationMax:3,keyboardSupport:1,arrowScroll:50,touchpadSupport:0,fixedBackground:1})
|
languages/wpmss.pot
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
msgid ""
|
3 |
msgstr ""
|
4 |
"Project-Id-Version: MouseWheel Smooth Scroll\n"
|
5 |
-
"POT-Creation-Date: 2018-
|
6 |
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
7 |
"Last-Translator: Ing. Jakub Novák <info@kubiq.sk>\n"
|
8 |
"Language-Team: KubiQ <info@kubiq.sk>\n"
|
@@ -18,81 +18,86 @@ msgstr ""
|
|
18 |
"X-Poedit-SearchPath-0: .\n"
|
19 |
"X-Poedit-SearchPath-1: ./.."
|
20 |
|
21 |
-
#: mousewheel-smooth-scroll.php:
|
22 |
msgid "Smooth Scroll"
|
23 |
msgstr ""
|
24 |
|
25 |
-
#: mousewheel-smooth-scroll.php:
|
26 |
msgid "MouseWheel Smooth Scroll"
|
27 |
msgstr ""
|
28 |
|
29 |
-
#: mousewheel-smooth-scroll.php:
|
30 |
-
msgid ""
|
31 |
-
"Feel free to experiment with these settings, you can simply reset them to "
|
32 |
-
"defaults by deleting fields values"
|
33 |
-
msgstr ""
|
34 |
-
|
35 |
-
#: mousewheel-smooth-scroll.php:132
|
36 |
msgid "Scrolling Core"
|
37 |
msgstr ""
|
38 |
|
39 |
-
#: mousewheel-smooth-scroll.php:
|
40 |
msgid "frameRate"
|
41 |
msgstr ""
|
42 |
|
43 |
-
#: mousewheel-smooth-scroll.php:
|
44 |
msgid "animationTime"
|
45 |
msgstr ""
|
46 |
|
47 |
-
#: mousewheel-smooth-scroll.php:
|
48 |
msgid "stepSize"
|
49 |
msgstr ""
|
50 |
|
51 |
-
#: mousewheel-smooth-scroll.php:
|
52 |
msgid "Pulse (less tweakable)<br>ratio of \"tail\" to \"acceleration\""
|
53 |
msgstr ""
|
54 |
|
55 |
-
#: mousewheel-smooth-scroll.php:
|
|
|
|
|
|
|
|
|
56 |
msgid "pulseScale"
|
57 |
msgstr ""
|
58 |
|
59 |
-
#: mousewheel-smooth-scroll.php:
|
60 |
msgid "pulseNormalize"
|
61 |
msgstr ""
|
62 |
|
63 |
-
#: mousewheel-smooth-scroll.php:
|
64 |
msgid "Acceleration"
|
65 |
msgstr ""
|
66 |
|
67 |
-
#: mousewheel-smooth-scroll.php:
|
68 |
msgid "accelerationDelta"
|
69 |
msgstr ""
|
70 |
|
71 |
-
#: mousewheel-smooth-scroll.php:
|
72 |
msgid "accelerationMax"
|
73 |
msgstr ""
|
74 |
|
75 |
-
#: mousewheel-smooth-scroll.php:
|
76 |
msgid "Keyboard Settings"
|
77 |
msgstr ""
|
78 |
|
79 |
-
#: mousewheel-smooth-scroll.php:
|
|
|
|
|
|
|
|
|
80 |
msgid "arrowScroll"
|
81 |
msgstr ""
|
82 |
|
83 |
-
#: mousewheel-smooth-scroll.php:
|
84 |
-
msgid "
|
85 |
msgstr ""
|
86 |
|
87 |
-
|
88 |
-
msgid "
|
89 |
msgstr ""
|
90 |
|
91 |
-
|
92 |
-
|
93 |
-
msgid "https://kubiq.sk"
|
94 |
msgstr ""
|
95 |
|
96 |
-
|
97 |
-
msgid "
|
|
|
|
|
|
|
|
|
98 |
msgstr ""
|
2 |
msgid ""
|
3 |
msgstr ""
|
4 |
"Project-Id-Version: MouseWheel Smooth Scroll\n"
|
5 |
+
"POT-Creation-Date: 2018-12-09 11:13+0000\n"
|
6 |
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
7 |
"Last-Translator: Ing. Jakub Novák <info@kubiq.sk>\n"
|
8 |
"Language-Team: KubiQ <info@kubiq.sk>\n"
|
18 |
"X-Poedit-SearchPath-0: .\n"
|
19 |
"X-Poedit-SearchPath-1: ./.."
|
20 |
|
21 |
+
#: mousewheel-smooth-scroll.php:37 mousewheel-smooth-scroll.php:38
|
22 |
msgid "Smooth Scroll"
|
23 |
msgstr ""
|
24 |
|
25 |
+
#: mousewheel-smooth-scroll.php:122
|
26 |
msgid "MouseWheel Smooth Scroll"
|
27 |
msgstr ""
|
28 |
|
29 |
+
#: mousewheel-smooth-scroll.php:145
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
msgid "Scrolling Core"
|
31 |
msgstr ""
|
32 |
|
33 |
+
#: mousewheel-smooth-scroll.php:150
|
34 |
msgid "frameRate"
|
35 |
msgstr ""
|
36 |
|
37 |
+
#: mousewheel-smooth-scroll.php:159
|
38 |
msgid "animationTime"
|
39 |
msgstr ""
|
40 |
|
41 |
+
#: mousewheel-smooth-scroll.php:168
|
42 |
msgid "stepSize"
|
43 |
msgstr ""
|
44 |
|
45 |
+
#: mousewheel-smooth-scroll.php:178
|
46 |
msgid "Pulse (less tweakable)<br>ratio of \"tail\" to \"acceleration\""
|
47 |
msgstr ""
|
48 |
|
49 |
+
#: mousewheel-smooth-scroll.php:183
|
50 |
+
msgid "pulseAlgorithm"
|
51 |
+
msgstr ""
|
52 |
+
|
53 |
+
#: mousewheel-smooth-scroll.php:192
|
54 |
msgid "pulseScale"
|
55 |
msgstr ""
|
56 |
|
57 |
+
#: mousewheel-smooth-scroll.php:201
|
58 |
msgid "pulseNormalize"
|
59 |
msgstr ""
|
60 |
|
61 |
+
#: mousewheel-smooth-scroll.php:211
|
62 |
msgid "Acceleration"
|
63 |
msgstr ""
|
64 |
|
65 |
+
#: mousewheel-smooth-scroll.php:216
|
66 |
msgid "accelerationDelta"
|
67 |
msgstr ""
|
68 |
|
69 |
+
#: mousewheel-smooth-scroll.php:225
|
70 |
msgid "accelerationMax"
|
71 |
msgstr ""
|
72 |
|
73 |
+
#: mousewheel-smooth-scroll.php:235
|
74 |
msgid "Keyboard Settings"
|
75 |
msgstr ""
|
76 |
|
77 |
+
#: mousewheel-smooth-scroll.php:240
|
78 |
+
msgid "keyboardSupport"
|
79 |
+
msgstr ""
|
80 |
+
|
81 |
+
#: mousewheel-smooth-scroll.php:249
|
82 |
msgid "arrowScroll"
|
83 |
msgstr ""
|
84 |
|
85 |
+
#: mousewheel-smooth-scroll.php:259
|
86 |
+
msgid "Other"
|
87 |
msgstr ""
|
88 |
|
89 |
+
#: mousewheel-smooth-scroll.php:264
|
90 |
+
msgid "touchpadSupport"
|
91 |
msgstr ""
|
92 |
|
93 |
+
#: mousewheel-smooth-scroll.php:273
|
94 |
+
msgid "fixedBackground"
|
|
|
95 |
msgstr ""
|
96 |
|
97 |
+
#: mousewheel-smooth-scroll.php:285
|
98 |
+
msgid "Any ideas, problems, issues?"
|
99 |
+
msgstr ""
|
100 |
+
|
101 |
+
#. Description of the plugin
|
102 |
+
msgid "MouseWheel smooth scrolling for your WordPress website"
|
103 |
msgstr ""
|
mousewheel-smooth-scroll.php
CHANGED
@@ -3,234 +3,299 @@
|
|
3 |
Plugin Name: MouseWheel Smooth Scroll
|
4 |
Plugin URI: https://kubiq.sk
|
5 |
Description: MouseWheel smooth scrolling for your WordPress website
|
6 |
-
Version:
|
7 |
Author: KubiQ
|
8 |
Author URI: https://kubiq.sk
|
9 |
Text Domain: wpmss
|
10 |
Domain Path: /languages
|
11 |
*/
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
}
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
$this->settings['general']['
|
54 |
-
|
55 |
-
$this->settings['general']['stepSize'] = isset( $this->settings['general']['stepSize'] ) && trim( $this->settings['general']['stepSize'] ) ? intval( $this->settings['general']['stepSize'] ) : 100;
|
56 |
-
$this->settings['general']['pulseScale'] = isset( $this->settings['general']['pulseScale'] ) && trim( $this->settings['general']['pulseScale'] ) ? intval( $this->settings['general']['pulseScale'] ) : 4;
|
57 |
-
$this->settings['general']['pulseNormalize'] = isset( $this->settings['general']['pulseNormalize'] ) && trim( $this->settings['general']['pulseNormalize'] ) ? intval( $this->settings['general']['pulseNormalize'] ) : 1;
|
58 |
-
$this->settings['general']['accelerationDelta'] = isset( $this->settings['general']['accelerationDelta'] ) && trim( $this->settings['general']['accelerationDelta'] ) ? intval( $this->settings['general']['accelerationDelta'] ) : 50;
|
59 |
-
$this->settings['general']['accelerationMax'] = isset( $this->settings['general']['accelerationMax'] ) && trim( $this->settings['general']['accelerationMax'] ) ? intval( $this->settings['general']['accelerationMax'] ) : 3;
|
60 |
-
$this->settings['general']['arrowScroll'] = isset( $this->settings['general']['arrowScroll'] ) && trim( $this->settings['general']['arrowScroll'] ) ? intval( $this->settings['general']['arrowScroll'] ) : 50;
|
61 |
-
add_action( 'wp_enqueue_scripts', array( $this, 'plugin_scripts_load' ) );
|
62 |
}
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
function plugin_admin_tabs( $current = 'general' ) {
|
69 |
-
$tabs = array( 'general' => __('General'), 'info' => __('Help') ); ?>
|
70 |
-
<h2 class="nav-tab-wrapper">
|
71 |
-
<?php foreach( $tabs as $tab => $name ){ ?>
|
72 |
-
<a class="nav-tab <?php echo ( $tab == $current ) ? "nav-tab-active" : "" ?>" href="?page=<?php echo basename( __FILE__ ) ?>&tab=<?php echo $tab ?>"><?php echo $name ?></a>
|
73 |
-
<?php } ?>
|
74 |
-
</h2><br><?php
|
75 |
-
}
|
76 |
|
77 |
-
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
|
|
|
|
91 |
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
<
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
<h3><?php _e( 'Scrolling Core', 'wpmss' ) ?></h3>
|
133 |
-
</th>
|
134 |
-
</tr>
|
135 |
-
<tr>
|
136 |
-
<th>
|
137 |
-
<label for="q_field_1"><?php _e( 'frameRate', 'wpmss' ) ?>:</label>
|
138 |
-
</th>
|
139 |
-
<td>
|
140 |
-
<input type="number" name="frameRate" placeholder="150" value="<?php echo $this->settings[ $this->tab ]['frameRate'] ?>" id="q_field_1">
|
141 |
-
[Hz]
|
142 |
-
</td>
|
143 |
-
</tr>
|
144 |
-
<tr>
|
145 |
-
<th>
|
146 |
-
<label for="q_field_2"><?php _e( 'animationTime', 'wpmss' ) ?>:</label>
|
147 |
-
</th>
|
148 |
-
<td>
|
149 |
-
<input type="number" name="animationTime" placeholder="1000" value="<?php echo $this->settings[ $this->tab ]['animationTime'] ?>" id="q_field_2">
|
150 |
-
[ms]
|
151 |
-
</td>
|
152 |
-
</tr>
|
153 |
-
<tr>
|
154 |
-
<th>
|
155 |
-
<label for="q_field_3"><?php _e( 'stepSize', 'wpmss' ) ?>:</label>
|
156 |
-
</th>
|
157 |
-
<td>
|
158 |
-
<input type="number" name="stepSize" placeholder="100" value="<?php echo $this->settings[ $this->tab ]['stepSize'] ?>" id="q_field_3">
|
159 |
-
[px]
|
160 |
-
</td>
|
161 |
-
</tr>
|
162 |
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
</
|
175 |
-
</
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
|
|
|
|
184 |
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
</
|
197 |
-
</
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
|
|
|
|
206 |
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
231 |
}
|
232 |
}
|
233 |
|
234 |
-
|
235 |
-
$wpmss = new wpmss();
|
236 |
-
}
|
3 |
Plugin Name: MouseWheel Smooth Scroll
|
4 |
Plugin URI: https://kubiq.sk
|
5 |
Description: MouseWheel smooth scrolling for your WordPress website
|
6 |
+
Version: 5.0
|
7 |
Author: KubiQ
|
8 |
Author URI: https://kubiq.sk
|
9 |
Text Domain: wpmss
|
10 |
Domain Path: /languages
|
11 |
*/
|
12 |
|
13 |
+
class wpmss{
|
14 |
+
var $plugin_admin_page;
|
15 |
+
var $settings;
|
16 |
+
var $tab;
|
17 |
+
|
18 |
+
function __construct(){
|
19 |
+
add_action( 'plugins_loaded', array( $this, 'plugins_loaded' ) );
|
20 |
+
add_action( 'admin_menu', array( $this, 'plugin_menu_link' ) );
|
21 |
+
add_action( 'init', array( $this, 'plugin_init' ) );
|
22 |
+
}
|
|
|
23 |
|
24 |
+
function plugins_loaded(){
|
25 |
+
load_plugin_textdomain( 'wpmss', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
|
26 |
+
}
|
27 |
+
|
28 |
+
function filter_plugin_actions( $links, $file ){
|
29 |
+
$settings_link = '<a href="options-general.php?page=' . basename( __FILE__ ) . '">' . __('Settings') . '</a>';
|
30 |
+
array_unshift( $links, $settings_link );
|
31 |
+
return $links;
|
32 |
+
}
|
33 |
+
|
34 |
+
function plugin_menu_link(){
|
35 |
+
$this->plugin_admin_page = add_submenu_page(
|
36 |
+
'options-general.php',
|
37 |
+
__( 'Smooth Scroll', 'wpmss' ),
|
38 |
+
__( 'Smooth Scroll', 'wpmss' ),
|
39 |
+
'manage_options',
|
40 |
+
basename( __FILE__ ),
|
41 |
+
array( $this, 'admin_options_page' )
|
42 |
+
);
|
43 |
+
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array( $this, 'filter_plugin_actions' ), 10, 2 );
|
44 |
+
}
|
45 |
+
|
46 |
+
function plugin_init(){
|
47 |
+
$this->settings = get_option('wpmss_settings');
|
48 |
+
if( ! isset( $this->settings['general']['timestamp'] ) ){
|
49 |
+
$this->settings['general']['timestamp'] = time();
|
50 |
+
$this->settings['general']['pulseAlgorithm'] = 1;
|
51 |
+
$this->settings['general']['keyboardSupport'] = 1;
|
52 |
+
$this->settings['general']['fixedBackground'] = 1;
|
53 |
+
update_option( 'wpmss_settings', $this->settings );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
}
|
55 |
|
56 |
+
$this->process_settings();
|
57 |
+
|
58 |
+
add_action( 'wp_enqueue_scripts', array( $this, 'plugin_scripts_load' ) );
|
59 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
function process_settings(){
|
62 |
+
$this->settings['general']['frameRate'] = isset( $this->settings['general']['frameRate'] ) && trim( $this->settings['general']['frameRate'] ) ? intval( $this->settings['general']['frameRate'] ) : 150;
|
63 |
+
$this->settings['general']['animationTime'] = isset( $this->settings['general']['animationTime'] ) && trim( $this->settings['general']['animationTime'] ) ? intval( $this->settings['general']['animationTime'] ) : 1000;
|
64 |
+
$this->settings['general']['stepSize'] = isset( $this->settings['general']['stepSize'] ) && trim( $this->settings['general']['stepSize'] ) ? intval( $this->settings['general']['stepSize'] ) : 100;
|
65 |
+
$this->settings['general']['pulseAlgorithm'] = isset( $this->settings['general']['pulseAlgorithm'] ) ? 1 : 0;
|
66 |
+
$this->settings['general']['pulseScale'] = isset( $this->settings['general']['pulseScale'] ) && trim( $this->settings['general']['pulseScale'] ) ? intval( $this->settings['general']['pulseScale'] ) : 4;
|
67 |
+
$this->settings['general']['pulseNormalize'] = isset( $this->settings['general']['pulseNormalize'] ) && trim( $this->settings['general']['pulseNormalize'] ) ? intval( $this->settings['general']['pulseNormalize'] ) : 1;
|
68 |
+
$this->settings['general']['accelerationDelta'] = isset( $this->settings['general']['accelerationDelta'] ) && trim( $this->settings['general']['accelerationDelta'] ) ? intval( $this->settings['general']['accelerationDelta'] ) : 50;
|
69 |
+
$this->settings['general']['accelerationMax'] = isset( $this->settings['general']['accelerationMax'] ) && trim( $this->settings['general']['accelerationMax'] ) ? intval( $this->settings['general']['accelerationMax'] ) : 3;
|
70 |
+
$this->settings['general']['keyboardSupport'] = isset( $this->settings['general']['keyboardSupport'] ) ? 1 : 0;
|
71 |
+
$this->settings['general']['arrowScroll'] = isset( $this->settings['general']['arrowScroll'] ) && trim( $this->settings['general']['arrowScroll'] ) ? intval( $this->settings['general']['arrowScroll'] ) : 50;
|
72 |
+
$this->settings['general']['touchpadSupport'] = isset( $this->settings['general']['touchpadSupport'] ) ? 1 : 0;
|
73 |
+
$this->settings['general']['fixedBackground'] = isset( $this->settings['general']['fixedBackground'] ) ? 1 : 0;
|
74 |
+
}
|
75 |
|
76 |
+
function plugin_scripts_load(){
|
77 |
+
wp_enqueue_script( 'SmoothScroll', plugins_url( 'js/SmoothScroll.min.js', __FILE__ ), array('jquery'), '1.4.8', 1 );
|
78 |
+
wp_enqueue_script( 'wpmss_script', plugins_url( 'js/wpmss.min.js', __FILE__ ), array('jquery'), $this->settings['general']['timestamp'], 1 );
|
79 |
+
}
|
80 |
+
|
81 |
+
function plugin_admin_tabs( $current = 'general' ){
|
82 |
+
$tabs = array( 'general' => __('General'), 'info' => __('Help') ); ?>
|
83 |
+
<h2 class="nav-tab-wrapper">
|
84 |
+
<?php foreach( $tabs as $tab => $name ){ ?>
|
85 |
+
<a class="nav-tab <?php echo ( $tab == $current ) ? "nav-tab-active" : "" ?>" href="?page=<?php echo basename( __FILE__ ) ?>&tab=<?php echo $tab ?>"><?php echo $name ?></a>
|
86 |
+
<?php } ?>
|
87 |
+
</h2><br><?php
|
88 |
+
}
|
89 |
|
90 |
+
function save_js_config(){
|
91 |
+
$content = sprintf('SmoothScroll({'.
|
92 |
+
'frameRate:%d,'.
|
93 |
+
'animationTime:%d,'.
|
94 |
+
'stepSize:%d,'.
|
95 |
+
'pulseAlgorithm:%d,'.
|
96 |
+
'pulseScale:%d,'.
|
97 |
+
'pulseNormalize:%d,'.
|
98 |
+
'accelerationDelta:%d,'.
|
99 |
+
'accelerationMax:%d,'.
|
100 |
+
'keyboardSupport:%d,'.
|
101 |
+
'arrowScroll:%d,'.
|
102 |
+
'touchpadSupport:%d,'.
|
103 |
+
'fixedBackground:%d'.
|
104 |
+
'})',
|
105 |
+
intval( $this->settings['general']['frameRate'] ),
|
106 |
+
intval( $this->settings['general']['animationTime'] ),
|
107 |
+
intval( $this->settings['general']['stepSize'] ),
|
108 |
+
intval( $this->settings['general']['pulseAlgorithm'] ),
|
109 |
+
intval( $this->settings['general']['pulseScale'] ),
|
110 |
+
intval( $this->settings['general']['pulseNormalize'] ),
|
111 |
+
intval( $this->settings['general']['accelerationDelta'] ),
|
112 |
+
intval( $this->settings['general']['accelerationMax'] ),
|
113 |
+
intval( $this->settings['general']['keyboardSupport'] ),
|
114 |
+
intval( $this->settings['general']['arrowScroll'] ),
|
115 |
+
intval( $this->settings['general']['touchpadSupport'] ),
|
116 |
+
intval( $this->settings['general']['fixedBackground'] )
|
117 |
+
);
|
118 |
+
file_put_contents( __DIR__ . '/js/wpmss.min.js', $content );
|
119 |
+
}
|
120 |
|
121 |
+
function admin_options_page(){
|
122 |
+
if( get_current_screen()->id != $this->plugin_admin_page ) return;
|
123 |
+
$this->tab = isset( $_GET['tab'] ) ? $_GET['tab'] : 'general';
|
124 |
+
if( isset( $_POST['plugin_sent'] ) ){
|
125 |
+
$this->settings[ $this->tab ] = $_POST;
|
126 |
+
update_option( 'wpmss_settings', $this->settings );
|
127 |
+
$this->process_settings();
|
128 |
+
$this->save_js_config();
|
129 |
+
} ?>
|
130 |
+
<div class="wrap">
|
131 |
+
<h2><?php _e( 'MouseWheel Smooth Scroll', 'wpmss' ); ?></h2>
|
132 |
+
<?php if( isset( $_POST['plugin_sent'] ) ) echo '<div id="message" class="below-h2 updated"><p>' . __('Settings saved.') . '</p></div>' ?>
|
133 |
+
<form method="post" action="<?php admin_url( 'options-general.php?page=' . basename( __FILE__ ) ) ?>">
|
134 |
+
<input type="hidden" name="plugin_sent" value="1"><?php
|
135 |
+
$this->plugin_admin_tabs( $this->tab );
|
136 |
+
switch( $this->tab ):
|
137 |
+
case 'general':
|
138 |
+
$this->plugin_general_options();
|
139 |
+
break;
|
140 |
+
case 'info':
|
141 |
+
$this->plugin_info_options();
|
142 |
+
break;
|
143 |
+
endswitch; ?>
|
144 |
+
</form>
|
145 |
+
</div><?php
|
146 |
+
}
|
147 |
+
|
148 |
+
function plugin_general_options(){ ?>
|
149 |
+
<style>.default{color:#a0a5aa}</style>
|
150 |
+
<input type="hidden" name="timestamp" value="<?php echo time() ?>">
|
151 |
+
<table class="form-table">
|
152 |
+
<tr>
|
153 |
+
<th colspan="2">
|
154 |
+
<h3><?php _e( 'Scrolling Core', 'wpmss' ) ?></h3>
|
155 |
+
</th>
|
156 |
+
</tr>
|
157 |
+
<tr>
|
158 |
+
<th>
|
159 |
+
<label for="q_field_1"><?php _e( 'frameRate', 'wpmss' ) ?>:</label>
|
160 |
+
</th>
|
161 |
+
<td>
|
162 |
+
<input type="number" name="frameRate" placeholder="150" value="<?php echo $this->settings[ $this->tab ]['frameRate'] ?>" id="q_field_1">
|
163 |
+
[Hz] <small class="default">default: 150</small>
|
164 |
+
</td>
|
165 |
+
</tr>
|
166 |
+
<tr>
|
167 |
+
<th>
|
168 |
+
<label for="q_field_2"><?php _e( 'animationTime', 'wpmss' ) ?>:</label>
|
169 |
+
</th>
|
170 |
+
<td>
|
171 |
+
<input type="number" name="animationTime" placeholder="1000" value="<?php echo $this->settings[ $this->tab ]['animationTime'] ?>" id="q_field_2">
|
172 |
+
[ms] <small class="default">default: 1000</small>
|
173 |
+
</td>
|
174 |
+
</tr>
|
175 |
+
<tr>
|
176 |
+
<th>
|
177 |
+
<label for="q_field_3"><?php _e( 'stepSize', 'wpmss' ) ?>:</label>
|
178 |
+
</th>
|
179 |
+
<td>
|
180 |
+
<input type="number" name="stepSize" placeholder="100" value="<?php echo $this->settings[ $this->tab ]['stepSize'] ?>" id="q_field_3">
|
181 |
+
[px] <small class="default">default: 100</small>
|
182 |
+
</td>
|
183 |
+
</tr>
|
184 |
|
185 |
+
<tr>
|
186 |
+
<th colspan="2">
|
187 |
+
<h3><?php _e( 'Pulse (less tweakable)<br>ratio of "tail" to "acceleration"', 'wpmss' ) ?></h3>
|
188 |
+
</th>
|
189 |
+
</tr>
|
190 |
+
<tr>
|
191 |
+
<th>
|
192 |
+
<label for="q_field_35"><?php _e( 'pulseAlgorithm', 'wpmss' ) ?>:</label>
|
193 |
+
</th>
|
194 |
+
<td>
|
195 |
+
<input type="checkbox" name="pulseAlgorithm" value="1" <?php echo $this->settings[ $this->tab ]['pulseAlgorithm'] ? 'checked' : '' ?> id="q_field_35">
|
196 |
+
 <small class="default">default: on</small>
|
197 |
+
</td>
|
198 |
+
</tr>
|
199 |
+
<tr>
|
200 |
+
<th>
|
201 |
+
<label for="q_field_4"><?php _e( 'pulseScale', 'wpmss' ) ?>:</label>
|
202 |
+
</th>
|
203 |
+
<td>
|
204 |
+
<input type="number" name="pulseScale" placeholder="4" value="<?php echo $this->settings[ $this->tab ]['pulseScale'] ?>" id="q_field_4">
|
205 |
+
 <small class="default">default: 4</small>
|
206 |
+
</td>
|
207 |
+
</tr>
|
208 |
+
<tr>
|
209 |
+
<th>
|
210 |
+
<label for="q_field_5"><?php _e( 'pulseNormalize', 'wpmss' ) ?>:</label>
|
211 |
+
</th>
|
212 |
+
<td>
|
213 |
+
<input type="number" name="pulseNormalize" placeholder="1" value="<?php echo $this->settings[ $this->tab ]['pulseNormalize'] ?>" id="q_field_5">
|
214 |
+
 <small class="default">default: 1</small>
|
215 |
+
</td>
|
216 |
+
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
217 |
|
218 |
+
<tr>
|
219 |
+
<th colspan="2">
|
220 |
+
<h3><?php _e( 'Acceleration', 'wpmss' ) ?></h3>
|
221 |
+
</th>
|
222 |
+
</tr>
|
223 |
+
<tr>
|
224 |
+
<th>
|
225 |
+
<label for="q_field_6"><?php _e( 'accelerationDelta', 'wpmss' ) ?>:</label>
|
226 |
+
</th>
|
227 |
+
<td>
|
228 |
+
<input type="number" name="accelerationDelta" placeholder="50" value="<?php echo $this->settings[ $this->tab ]['accelerationDelta'] ?>" id="q_field_6">
|
229 |
+
 <small class="default">default: 50</small>
|
230 |
+
</td>
|
231 |
+
</tr>
|
232 |
+
<tr>
|
233 |
+
<th>
|
234 |
+
<label for="q_field_7"><?php _e( 'accelerationMax', 'wpmss' ) ?>:</label>
|
235 |
+
</th>
|
236 |
+
<td>
|
237 |
+
<input type="number" name="accelerationMax" placeholder="3" value="<?php echo $this->settings[ $this->tab ]['accelerationMax'] ?>" id="q_field_7">
|
238 |
+
 <small class="default">default: 3</small>
|
239 |
+
</td>
|
240 |
+
</tr>
|
241 |
|
242 |
+
<tr>
|
243 |
+
<th colspan="2">
|
244 |
+
<h3><?php _e( 'Keyboard Settings', 'wpmss' ) ?></h3>
|
245 |
+
</th>
|
246 |
+
</tr>
|
247 |
+
<tr>
|
248 |
+
<th>
|
249 |
+
<label for="q_field_75"><?php _e( 'keyboardSupport', 'wpmss' ) ?>:</label>
|
250 |
+
</th>
|
251 |
+
<td>
|
252 |
+
<input type="checkbox" name="keyboardSupport" value="1" <?php echo $this->settings[ $this->tab ]['keyboardSupport'] ? 'checked' : '' ?> id="q_field_75">
|
253 |
+
 <small class="default">default: on</small>
|
254 |
+
</td>
|
255 |
+
</tr>
|
256 |
+
<tr>
|
257 |
+
<th>
|
258 |
+
<label for="q_field_8"><?php _e( 'arrowScroll', 'wpmss' ) ?>:</label>
|
259 |
+
</th>
|
260 |
+
<td>
|
261 |
+
<input type="number" name="arrowScroll" placeholder="50" value="<?php echo $this->settings[ $this->tab ]['arrowScroll'] ?>" id="q_field_8">
|
262 |
+
[px] <small class="default">default: 50</small>
|
263 |
+
</td>
|
264 |
+
</tr>
|
265 |
|
266 |
+
<tr>
|
267 |
+
<th colspan="2">
|
268 |
+
<h3><?php _e( 'Other', 'wpmss' ) ?></h3>
|
269 |
+
</th>
|
270 |
+
</tr>
|
271 |
+
<tr>
|
272 |
+
<th>
|
273 |
+
<label for="q_field_9"><?php _e( 'touchpadSupport', 'wpmss' ) ?>:</label>
|
274 |
+
</th>
|
275 |
+
<td>
|
276 |
+
<input type="checkbox" name="touchpadSupport" value="1" <?php echo $this->settings[ $this->tab ]['touchpadSupport'] ? 'checked' : '' ?> id="q_field_9">
|
277 |
+
 <small class="default">default: off</small>
|
278 |
+
</td>
|
279 |
+
</tr>
|
280 |
+
<tr>
|
281 |
+
<th>
|
282 |
+
<label for="q_field_10"><?php _e( 'fixedBackground', 'wpmss' ) ?>:</label>
|
283 |
+
</th>
|
284 |
+
<td>
|
285 |
+
<input type="checkbox" name="fixedBackground" value="1" <?php echo $this->settings[ $this->tab ]['fixedBackground'] ? 'checked' : '' ?> id="q_field_10">
|
286 |
+
 <small class="default">default: on</small>
|
287 |
+
</td>
|
288 |
+
</tr>
|
289 |
+
</table>
|
290 |
+
<p class="submit"><input type="submit" class="button button-primary button-large" value="<?php _e('Save') ?>"></p><?php
|
291 |
+
}
|
292 |
+
|
293 |
+
function plugin_info_options(){ ?>
|
294 |
+
<p><?php _e( 'Any ideas, problems, issues?', 'wpmss' ) ?></p>
|
295 |
+
<p>Ing. Jakub Novák</p>
|
296 |
+
<p><a href="mailto:info@kubiq.sk" target="_blank">info@kubiq.sk</a></p>
|
297 |
+
<p><a href="https://kubiq.sk" target="_blank">https://kubiq.sk</a></p><?php
|
298 |
}
|
299 |
}
|
300 |
|
301 |
+
$wpmss = new wpmss();
|
|
|
|
readme.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: KubiQ
|
|
3 |
Donate link: https://kubiq.sk
|
4 |
Tags: smooth scroll, mousewheel scroll, scrolling
|
5 |
Requires at least: 3.0.1
|
6 |
-
Tested up to:
|
7 |
-
Stable tag:
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -26,59 +26,63 @@ Replace basic website scrolling "effect" with nice smooth scroll using mousewhee
|
|
26 |
|
27 |
== Changelog ==
|
28 |
|
29 |
-
=
|
30 |
-
*
|
31 |
-
|
32 |
-
= 1.0.1 =
|
33 |
-
* Optimalisation
|
34 |
-
|
35 |
-
= 1.0.2 =
|
36 |
-
* Improve / change default settings
|
37 |
|
38 |
-
=
|
39 |
-
*
|
|
|
|
|
40 |
|
41 |
-
=
|
42 |
-
*
|
|
|
43 |
|
44 |
-
=
|
45 |
-
*
|
46 |
|
47 |
-
=
|
48 |
-
*
|
49 |
-
* Use different jQuery library
|
50 |
-
* Repair scripts enqueue dependencies
|
51 |
-
* Ctrl + scroll is now zooming - default browser behaviour
|
52 |
|
53 |
-
=
|
54 |
-
*
|
55 |
-
* Scroll library improvements
|
56 |
|
57 |
-
= 1
|
58 |
-
*
|
59 |
|
60 |
= 2.0 =
|
61 |
* completely new scrolling script
|
62 |
* lightweight settings
|
63 |
* optimization
|
64 |
|
65 |
-
=
|
66 |
-
*
|
67 |
|
68 |
-
=
|
69 |
-
*
|
|
|
70 |
|
71 |
-
= 2
|
72 |
-
*
|
|
|
|
|
|
|
73 |
|
74 |
-
=
|
75 |
-
*
|
76 |
|
77 |
-
=
|
78 |
-
*
|
79 |
-
* new options
|
80 |
|
81 |
-
=
|
82 |
-
*
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
Donate link: https://kubiq.sk
|
4 |
Tags: smooth scroll, mousewheel scroll, scrolling
|
5 |
Requires at least: 3.0.1
|
6 |
+
Tested up to: 5.0
|
7 |
+
Stable tag: 5.0
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
26 |
|
27 |
== Changelog ==
|
28 |
|
29 |
+
= 5.0 =
|
30 |
+
* tested on WP 5.0
|
31 |
+
* updated scrolling script
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
= 4.0 =
|
34 |
+
* generate JS file instead of PHP
|
35 |
+
* optimized for cache
|
36 |
+
* optimized for translator plugins
|
37 |
|
38 |
+
= 3.0 =
|
39 |
+
* completely new scrolling script
|
40 |
+
* new options
|
41 |
|
42 |
+
= 2.4 =
|
43 |
+
* Enable for all browsers
|
44 |
|
45 |
+
= 2.3 =
|
46 |
+
* Enqueue script in footer
|
|
|
|
|
|
|
47 |
|
48 |
+
= 2.2 =
|
49 |
+
* Escaping option values for better security
|
|
|
50 |
|
51 |
+
= 2.1 =
|
52 |
+
* Tested on WP 4.5
|
53 |
|
54 |
= 2.0 =
|
55 |
* completely new scrolling script
|
56 |
* lightweight settings
|
57 |
* optimization
|
58 |
|
59 |
+
= 1.4 =
|
60 |
+
* minify JS scripts and combine them into one file
|
61 |
|
62 |
+
= 1.3 =
|
63 |
+
* Added PHP header to hybrid PHP/JS file
|
64 |
+
* Scroll library improvements
|
65 |
|
66 |
+
= 1.2 =
|
67 |
+
* Tested on WP 4.4
|
68 |
+
* Use different jQuery library
|
69 |
+
* Repair scripts enqueue dependencies
|
70 |
+
* Ctrl + scroll is now zooming - default browser behaviour
|
71 |
|
72 |
+
= 1.1 =
|
73 |
+
* Tested on WP 4.2
|
74 |
|
75 |
+
= 1.0.4 =
|
76 |
+
* Remove some script
|
|
|
77 |
|
78 |
+
= 1.0.3 =
|
79 |
+
* Update scroll script
|
80 |
+
|
81 |
+
= 1.0.2 =
|
82 |
+
* Improve / change default settings
|
83 |
+
|
84 |
+
= 1.0.1 =
|
85 |
+
* Optimalisation
|
86 |
+
|
87 |
+
= 1.0 =
|
88 |
+
* First version
|