]> _ Git - fluidbook-html5.git/commitdiff
fix #3763 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 3 Jul 2020 16:11:31 +0000 (18:11 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 3 Jul 2020 16:11:31 +0000 (18:11 +0200)
js/libs/fluidbook/fluidbook.interface.js
js/libs/fluidbook/fluidbook.keyboard.js
js/libs/fluidbook/fluidbook.search.js
js/libs/fluidbook/fluidbook.zoom.js

index 8b43c5d96e4e1e1799ced37ea7dd246785a4c65c..dde9a50807ee1279a58783884449cd2b3dd4212e 100644 (file)
@@ -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 += '<div id="next-arrows">';
                 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 += '</div>';
                 res += '<div id="prev-arrows">';
                 res += this.fluidbook.nav.getLink('interface-prev', '#', 'previous', '', labels.previous, 'arrow-top', true, '', 'ArrowLeft');
@@ -32,11 +33,11 @@ FluidbookInterface.prototype = {
             } else {
                 res += '<div id="next-arrows">';
                 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 += '</div>';
                 res += '<div id="prev-arrows">';
-                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 += '</div>';
             }
 
index ea44ab10244c418d71f9dca14f726cec73cb03e9..1eb9946021e3006b87275d382bd0aa61cc46a968 100644 (file)
@@ -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) {
index 32ebd19fee9e5b8379522e19e4eac23a723c0720..a6a4e70b8c588eb2d15a39b62bf081fcd988583e 100644 (file)
@@ -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
index 1b025e6f5fd7c94452b7b303d391ce724459b01b..960b9e95c09ed95d1eb6dba65a873f6665c5dd3a 100644 (file)
@@ -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 () {