Compare commits

..
3 Commits
Author SHA1 Message Date
matmoul e16698ad39 Version 0.1.25 2026-11-16 22:54:33 +01:00
MatMoul 01cb753277 Merge pull request #195 from xan2622/fix-back-button
Fix Back button not returning to the parent folder
2026-11-16 22:50:55 +01:00
xan2622 f32a72210c Fix Back button not returning to the parent folder
The Back link used href="#" with an onclick calling history.back()
without preventing the default action: the fragment navigation was
applied before the asynchronous history traversal, which then only went
back to the same folder URL without '#'.

The Back link now targets the parent folder, so it also works when the
folder was opened in a new tab (no usable history). On a plain click,
when the previous history entry is the parent folder (checked with the
Navigation API when available), it goes back in history instead, so no
extra entry is added and the parent page state is restored. If the
traversal fails, the direct link is used. Modified clicks keep the
default link behavior.

Grid cells now reset their link target with removeAttribute('target'):
'delete link.target' is a no-op on an HTMLAnchorElement, so a cell that
had held a bookmark opened in a new tab kept target="_blank" after
paging, and a folder later shown there opened in a new tab despite the
'open folder' setting.

The dial URL building is shared by folder and Back links through
utils.getDialUrl, removing an unreachable branch (dial.path is never
empty).
2026-11-12 20:09:33 +01:00
2 changed files with 23 additions and 9 deletions

No files matched your search

+22 -8
View File
@@ -60,6 +60,11 @@ utils.getPath = function(){
if(path) return path + '/'; if(path) return path + '/';
else return '/'; else return '/';
}; };
utils.getDialUrl = function(path){
var url = '?bg=' + encodeURIComponent(app.settings.backgroundColor);
if(path) url += '&path=' + encodeURIComponent(path);
return url;
};
app.init = function(){ app.init = function(){
app.Messages.getSettings(function(settings){ app.Messages.getSettings(function(settings){
@@ -517,7 +522,7 @@ dial.populateGrid = function(){
link.Node = null; link.Node = null;
link.className = 'Empty'; link.className = 'Empty';
link.childNodes[0].style.backgroundImage = ''; link.childNodes[0].style.backgroundImage = '';
if(link.target) delete link.target; link.removeAttribute('target');
link.href = null; link.href = null;
link.onclick = null; link.onclick = null;
link.removeAttribute('contextmenu'); link.removeAttribute('contextmenu');
@@ -527,9 +532,19 @@ dial.populateGrid = function(){
link.className = 'Back'; link.className = 'Back';
link.childNodes[0].style.backgroundImage = ''; link.childNodes[0].style.backgroundImage = '';
link.childNodes[1].innerText = 'Back'; link.childNodes[1].innerText = 'Back';
if(link.target) delete link.target; link.removeAttribute('target');
link.href = '#'; var parentPath = dial.path.substring(0, dial.path.lastIndexOf('/', dial.path.length - 2));
link.onclick = function(){ window.history.back(); } link.href = utils.getDialUrl(parentPath);
link.onclick = function(e){
if(e.ctrlKey || e.shiftKey || e.altKey || e.metaKey) return;
if(!window.navigation || !navigation.canGoBack) return;
var previousUrl = navigation.entries()[navigation.currentEntry.index - 1].url;
if(!previousUrl) return;
previousUrl = new URL(previousUrl);
if(previousUrl.pathname != location.pathname || (previousUrl.searchParams.get('path') || '') != parentPath) return;
e.preventDefault();
navigation.back().committed.catch(function(){ location.assign(link.href); });
};
link.removeAttribute('contextmenu'); link.removeAttribute('contextmenu');
} }
populateFolder = function(link, node){ populateFolder = function(link, node){
@@ -544,14 +559,13 @@ dial.populateGrid = function(){
link.childNodes[1].innerText = node.title; link.childNodes[1].innerText = node.title;
switch(app.settings.grid.openFolderMethod){ switch(app.settings.grid.openFolderMethod){
case 0: case 0:
if(link.target) delete link.target; link.removeAttribute('target');
break; break;
case 1: case 1:
link.target = '_blank'; link.target = '_blank';
break; break;
} }
if(dial.path) link.href = '?' + 'bg=' + encodeURIComponent(app.settings.backgroundColor) + '&path=' + encodeURIComponent(dial.path + node.title); link.href = utils.getDialUrl(dial.path + node.title);
else link.href = '?' + 'bg=' + encodeURIComponent(app.settings.backgroundColor) + '&path=' + encodeURIComponent(node.title);
link.onclick = null; link.onclick = null;
link.setAttribute('contextmenu', 'item'); link.setAttribute('contextmenu', 'item');
} }
@@ -571,7 +585,7 @@ dial.populateGrid = function(){
link.childNodes[1].innerText = node.title; link.childNodes[1].innerText = node.title;
switch(app.settings.grid.openBookmarkMethod){ switch(app.settings.grid.openBookmarkMethod){
case 0: case 0:
if(link.target) delete link.target; link.removeAttribute('target');
break; break;
case 1: case 1:
link.target = '_blank'; link.target = '_blank';
+1 -1
View File
@@ -2,7 +2,7 @@
"manifest_version": 2, "manifest_version": 2,
"name": "Quick Dial", "name": "Quick Dial",
"version": "0.1.24", "version": "0.1.25",
"author": "MatMoul", "author": "MatMoul",
"homepage_url": "https://github.com/MatMoul/quickdial-webext", "homepage_url": "https://github.com/MatMoul/quickdial-webext",
"developer": { "developer": {