From: Vincent Vanwaelscappel Date: Fri, 3 Jul 2020 16:11:31 +0000 (+0200) Subject: fix #3763 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=06bdb377d026c9ca2d1cd9e083a6c77734054a3c;p=fluidbook-html5.git fix #3763 @1.5 --- diff --git a/js/libs/fluidbook/fluidbook.interface.js b/js/libs/fluidbook/fluidbook.interface.js index 8b43c5d9..dde9a508 100644 --- a/js/libs/fluidbook/fluidbook.interface.js +++ b/js/libs/fluidbook/fluidbook.interface.js @@ -18,12 +18,13 @@ FluidbookInterface.prototype = { var $this = this; if (this.arrowsEnabled()) { + this.fluidbook.keyboard.initInterfaceShortcuts(); var labels = this.getLabels(); var res = ''; if ($('html').hasClass('ltr')) { res += '
'; res += this.fluidbook.nav.getLink('interface-next', '#', 'next', '', labels.next, 'arrow-top', true, '', 'ArrowRight'); - res += this.fluidbook.nav.getLink('interface-last', '#', 'last', '', labels.last, 'arrow-bottom', true ,'','End'); + res += this.fluidbook.nav.getLink('interface-last', '#', 'last', '', labels.last, 'arrow-bottom', true, '', 'End'); res += '
'; res += '
'; res += this.fluidbook.nav.getLink('interface-prev', '#', 'previous', '', labels.previous, 'arrow-top', true, '', 'ArrowLeft'); @@ -32,11 +33,11 @@ FluidbookInterface.prototype = { } else { res += '
'; res += this.fluidbook.nav.getLink('interface-next', '#', 'previous', '', labels.previous, 'arrow-top', true, '', 'ArrowRight'); - res += this.fluidbook.nav.getLink('interface-last', '#', 'first', '', labels.first, 'arrow-bottom', true, 'Home'); + res += this.fluidbook.nav.getLink('interface-last', '#', 'first', '', labels.first, 'arrow-bottom', true, '', 'Home'); res += '
'; res += '
'; - res += this.fluidbook.nav.getLink('interface-prev', '#', 'next', '', labels.next, 'arrow-top', true, 'ArrowLeft'); - res += this.fluidbook.nav.getLink('interface-first', '#', 'last', '', labels.last, 'arrow-bottom', true, 'End'); + res += this.fluidbook.nav.getLink('interface-prev', '#', 'next', '', labels.next, 'arrow-top', true, '', 'ArrowLeft'); + res += this.fluidbook.nav.getLink('interface-first', '#', 'last', '', labels.last, 'arrow-bottom', true, '', 'End'); res += '
'; } diff --git a/js/libs/fluidbook/fluidbook.keyboard.js b/js/libs/fluidbook/fluidbook.keyboard.js index ea44ab10..1eb99460 100644 --- a/js/libs/fluidbook/fluidbook.keyboard.js +++ b/js/libs/fluidbook/fluidbook.keyboard.js @@ -70,8 +70,7 @@ FluidbookKeyboard.prototype = { initZoomShortcuts: function () { var $this = this; - window.addEventListener('keydown', function(e){ - console.log(e); + window.addEventListener('keydown', function (e) { if (e.ctrlKey) { if (e.key === '+') { $this.fluidbook.zoom.increaseZoom(); @@ -85,31 +84,74 @@ FluidbookKeyboard.prototype = { } } }); + + this.keyShortcut('left,right,up,down', function (e, handler) { + if ($this.fluidbook.zoom.zoom === 1) { + return; + } + console.log(handler.key); + $this.fluidbook.zoom.move(handler.key); + e.preventDefault(); + }, false, false); }, - keyShortcut: function (shortcuts, func) { + initInterfaceShortcuts: function () { + var $this = this; + this.keyShortcut('left,right,home,end', function (e, handler) { + if ($this.fluidbook.zoom.zoom > 1) { + return; + } + if (handler.key === 'left' || handler.key === 'right') { + var dir = 'Next'; + if (handler.key === 'left' && this.fluidbook.l10n.ltr || handler.key === 'right' && this.fluidbook.l10n.rtl) { + dir = 'Previous'; + } + var func = 'go' + dir; + if (this.fluidbook.pad.enabled) { + func += 'Chapter'; + }else{ + func+='Page'; + } + this.fluidbook[func](); + } else if (handler.key === 'end') { + $this.fluidbook.goLastPage(); + } else if (handler.key === 'home') { + $this.fluidbook.goFirstPage(); + } + e.preventDefault(); + }, false); + }, + + keyShortcut: function (shortcuts, func, preventDefault, check) { + + if (preventDefault === undefined) { + preventDefault = true; + } + if (check === undefined) { + check = true; + } if (shortcuts === '') { return; } - var s = this.checkShortcuts(shortcuts); - hotkeys(s.shortcuts, s.options, function () { - func(); - return false; + var s = {shortcuts: shortcuts, options: {}}; + if (check) { + s = this.checkShortcuts(shortcuts); + } + hotkeys(s.shortcuts, s.options, function (e, handler) { + func(e, handler); + if (preventDefault) { + e.preventDefault(); + } }); }, checkShortcuts: function (shortcuts) { - console.log(shortcuts); var $this = this; var res = []; - var splitKey = shortcuts.indexOf('plus') >= 0 ? '-' : '+'; - if (splitKey !== '+') { - shortcuts = shortcuts.replace(/\+/g, splitKey); - shortcuts = shortcuts.replace(/plus/g, '+'); - } - var s = shortcuts.split(','); + var splitKey = '+'; + var s = shortcuts.split(','); $.each(s, function (k, shortcut) { shortcut = shortcut.trim(); @@ -119,8 +161,7 @@ FluidbookKeyboard.prototype = { } }); - var ret = {shortcuts: res.join(', '), options: {splitKey: splitKey}}; - return ret; + return {shortcuts: res.join(', '), options: {splitKey: splitKey}}; }, ariaShortcut: function (shortcuts, func) { diff --git a/js/libs/fluidbook/fluidbook.search.js b/js/libs/fluidbook/fluidbook.search.js index 32ebd19f..a6a4e70b 100644 --- a/js/libs/fluidbook/fluidbook.search.js +++ b/js/libs/fluidbook/fluidbook.search.js @@ -649,11 +649,15 @@ FluidbookSearch.prototype = { }, hideSearchHints: function () { - this.menuSearchHints.html('').hide(); // Clear and hide all hints + if (this.menuSearchHints !== undefined) { + this.menuSearchHints.html('').hide(); // Clear and hide all hints + } }, hideSearchResults: function () { - this.menuSearchResults.html('').hide(); + if (this.menuSearchResults !== undefined) { + this.menuSearchResults.html('').hide(); + } }, // Check if a search is active in the interface diff --git a/js/libs/fluidbook/fluidbook.zoom.js b/js/libs/fluidbook/fluidbook.zoom.js index 1b025e6f..960b9e95 100644 --- a/js/libs/fluidbook/fluidbook.zoom.js +++ b/js/libs/fluidbook/fluidbook.zoom.js @@ -1,7 +1,7 @@ function FluidbookZoom(fluidbook) { this.fluidbook = fluidbook; this.zoom = 0; - this.originpct = ['0%', '0%']; + this.originpct = [0.5, 0.5]; this.originpx = ['0px', '0px']; this.initial = this.fluidbook.settings.zoom / 100; this.max = this.fluidbook.settings.zoomw / 100; @@ -60,12 +60,26 @@ FluidbookZoom.prototype = { } else if (this.zoom > this.initial) { z = this.initial; } else { - z = 1; + return this.resetZoom(); } this.setZoom(z, -1, true); }, + move: function (direction, amount) { + amount = amount === undefined ? 0.1 : amount; + var dir = 0; + var mult = 1; + if (direction === 'up' || direction === 'down') { + dir = 1; + } + if (direction === 'left' || direction === 'up') { + mult = -1; + } + this.originpct[dir] = Math.min(1, Math.max(0, this.originpct[dir] + amount * mult)); + this.setOriginPct(this.originpct[0], this.originpct[1], false, true); + }, + disable: function () { this.enabled = false; $('body').addClass('zoom-disabled'); @@ -146,6 +160,7 @@ FluidbookZoom.prototype = { } return; } + this.setOriginPct(0.5, 0.5, true, true); this.setZoom(1, -1); if (callback) { setTimeout(function () {