init: function () {
// Add button elements
- this.container.append(this.buttonLeft);
- this.container.append(this.buttonRight);
+ this.container.append('<div class="audio-description-wrapper left" />');
+ this.container.find('.audio-description-wrapper.left').append(this.buttonLeft);
+ this.container.append('<div class="audio-description-wrapper right" />');
+ this.container.find('.audio-description-wrapper.right').append(this.buttonRight);
- var $this = this,
- buttons = $('.' + this.buttonClass)
+ var $this = this;
+ var buttons = $('.' + this.buttonClass)
// Add tooltips
buttons.attr('data-tooltip', this.fluidbook.l10n.__('listen to the page'));
$(this.buttonLeft).hide();
}
+
// Right hand page
if (this.hasAudio(pageNumRight) && !this.fluidbook.displayOnePage) {
$(this.buttonRight).show();
playSide: function (side) {
- var targetSelector = '.' + this.buttonClass + '.' + side,
- pageNum = this.fluidbook.getPageNumberOfSide(side);
+ var targetSelector = '.' + this.buttonClass + '.' + side, pageNum = this.fluidbook.getPageNumberOfSide(side);
// Only try to play audio if available (button will be visible)
if (this.hasAudio(pageNum)) {
} else if ($this.fluidbook.menu.viewMode()) {
$this.tabNavigation('.mview', dir);
e.preventDefault();
+ } else {
+ $this.tabNavigationSections(['.audio-description-wrapper.left', '.audio-description-wrapper.right'], dir);
+ e.preventDefault();
}
}, false, false);
})
},
- _navigate: function (list, dir, actions) {
+
+ tabNavigationSections: function (selectors, dir) {
+ let currentSection = -1;
+ let active = $(document.activeElement);
+ $.each(selectors, function (k, s) {
+ if ($(s).has(active) || $(s).is(active)) {
+ currentSection = k;
+ return false;
+ }
+ });
+
+ if (currentSection === -1) {
+ currentSection = 0;
+ }
+ if (!this.tabNavigation(selectors[currentSection], dir, false)) {
+ currentSection = (currentSection + selectors.length + dir) % selectors.length;
+ this.tabNavigation(selectors[currentSection], dir, false);
+ }
+ },
+
+ tabNavigation: function (selector, dir, loop) {
+ if (loop === undefined) {
+ loop = true;
+ }
+ 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]';
+ var 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);
+ }
+ });
+ return this._navigate(list, dir, ['focus'], loop);
+ },
+
+ _navigate: function (list, dir, actions, loop) {
+ if (loop === undefined) {
+ loop = true;
+ }
if (actions === undefined) {
actions = ['focus'];
}
var next;
if ($(items).has(document.activeElement)) {
var index = $(items).index(document.activeElement);
- next = (nb + index + dir) % nb;
+ if (loop) {
+ next = (nb + index + dir) % nb;
+ } else {
+ next = index + dir;
+ if (next >= nb || next < 0) {
+ return false;
+ }
+ }
} else {
if (dir === 1) {
next = 0;
}
}
var ne = $(items).eq(next);
- console.log(items, ne);
$.each(actions, function (k, action) {
if (action === 'focus') {
$(ne).focus();
$(ne).click();
}
});
- },
-
- 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]';
- var elements = $(selector).find(focusableElementsString);
- var list = [];
- $(elements).each(function () {
- if ($(this).attr('tabindex') == '-1') {
- return;
- }
- if ($(this).parents('[tabindex="-1"],.ignore-tab-children').length === 0 && $(this).is(':visible')) {
- list.push(this);
- }
- });
- this._navigate(list, dir);
+ return true;
},
initBookmarksShortcuts: function () {