|
@@ -2,6 +2,7 @@ import Container from './NativeDOM/Container.js';
|
|
|
import Footer from './NativeDOM/Footer.js';
|
|
|
import Melba from 'melba-toast';
|
|
|
import UI from './UI.js';
|
|
|
+import {trailingSlash} from '../trailingSlash.js';
|
|
|
|
|
|
export default class NativeDOM extends UI {
|
|
|
render(container = new Container(), footer = new Footer()) {
|
|
@@ -22,7 +23,17 @@ export default class NativeDOM extends UI {
|
|
|
return typeof element[`on${eventName}`] === 'function';
|
|
|
},
|
|
|
isTouch = supportsEvent('touchstart'),
|
|
|
- supportsDragDrop = supportsEvent('dragstart') && supportsEvent('drop')
|
|
|
+ supportsDragDrop = supportsEvent('dragstart') && supportsEvent('drop'),
|
|
|
+ updateTitle = (title) => {
|
|
|
+ if (document.title !== title) {
|
|
|
+ document.title = title;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ updatePath = (path) => {
|
|
|
+ if (location.pathname !== path) {
|
|
|
+ history.pushState(history.state, path, path);
|
|
|
+ }
|
|
|
+ }
|
|
|
;
|
|
|
|
|
|
// DOM events
|
|
@@ -37,16 +48,26 @@ export default class NativeDOM extends UI {
|
|
|
window.addEventListener('popstate', () => {
|
|
|
const url = location.pathname;
|
|
|
|
|
|
+ element.dispatchEvent(new CustomEvent('preview:close', {
|
|
|
+ bubbles: true,
|
|
|
+ detail: {
|
|
|
+ preview: true,
|
|
|
+ }
|
|
|
+ }));
|
|
|
+
|
|
|
if (url.endsWith('/')) {
|
|
|
return this.trigger('go');
|
|
|
}
|
|
|
|
|
|
- const parts = url.split(/\//),
|
|
|
- // file = parts.pop(),
|
|
|
- path = parts.join('/')
|
|
|
- ;
|
|
|
+ const path = url.replace(/[^/]+$/, '');
|
|
|
|
|
|
- this.trigger('go', path);
|
|
|
+ this.trigger('go', path, {
|
|
|
+ bypassPushState: true,
|
|
|
+ success: () => this.container
|
|
|
+ .querySelector(`main ul li[data-full-path="${url}"]`)
|
|
|
+ ?.dispatchEvent(new CustomEvent('click'))
|
|
|
+ ,
|
|
|
+ });
|
|
|
|
|
|
// trigger opening file
|
|
|
});
|
|
@@ -183,8 +204,16 @@ export default class NativeDOM extends UI {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- this.on('go', async (path = location.pathname, bypassCache = false, failure = null) => {
|
|
|
- const prevPath = location.pathname;
|
|
|
+ this.on('go', async (
|
|
|
+ path = location.pathname,
|
|
|
+ {
|
|
|
+ bypassCache = false,
|
|
|
+ bypassPushState = false,
|
|
|
+ failure = null,
|
|
|
+ success = null,
|
|
|
+ } = {}
|
|
|
+ ) => {
|
|
|
+ path = trailingSlash(path);
|
|
|
|
|
|
this.trigger('list:update:request', path);
|
|
|
|
|
@@ -203,14 +232,41 @@ export default class NativeDOM extends UI {
|
|
|
|
|
|
this.trigger('list:update:success', collection);
|
|
|
|
|
|
- if (path !== prevPath) {
|
|
|
- history.pushState(history.state, path, path);
|
|
|
+ if (! bypassPushState) {
|
|
|
+ updatePath(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ updateTitle(`${decodeURIComponent(path)} | WebDAV`);
|
|
|
+
|
|
|
+ if (success) {
|
|
|
+ success(collection);
|
|
|
}
|
|
|
+ });
|
|
|
|
|
|
- document.title = `${decodeURIComponent(path)} | WebDAV`;
|
|
|
+ this.on('preview:opened', (entry) => {
|
|
|
+ document.body.classList.add('preview-open');
|
|
|
+ this.container
|
|
|
+ .querySelector(`[data-full-path="${entry.fullPath}"]`)
|
|
|
+ ?.focus()
|
|
|
+ ;
|
|
|
+
|
|
|
+ updatePath(entry.fullPath);
|
|
|
+ updateTitle(`${decodeURIComponent(entry.fullPath)} | 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));
|
|
|
+ this.on('preview:closed', (entry, {
|
|
|
+ preview = false,
|
|
|
+ } = {}) => {
|
|
|
+ if (preview) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const path = trailingSlash(entry.path);
|
|
|
+
|
|
|
+ document.body.classList.remove('preview-open');
|
|
|
+
|
|
|
+ updatePath(path);
|
|
|
+ updateTitle(`${decodeURIComponent(path)} | WebDAV`);
|
|
|
+ });
|
|
|
}
|
|
|
}
|