Procházet zdrojové kódy

Add pushstate when previews are opened in lightbox and popstate when closed. Still work to do with potentially managing the popstate handler for files too. Potentially addresses the main problem in #59.

dom111 před 5 roky
rodič
revize
34725983be
3 změnil soubory, kde provedl 23 přidání a 2 odebrání
  1. 17 1
      src/lib/UI/NativeDOM.js
  2. 6 1
      src/lib/UI/NativeDOM/List/Item.js
  3. 0 0
      src/webdav-min.js

+ 17 - 1
src/lib/UI/NativeDOM.js

@@ -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) {
@@ -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));
   }
 }

+ 6 - 1
src/lib/UI/NativeDOM/List/Item.js

@@ -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)) {

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 0
src/webdav-min.js


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů