From c8df78e5cd66e7c8c8034c7f8de0433433d07744 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 16 Jul 2020 19:55:35 +0200 Subject: [PATCH] fix #3779 @2 --- js/libs/fluidbook/fluidbook.js | 4 +-- js/libs/fluidbook/fluidbook.keyboard.js | 39 ++++++++++++++++++++++++- js/libs/fluidbook/fluidbook.menu.js | 2 +- js/libs/fluidbook/fluidbook.search.js | 26 ++--------------- 4 files changed, 43 insertions(+), 28 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index e0bcb738..481484f9 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -521,12 +521,12 @@ Fluidbook.prototype = { hideArrows: function (id) { $(id).addClass('hidden').attr('aria-hidden', 'true'); - $(id).find('a').attr('tabindex', '-1'); + $(id).find('a').prop('tabindex', -1); }, showArrows: function (id) { $(id).removeClass('hidden').attr('aria-hidden', 'false'); - $(id).find('a').attr('tabindex', null); + $(id).find('a').prop('tabindex', 0); }, updateShadows: function (page, animationDuration) { diff --git a/js/libs/fluidbook/fluidbook.keyboard.js b/js/libs/fluidbook/fluidbook.keyboard.js index 3fdecb8e..ebb451a4 100644 --- a/js/libs/fluidbook/fluidbook.keyboard.js +++ b/js/libs/fluidbook/fluidbook.keyboard.js @@ -28,6 +28,14 @@ FluidbookKeyboard.prototype = { screenfull.exit(); } }); + this.keyShortcut('tab,shift+tab', function (e, handler) { + if ($this.fluidbook.menu.viewMode()) { + $this.tabNavigation('.mview', handler.shortcut === 'tab' ? 1 : -1); + e.preventDefault(); + } + }, false, false); + + if (this.fluidbook.settings.fullscreen) { this.keyShortcut('f11', function () { screenfull.toggle(); @@ -40,6 +48,35 @@ FluidbookKeyboard.prototype = { } }, + _navigate: function (list, dir) { + if (dir === undefined) { + dir = 1; + } + var items = $(list); + console.log(list); + var nb = items.length; + var next; + if ($(items).has(document.activeElement)) { + var index = $(items).index(document.activeElement); + next = (nb + index + dir) % nb; + console.log('n', nb); + } else { + if (dir === 1) { + next = 0; + } else { + next = nb - 1; + } + } + console.log(next); + var ne = $(items).eq(next); + $(ne).focus(); + }, + + tabNavigation: function (selector, dir) { + var focusableElementsString = 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex="0"]:not(.ps__thumb-x):not(.ps__thumb-y), [contenteditable]'; + this._navigate($(selector).find(focusableElementsString), dir); + }, + initBookmarksShortcuts: function () { var $this = this; this.keyShortcut('ctrl+alt+d', function () { @@ -71,7 +108,7 @@ FluidbookKeyboard.prototype = { if ($this.fluidbook.search.isHintsNavOpened()) { $this.fluidbook.search.navigateHint(handler.key === 'down' ? 1 : -1); e.preventDefault(); - }else if($this.fluidbook.search.isResultsOverviewOpened()) { + } else if ($this.fluidbook.search.isResultsOverviewOpened()) { $this.fluidbook.search.navigateResults(handler.key === 'down' ? 1 : -1); } }, false, false); diff --git a/js/libs/fluidbook/fluidbook.menu.js b/js/libs/fluidbook/fluidbook.menu.js index a53eacc5..41b58704 100644 --- a/js/libs/fluidbook/fluidbook.menu.js +++ b/js/libs/fluidbook/fluidbook.menu.js @@ -168,7 +168,7 @@ FluidbookMenu.prototype = { $("#view").append(res); }, - getCaption:function(caption, close, cls) { + getCaption: function (caption, close, cls) { if (cls === undefined) { cls = ''; } diff --git a/js/libs/fluidbook/fluidbook.search.js b/js/libs/fluidbook/fluidbook.search.js index 596c4153..7c3c94fc 100644 --- a/js/libs/fluidbook/fluidbook.search.js +++ b/js/libs/fluidbook/fluidbook.search.js @@ -165,35 +165,13 @@ FluidbookSearch.prototype = { }, navigateHint: function (dir) { - this._navigate("#menuSearchHints .hint", '.hint', dir); + this.fluidbook.keyboard._navigate("#menuSearchHints .hint", dir); }, navigateResults: function (dir) { - this._navigate('#menuSearchResults .doubleThumb', '.doubleThumb', dir); + this.fluidbook.keyboard._navigate('#menuSearchResults .doubleThumb', dir); }, - _navigate: function (listSelector, elementSelector, dir) { - if (dir === undefined) { - dir = 1; - } - var hints = $(listSelector); - var nbhints = hints.length; - var next; - if ($(document.activeElement).is(elementSelector)) { - var index = $(hints).index(document.activeElement); - next = (nbhints + index + dir) % nbhints; - } else { - if (dir === 1) { - next = 0; - } else { - next = nbhints - 1; - } - } - var ne = $(hints).eq(next); - $(ne).focus(); - }, - - closeResultsNav: function (keepSearch) { keepSearch = keepSearch !== 'undefined' ? keepSearch : false; -- 2.39.5