Skip to content

Commit

Permalink
New: Library Navigation using side mouse buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
ollm authored Aug 11, 2024
1 parent aecc77b commit 96f4bb8
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 8 deletions.
36 changes: 33 additions & 3 deletions scripts/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,7 @@ function calculateVisibleItems(view, scrollTop = false)
return {start: start, end: end};
}

var indexPathControlA = [], indexPathA = false, indexMainPathA = false;
var indexPathControlA = [], indexPathA = false, indexMainPathA = false, indexPathControlForwards = [], fromGoForwards = false;

function indexPathControlGoBack()
{
Expand All @@ -1258,13 +1258,17 @@ function indexPathControlGoBack()
if(isFromIndexLabel && !isFromRecentlyOpened)
indexLabel = isFromIndexLabel;

indexPathControlForwards.push(indexPathControlA.pop());

if(isFromRecentlyOpened)
recentlyOpened.load(true);
else
loadIndexPage(true, false);
}
else if(indexPathControlA.length > 0)
{
console.log(indexPathControlA);

let goBack = indexPathControlA[indexPathControlA.length - 2];

indexLabel = goBack.indexLabel;
Expand All @@ -1274,13 +1278,33 @@ function indexPathControlGoBack()
else
loadIndexPage(true, goBack.path, false, false, goBack.mainPath, true);

indexPathControlA.pop();
indexPathControlForwards.push(indexPathControlA.pop());

indexPathA = goBack.path;
indexMainPathA = goBack.mainPath;
}
}

function indexPathControlGoForwards()
{
if(indexPathControlForwards.length > 0)
{
const goForwards = indexPathControlForwards.pop();

if(onReading)
reading.saveReadingProgress();

fromGoForwards = true;

if(goForwards.isComic)
openComic(true, goForwards.path, goForwards.mainPath, false, false);
else
loadIndexPage(true, goForwards.path, false, false, goForwards.mainPath, false);

fromGoForwards = false;
}
}

function indexPathControlUpdateLastComic(path = false)
{
let index = indexPathControlA.length - 1;
Expand Down Expand Up @@ -1320,10 +1344,15 @@ function indexPathControl(path = false, mainPath = false, isComic = false, fromN

if(index >= 0)
{
if(len > 0 && isComic && fromNextAndPrev && indexPathControlA[len-1].isComic) //
if(len > 0 && isComic && fromNextAndPrev && indexPathControlA[len-1].isComic)
{
indexPathControlA[len-1] = {file: files[index], path: path, mainPath: mainPath, isComic: isComic};
}
else
{
indexPathControlA.push({file: files[index], path: path, mainPath: mainPath, isComic: isComic});
if(!fromGoForwards) indexPathControlForwards = [];
}
}
}

Expand Down Expand Up @@ -2279,6 +2308,7 @@ module.exports = {
indexPathControl: indexPathControl,
indexPathControlA: function(){return indexPathControlA},
indexPathControlGoBack: indexPathControlGoBack,
indexPathControlGoForwards: indexPathControlGoForwards,
selectElement: selectElement,
openComic: openComic,
nextComic: function(){return skipNextComic},
Expand Down
34 changes: 31 additions & 3 deletions scripts/gamepad.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,12 +816,39 @@ function goBack(fromKeyboard = false)
}
}

setButtonEvent('browsableItems', [0, 2, 3, 9, 12, 13, 14, 15, 16], function(key) {
function goForwards(fromKeyboard = false)
{
if(fromKeyboard)
hasKeyboardNavigation = true;

// Close dialog
let dialogActive = document.querySelector('.dialogs .dialog');

if(dialogActive)
{
events.closeDialog();

return;
}

// Close menu
let menuActive = document.querySelector('.menu-close.a');

if(menuActive)
{
eval(menuActive.getAttribute('onclick'));

return;
}

// Go forwards
dom.indexPathControlGoForwards();
}

setButtonEvent('browsableItems', [0, 3, 9, 12, 13, 14, 15, 16], function(key) {

if(key == 0)
goHighlightItem();
else if(key == 2)
highlightItemContextMenu();
else if(key == 3)
highlightItemContextMenu();
else if(key == 12)
Expand Down Expand Up @@ -916,6 +943,7 @@ module.exports = {
updateBrowsableItemsPrevKey: updateBrowsableItemsPrevKey,
cleanBrowsableItems: cleanBrowsableItems,
goBack: goBack,
goForwards: goForwards,
buttonName: buttonName,
buttonKey: buttonKey,
buttonEvents: function(){return buttonEvents},
Expand Down
2 changes: 1 addition & 1 deletion scripts/reading.js
Original file line number Diff line number Diff line change
Expand Up @@ -4675,7 +4675,7 @@ async function read(path, index = 1, end = false, isCanvas = false, isEbook = fa

if(onReading && (!haveZoom || config.readingGlobalZoom) && !config.readingScrollWithMouse && readingViewIs('scroll'))
{
if(e.originalEvent.pointerType != 'touch')
if(e.originalEvent.pointerType != 'touch' && e.originalEvent.button >= 0 && e.originalEvent.button <= 2)
{
// e.preventDefault();

Expand Down
31 changes: 30 additions & 1 deletion scripts/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ function loadShortcuts()
'reload',
'search',
'searchFilter',
'prevChapter',
'nextChapter',
'goBack',
'goForwards',
],
actions: {
reload: {
Expand Down Expand Up @@ -72,12 +76,28 @@ function loadShortcuts()
return true;
},
},
goBack: {
name: language.global.back,
function: function(){
gamepad.goBack();
return true;
},
},
goForwards: {
name: language.global.forwards,
function: function(){
gamepad.goForwards();
return true;
},
},
},
shortcuts: {},
_shortcuts: {
'F5': 'reload',
'Ctrl+F': 'search',
'Ctrl+G': 'searchFilter',
'Mouse3': 'goBack',
'Mouse4': 'goForwards',
},
gamepad: {},
_gamepad: {
Expand All @@ -103,6 +123,7 @@ function loadShortcuts()
'resetZoom',
'fullscreen',
'goBack',
'goForwards',
'gamepadMenu',
],
actions: {
Expand Down Expand Up @@ -132,7 +153,7 @@ function loadShortcuts()

if(event instanceof PointerEvent)
{
if(event.type == 'contextmenu')
if(event.button != 2 || event.type != 'contextmenu')
return reading.rightClick(event);
else
return false;
Expand Down Expand Up @@ -299,6 +320,14 @@ function loadShortcuts()
return true;
},
},
goForwards: {
name: language.global.forwards,
function: function(){
if(inputIsFocused() || !reading.isLoaded()) return false;
gamepad.goForwards();
return true;
},
},
gamepadMenu: {
name: language.settings.shortcuts.gamepadMenu,
function: function(){
Expand Down
1 change: 1 addition & 0 deletions themes/material-design/reading.css
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
transform-origin: top left;
border: 0px;
background-color: white;
-webkit-user-drag: none;
}

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

0 comments on commit 96f4bb8

Please sign in to comment.