Skip to content

Commit 96f4bb8

Browse files
authored
New: Library Navigation using side mouse buttons
1 parent aecc77b commit 96f4bb8

File tree

5 files changed

+96
-8
lines changed

5 files changed

+96
-8
lines changed

scripts/dom.js

+33-3
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ function calculateVisibleItems(view, scrollTop = false)
12491249
return {start: start, end: end};
12501250
}
12511251

1252-
var indexPathControlA = [], indexPathA = false, indexMainPathA = false;
1252+
var indexPathControlA = [], indexPathA = false, indexMainPathA = false, indexPathControlForwards = [], fromGoForwards = false;
12531253

12541254
function indexPathControlGoBack()
12551255
{
@@ -1258,13 +1258,17 @@ function indexPathControlGoBack()
12581258
if(isFromIndexLabel && !isFromRecentlyOpened)
12591259
indexLabel = isFromIndexLabel;
12601260

1261+
indexPathControlForwards.push(indexPathControlA.pop());
1262+
12611263
if(isFromRecentlyOpened)
12621264
recentlyOpened.load(true);
12631265
else
12641266
loadIndexPage(true, false);
12651267
}
12661268
else if(indexPathControlA.length > 0)
12671269
{
1270+
console.log(indexPathControlA);
1271+
12681272
let goBack = indexPathControlA[indexPathControlA.length - 2];
12691273

12701274
indexLabel = goBack.indexLabel;
@@ -1274,13 +1278,33 @@ function indexPathControlGoBack()
12741278
else
12751279
loadIndexPage(true, goBack.path, false, false, goBack.mainPath, true);
12761280

1277-
indexPathControlA.pop();
1281+
indexPathControlForwards.push(indexPathControlA.pop());
12781282

12791283
indexPathA = goBack.path;
12801284
indexMainPathA = goBack.mainPath;
12811285
}
12821286
}
12831287

1288+
function indexPathControlGoForwards()
1289+
{
1290+
if(indexPathControlForwards.length > 0)
1291+
{
1292+
const goForwards = indexPathControlForwards.pop();
1293+
1294+
if(onReading)
1295+
reading.saveReadingProgress();
1296+
1297+
fromGoForwards = true;
1298+
1299+
if(goForwards.isComic)
1300+
openComic(true, goForwards.path, goForwards.mainPath, false, false);
1301+
else
1302+
loadIndexPage(true, goForwards.path, false, false, goForwards.mainPath, false);
1303+
1304+
fromGoForwards = false;
1305+
}
1306+
}
1307+
12841308
function indexPathControlUpdateLastComic(path = false)
12851309
{
12861310
let index = indexPathControlA.length - 1;
@@ -1320,10 +1344,15 @@ function indexPathControl(path = false, mainPath = false, isComic = false, fromN
13201344

13211345
if(index >= 0)
13221346
{
1323-
if(len > 0 && isComic && fromNextAndPrev && indexPathControlA[len-1].isComic) //
1347+
if(len > 0 && isComic && fromNextAndPrev && indexPathControlA[len-1].isComic)
1348+
{
13241349
indexPathControlA[len-1] = {file: files[index], path: path, mainPath: mainPath, isComic: isComic};
1350+
}
13251351
else
1352+
{
13261353
indexPathControlA.push({file: files[index], path: path, mainPath: mainPath, isComic: isComic});
1354+
if(!fromGoForwards) indexPathControlForwards = [];
1355+
}
13271356
}
13281357
}
13291358

@@ -2279,6 +2308,7 @@ module.exports = {
22792308
indexPathControl: indexPathControl,
22802309
indexPathControlA: function(){return indexPathControlA},
22812310
indexPathControlGoBack: indexPathControlGoBack,
2311+
indexPathControlGoForwards: indexPathControlGoForwards,
22822312
selectElement: selectElement,
22832313
openComic: openComic,
22842314
nextComic: function(){return skipNextComic},

scripts/gamepad.js

+31-3
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,39 @@ function goBack(fromKeyboard = false)
816816
}
817817
}
818818

