MCPcopy Create free account
hub / github.com/Useful-Scripts-Extension/useful-script / wheel

Function wheel

scripts/smoothScroll.js:409–490  ·  view source on GitHub ↗

* Mouse wheel handler. * @param {Object} event

(event)

Source from the content-addressed store, hash-verified

407 * @param {Object} event
408 */
409 function wheel(event) {
410 if (!initDone) {
411 init();
412 }
413 let target = event.target;
414 // leave early if default action is prevented
415 // or it's a zooming event with CTRL
416 if (event.defaultPrevented || event.ctrlKey) {
417 return true;
418 }
419 // leave embedded content alone (flash & pdf)
420 if (
421 isNodeName(activeElement, "embed") ||
422 (isNodeName(target, "embed") && /\.pdf/i.test(target.src)) ||
423 isNodeName(activeElement, "object") ||
424 target.shadowRoot
425 ) {
426 return true;
427 }
428 let deltaX = -event.wheelDeltaX || event.deltaX || 0;
429 let deltaY = -event.wheelDeltaY || event.deltaY || 0;
430 if (isMac) {
431 if (event.wheelDeltaX && isDivisible(event.wheelDeltaX, 120)) {
432 deltaX = -120 * (event.wheelDeltaX / Math.abs(event.wheelDeltaX));
433 }
434 if (event.wheelDeltaY && isDivisible(event.wheelDeltaY, 120)) {
435 deltaY = -120 * (event.wheelDeltaY / Math.abs(event.wheelDeltaY));
436 }
437 }
438 if (isLinux) {
439 // issues #148 #176
440 let otherModifier = event.ctrlKey || event.altKey || event.metaKey;
441 if (event.shiftKey && !otherModifier) {
442 deltaX = deltaX || deltaY;
443 deltaY = 0;
444 }
445 }
446 // use wheelDelta if deltaX/Y is not available
447 if (!deltaX && !deltaY) {
448 deltaY = -event.wheelDelta || 0;
449 }
450 // line based scrolling
451 if (event.deltaMode === 1) {
452 deltaX *= 40;
453 deltaY *= 40;
454 }
455 // check if it's a touchpad scroll that should be ignored
456 if (!options.touchpadSupport && isTouchpad(deltaY)) {
457 return true;
458 }
459 let xOnly = deltaX && !deltaY;
460 let overflowing = overflowingAncestor(target, xOnly);
461 // nothing to do if there's no element that's scrollable
462 if (!overflowing) {
463 // Chrome iframes seem to eat wheel events, which we need to
464 // propagate up if the iframe has nothing overflowing to scroll
465 if (isFrame) {
466 event.preventDefault();

Callers 1

initFunction · 0.85

Calls 8

isNodeNameFunction · 0.85
isDivisibleFunction · 0.85
isTouchpadFunction · 0.85
overflowingAncestorFunction · 0.85
postScrollToParentFunction · 0.85
scrollArrayFunction · 0.85
scheduleClearCacheFunction · 0.85
initFunction · 0.70

Tested by

no test coverage detected