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');
} 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>';
}
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();
}
}
});
+
+ 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();
}
});
- var ret = {shortcuts: res.join(', '), options: {splitKey: splitKey}};
- return ret;
+ return {shortcuts: res.join(', '), options: {splitKey: splitKey}};
},
ariaShortcut: function (shortcuts, func) {
},
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
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;
} 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');
}
return;
}
+ this.setOriginPct(0.5, 0.5, true, true);
this.setZoom(1, -1);
if (callback) {
setTimeout(function () {