From cead39e610ebcdb3bfe2e9f1a655046eb8e65a2a Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 2 Mar 2021 10:13:41 +0100 Subject: [PATCH] wip #4314 @1 --- js/libs/fluidbook/fluidbook.desktop.js | 13 +-------- js/libs/fluidbook/fluidbook.help.js | 7 ++++- js/libs/fluidbook/fluidbook.zoom.js | 40 ++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 13 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.desktop.js b/js/libs/fluidbook/fluidbook.desktop.js index d6e51c2a..0d253b62 100644 --- a/js/libs/fluidbook/fluidbook.desktop.js +++ b/js/libs/fluidbook/fluidbook.desktop.js @@ -26,11 +26,6 @@ FluidbookDesktop.prototype = { }) - $(document).on('mousewheel', function (e) { - if ($this.fluidbook.zoom.enabled) { - $this.wheelZoom(e.deltaY); - } - }); $(document).on('mousemove', 'body', function (e) { if ($this.fluidbook.zoom.enabled) { $this.moveZoom(e); @@ -65,12 +60,6 @@ FluidbookDesktop.prototype = { this.fluidbook.zoom.setZoom(newScale); return false; }, - wheelZoom: function (delta) { - // Disable scroll zoom when either a view or the menu is open... - if ($("body").is('.view, .menu-open')) { - return; - } - this.fluidbook.zoom.setZoom(this.fluidbook.zoom.zoom + delta / 3, delta > 0 ? 1 : -1); - }, + }; \ No newline at end of file diff --git a/js/libs/fluidbook/fluidbook.help.js b/js/libs/fluidbook/fluidbook.help.js index 4d8956af..2e01fa9d 100644 --- a/js/libs/fluidbook/fluidbook.help.js +++ b/js/libs/fluidbook/fluidbook.help.js @@ -78,7 +78,12 @@ FluidbookHelp.prototype = { if (this.fluidbook.mobilefirst.enabled) { text = this.fluidbook.l10n.__('scroll down to read the page content'); } else { - text = this.fluidbook.l10n.__('click once to zoom in, click again to zoom out') + '
' + this.fluidbook.l10n.__('roll the mouse wheel to zoom in/out'); + text = this.fluidbook.l10n.__('click once to zoom in, click again to zoom out'); + if (this.fluidbook.settings.zoomWheel === 'wheel') { + text += '
' + this.fluidbook.l10n.__('roll the mouse wheel to zoom in/out'); + } else if (this.fluidbook.settings.zoomWheel === 'ctrlwheel') { + text += '
' + this.fluidbook.l10n.__('use Ctrl + scroll to zoom in/out'); + } } help += '
' + getSpriteIcon('help-mouse', { diff --git a/js/libs/fluidbook/fluidbook.zoom.js b/js/libs/fluidbook/fluidbook.zoom.js index 960b9e95..e0bd6737 100644 --- a/js/libs/fluidbook/fluidbook.zoom.js +++ b/js/libs/fluidbook/fluidbook.zoom.js @@ -22,6 +22,8 @@ FluidbookZoom.prototype = { var $this = this; this.setTransition(true); + this.initMouseWheel(); + $(this.fluidbook).on('fluidbook.zoom.out.end', function () { $("#z").addClass('nozoom'); }); @@ -43,6 +45,44 @@ FluidbookZoom.prototype = { this.fluidbook.keyboard.initZoomShortcuts(); }, + initMouseWheel: function () { + var $this = this; + window.addEventListener('wheel', function (e) { + var returnValue = true; + if (e.ctrlKey) { + e.preventDefault(); + e.stopPropagation(); + e.stopImmediatePropagation(); + returnValue = false; + } + if (!$this.enabled || $this.fluidbook.settings.zoomWheel === 'disabled') { + return returnValue; + } + if ($this.fluidbook.settings.zoomWheel === 'ctrlwheel' && !e.ctrlKey) { + return returnValue; + } + // Disable scroll zoom when either a view or the menu is open... + if ($("body").is('.view, .menu-open')) { + return returnValue; + } + + $this.wheelZoom(e.deltaY * -1); + return returnValue; + }, {passive: false}); + }, + + wheelZoom: function (delta) { + var dir; + if (delta > 0) { + delta = 0.7; + dir = 1; + } else { + delta = -0.7; + dir = -1; + } + this.setZoom(this.zoom + delta, dir); + }, + increaseZoom: function () { var z; if (this.zoom === 1) { -- 2.39.5