Move open parent and open root to background
This commit is contained in:
parent
e779fb1779
commit
8d0739463d
8 changed files with 108 additions and 57 deletions
|
@ -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]`);
|
||||
|
|
Reference in a new issue