819-
setButtonEvent('browsableItems', [0, 2, 3, 9, 12, 13, 14, 15, 16], function(key) {
819+
function goForwards(fromKeyboard = false)
820+
{
821+
if(fromKeyboard)
822+
hasKeyboardNavigation = true;
823+
824+
// Close dialog
825+
let dialogActive = document.querySelector('.dialogs .dialog');
826+
827+
if(dialogActive)
828+
{
829+
events.closeDialog();
830+
831+
return;
832+
}
833+
834+
// Close menu
835+
let menuActive = document.querySelector('.menu-close.a');
836+
837+
if(menuActive)
838+
{
839+
eval(menuActive.getAttribute('onclick'));
840+
841+
return;
842+
}
843+
844+
// Go forwards
845+
dom.indexPathControlGoForwards();
846+
}
847+
848+
setButtonEvent('browsableItems', [0, 3, 9, 12, 13, 14, 15, 16], function(key) {
820849

821850
if(key == 0)
822851
goHighlightItem();
823-
else if(key == 2)
824-
highlightItemContextMenu();
825852
else if(key == 3)
826853
highlightItemContextMenu();
827854
else if(key == 12)
@@ -916,6 +943,7 @@ module.exports = {
916943
updateBrowsableItemsPrevKey: updateBrowsableItemsPrevKey,
917944
cleanBrowsableItems: cleanBrowsableItems,
918945
goBack: goBack,
946+
goForwards: goForwards,
919947
buttonName: buttonName,
920948
buttonKey: buttonKey,
921949
buttonEvents: function(){return buttonEvents},

scripts/reading.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4675,7 +4675,7 @@ async function read(path, index = 1, end = false, isCanvas = false, isEbook = fa
46754675

46764676
if(onReading && (!haveZoom || config.readingGlobalZoom) && !config.readingScrollWithMouse && readingViewIs('scroll'))
46774677
{
4678-
if(e.originalEvent.pointerType != 'touch')
4678+
if(e.originalEvent.pointerType != 'touch' && e.originalEvent.button >= 0 && e.originalEvent.button <= 2)
46794679
{
46804680
// e.preventDefault();
46814681

scripts/shortcuts.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ function loadShortcuts()
3535
'reload',
3636
'search',
3737
'searchFilter',
38+
'prevChapter',
39+
'nextChapter',
40+
'goBack',
41+
'goForwards',
3842
],
3943
actions: {
4044
reload: {
@@ -72,12 +76,28 @@ function loadShortcuts()
7276
return true;
7377
},
7478
},
79+
goBack: {
80+
name: language.global.back,
81+
function: function(){
82+
gamepad.goBack();
83+
return true;
84+
},
85+
},
86+
goForwards: {
87+
name: language.global.forwards,
88+
function: function(){
89+
gamepad.goForwards();
90+
return true;
91+
},
92+
},
7593
},
7694
shortcuts: {},
7795
_shortcuts: {
7896
'F5': 'reload',
7997
'Ctrl+F': 'search',
8098
'Ctrl+G': 'searchFilter',
99+
'Mouse3': 'goBack',
100+
'Mouse4': 'goForwards',
81101
},
82102
gamepad: {},
83103
_gamepad: {
@@ -103,6 +123,7 @@ function loadShortcuts()
103123
'resetZoom',
104124
'fullscreen',
105125
'goBack',
126+
'goForwards',
106127
'gamepadMenu',
107128
],
108129
actions: {
@@ -132,7 +153,7 @@ function loadShortcuts()
132153

133154
if(event instanceof PointerEvent)
134155
{
135-
if(event.type == 'contextmenu')
156+
if(event.button != 2 || event.type != 'contextmenu')
136157
return reading.rightClick(event);
137158
else
138159
return false;
@@ -299,6 +320,14 @@ function loadShortcuts()
299320
return true;
300321
},
301322
},
323+
goForwards: {
324+
name: language.global.forwards,
325+
function: function(){
326+
if(inputIsFocused() || !reading.isLoaded()) return false;
327+
gamepad.goForwards();
328+
return true;
329+
},
330+
},
302331
gamepadMenu: {
303332
name: language.settings.shortcuts.gamepadMenu,
304333
function: function(){

themes/material-design/reading.css

+1
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214
transform-origin: top left;
215215
border: 0px;
216216
background-color: white;
217+
-webkit-user-drag: none;
217218
}
218219

219220
.reading-body:not(.zooming):not(.resizing) .r-img > oc-img > *.pixelated,/* .reading-lens:not(.zooming) .r-img > oc-img > *.pixelated,*/

0 commit comments

Comments
 (0)