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'];
}
$(ne).click();
}
});
++
+ return true;
},
- //console.log('elements', elements);
+ 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('skip because of tabindex', this);
+ $(elements).each(function () {
+ if ($(this).attr('tabindex') == '-1') {
- } else {
- //console.log('skip because of parent or not being visible', this);
+ return;
+ }
+ if ($(this).parents('.ignore-tab-children').length === 0 && $(this).is(':visible')) {
+ list.push(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 () {