implement go-parent command

This commit is contained in:
Shin'ya Ueoka 2017-09-17 12:52:24 +09:00
parent 0be9776cb3
commit e9863299ab
6 changed files with 34 additions and 5 deletions

View file

@ -43,6 +43,8 @@ const execOperation = (operation) => {
return navigates.linkPrev(window);
case operations.NAVIGATE_LINK_NEXT:
return navigates.linkNext(window);
case operations.NAVIGATE_PARENT:
return navigates.parent(window);
}
};

View file

@ -44,4 +44,23 @@ const linkNext = (win) => {
}
};
export { historyPrev, historyNext, linkPrev, linkNext };
const parent = (win) => {
let loc = win.location;
if (loc.hash !== '') {
loc.hash = '';
return;
} else if (loc.search !== '') {
loc.search = '';
return;
}
const basenamePattern = /\/[^/]+$/;
const lastDirPattern = /\/[^/]+\/$/;
if (basenamePattern.test(loc.pathname)) {
loc.pathname = loc.pathname.replace(basenamePattern, '/');
} else if (lastDirPattern.test(loc.pathname)) {
loc.pathname = loc.pathname.replace(lastDirPattern, '/');
}
};
export { historyPrev, historyNext, linkPrev, linkNext, parent };