Move open parent and open root to background

This commit is contained in:
Shin'ya Ueoka 2019-05-24 21:51:18 +09:00
parent e779fb1779
commit 8d0739463d
8 changed files with 108 additions and 57 deletions

View file

@ -6,10 +6,6 @@ export default interface NavigationPresenter {
openLinkPrev(): void;
openLinkNext(): void;
openParent(): void;
openRoot(): void;
}
const REL_PATTERN: {[key: string]: RegExp} = {
@ -51,29 +47,6 @@ export class NavigationPresenterImpl implements NavigationPresenter {
this.linkRel('next');
}
openParent(): void {
const loc = window.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, '/');
}
}
openRoot(): void {
window.location.href = window.location.origin;
}
// Code common to linkPrev and linkNext which navigates to the specified page.
private linkRel(rel: 'prev' | 'next'): void {
let link = selectLast<HTMLLinkElement>(`link[rel~=${rel}][href]`);