From: Vincent Vanwaelscappel Date: Thu, 26 Jun 2025 16:23:44 +0000 (+0200) Subject: Merge branch 'master' into taborder X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=1a64d8551aa037bd34356cbb33b87ee18e70d148;p=fluidbook-html5.git Merge branch 'master' into taborder # Conflicts: # js/libs/fluidbook/fluidbook.keyboard.js --- 1a64d8551aa037bd34356cbb33b87ee18e70d148 diff --cc js/libs/fluidbook/fluidbook.keyboard.js index f2ddedca,58c69085..2fb02768 --- a/js/libs/fluidbook/fluidbook.keyboard.js +++ b/js/libs/fluidbook/fluidbook.keyboard.js @@@ -68,79 -42,50 +54,119 @@@ FluidbookKeyboard.prototype = this.keyShortcut('f10', function () { $this.fluidbook.nav.burger.toggle(); - }) + }); + + setInterval(function () { + $this.listenToIframeEscapeEvents(); + }, 500); + }, + + listenToIframeEscapeEvents: function () { + var $this = this; + $('iframe:not(.listenescape)').each(function () { + $(this).addClass('listenescape'); + let iframe = $(this); + $(this).on('load', function () { + let win = $(iframe).get(0).contentWindow; + let doc = win.document; + doc.addEventListener('keydown', function (e) { + if (e.code === 'Escape') { + $this.escape(); + } + }); + }); + + }); + }, + + escape: function () { + if (this.fluidbook.help.isVisible()) { + this.fluidbook.help.hide(); + } + if (this.fluidbook.menu.viewMode()) { + this.fluidbook.menu.closeView(function () { + + }, true, true); + } + this.fluidbook.search.closeSearch(); + this.fluidbook.search.closeResultsNav(); + this.fluidbook.nav.burger.close(); + + if (this.fluidbook.support.isFullscreen()) { + document.exitFullscreen(); + } }, - _navigate: function (list, dir, actions) { + + tabNavigationSections: function (selectors, dir) { + let currentSection = -1; + let active = $(document.activeElement); + + $.each(selectors, function (k, s) { + if (active.is(s) || active.closest(s).length > 0) { + currentSection = k; + return false; + } + }); + + if (currentSection === -1) { + currentSection = 0; + } + let loop = 0; + while (!this.tabNavigation(selectors[currentSection], dir, false, loop > 0)) { + currentSection += dir; + if (currentSection >= selectors.length || currentSection < 0) { + return false; + } + loop++; + if (loop++ > selectors.length) { + break; + } + } + return true; + }, + + tabNavigation: function (selector, dir, loop, switchList) { + if (switchList === undefined) { + switchList = false; + } + if (loop === undefined) { + loop = true; + } + const 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]'; + let elements; + if ($(selector).is(focusableElementsString)) { + elements = $(selector); + } else { + elements = $(selector).find(focusableElementsString); + } + var list = []; + $(elements).each(function () { + if (parseInt($(this).attr('tabindex')) < 0) { + return; + } + if ($(this).parents('[tabindex="-1"],.ignore-tab-children').length === 0 && $(this).is(':visible')) { + list.push(this); + } + }); + if (list.length === 0) { + console.log(selector, 'nothing here'); + return false; + } + let res = this._navigate(list, dir, ['focus'], loop, switchList); + if (!res) { + console.log(selector, 'end of list'); + } + return res; + }, + + _navigate: function (list, dir, actions, loop, switchList) { + if (switchList === undefined) { + switchList = false; + } + if (loop === undefined) { + loop = true; + } if (actions === undefined) { actions = ['focus']; } @@@ -178,9 -114,28 +205,25 @@@ $(ne).click(); } }); ++ + return true; }, + 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], button'; + var elements = $(selector).find(focusableElementsString); + var list = []; - //console.log('elements', elements); + $(elements).each(function () { + if ($(this).attr('tabindex') == '-1') { - //console.log('skip because of tabindex', this); + return; + } + if ($(this).parents('.ignore-tab-children').length === 0 && $(this).is(':visible')) { + list.push(this); - } else { - //console.log('skip because of parent or not being visible', this); + } + }); - //console.log('list', list); - this._navigate(list, dir); ++ return this._navigate(list, dir); + }, + initBookmarksShortcuts: function () { var $this = this; this.keyShortcut('ctrl+alt+d', function () {