Skip to content

Commit

Permalink
Add pushstate when previews are opened in lightbox and popstate when …
Browse files Browse the repository at this point in the history
…closed. Still work to do with potentially managing the popstate handler for files too. Potentially addresses the main problem in #59.
  • Loading branch information
dom111 committed May 6, 2020
1 parent 9c292f1 commit 3472598
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
18 changes: 17 additions & 1 deletion src/lib/UI/NativeDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ export default class NativeDOM extends UI {
}

window.addEventListener('popstate', () => {
this.trigger('go');
const url = location.pathname;

if (url.endsWith('/')) {
return this.trigger('go');
}

const parts = url.split(/\//),
// file = parts.pop(),
path = parts.join('/')
;

this.trigger('go', path);

// trigger opening file
});

if (supportsDragDrop) {
Expand Down Expand Up @@ -196,5 +209,8 @@ export default class NativeDOM extends UI {

document.title = `${decodeURIComponent(path)} | WebDAV`;
});

this.on('preview:opened', (entry) => history.pushState(history.state, entry.fullPath, entry.fullPath));
this.on('preview:closed', (entry) => history.pushState(history.state, entry.path, entry.path));
}
}
7 changes: 6 additions & 1 deletion src/lib/UI/NativeDOM/List/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,16 @@ export default class Item extends Element {
onShow(lightbox);
}
},
onClose: () => document.removeEventListener('keydown', escapeListener)
onClose: () => {
document.removeEventListener('keydown', escapeListener);
this.trigger('preview:closed', this.#entry);
}
})
;

lightbox.show();

this.trigger('preview:opened', this.#entry);
};

if (['video', 'audio', 'image', 'font', 'pdf'].includes(entry.type)) {
Expand Down
2 changes: 1 addition & 1 deletion src/webdav-min.js

Large diffs are not rendered by default.

0 comments on commit 3472598

Please sign in to comment.