Przeglądaj źródła

new popup scrolls to top and restore it's previous position after closing again

Martin Filser 3 lat temu
rodzic
commit
949a3a1337
1 zmienionych plików z 20 dodań i 0 usunięć
  1. 20 0
      client/lib/popup.js

+ 20 - 0
client/lib/popup.js

@@ -29,6 +29,13 @@ window.Popup = new (class {
   open(name) {
     const self = this;
     const popupName = `${name}Popup`;
+    const $contentWrapper = $('.content-wrapper')
+    if ($contentWrapper.length > 0) {
+      const contentWrapper = $contentWrapper[0];
+      this._getTopStack().scrollTop = contentWrapper.scrollTop;
+      // scroll from e.g. delete comment to the top (where the confirm button is)
+      $contentWrapper.scrollTop(0);
+    }
     function clickFromPopup(evt) {
       return $(evt.target).closest('.js-pop-over').length !== 0;
     }
@@ -129,6 +136,19 @@ window.Popup = new (class {
   /// steps back is greater than the popup stack size, the popup will be closed.
   back(n = 1) {
     if (this._stack.length > n) {
+      const $contentWrapper = $('.content-wrapper')
+      if ($contentWrapper.length > 0) {
+        const contentWrapper = $contentWrapper[0];
+        const stack = this._stack[this._stack.length - 1 - n];
+        if (contentWrapper.scrollTopMax && stack.scrollTop > contentWrapper.scrollTopMax) {
+          // sometimes scrollTopMax is lower than scrollTop, so i need this dirty hack
+          setTimeout(() => {
+            $contentWrapper.scrollTop(stack.scrollTop);
+          }, 6);
+        }
+        // restore the old popup scroll position
+        $contentWrapper.scrollTop(stack.scrollTop);
+      }
       _.times(n, () => this._stack.pop());
       this._dep.changed();
     } else {