]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - app/Resources/static/themes/material/index.js
Set progress
[github/wallabag/wallabag.git] / app / Resources / static / themes / material / index.js
index d6afbb8a32eba702d7a68e255608e02c30889e2c..408528ea92de08ccbd5b02e1c4834062d5007a23 100755 (executable)
@@ -75,4 +75,37 @@ $(document).ready(() => {
     const scrollPercent = (s / (d - c)) * 100;
     $('.progress .determinate').css('width', `${scrollPercent}%`);
   });
+
+/* ==========================================================================
+   Annotations & Remember position
+   ========================================================================== */
+
+  if ($('article').length) {
+    const app = new annotator.App();
+    const x = JSON.parse($('#annotationroutes').html());
+
+    app.include(annotator.ui.main, {
+      element: document.querySelector('article'),
+    });
+
+    app.include(annotator.storage.http, x);
+
+    app.start().then(() => {
+      app.annotations.load({ entry: x.entryId });
+    });
+
+    window.addEventListener('unload', () => {
+      const scrollTop = $(window).scrollTop();
+      const docHeight = $(document).height();
+      const scrollPercent = (scrollTop) / (docHeight);
+      const scrollPercentRounded = Math.round(scrollPercent * 100) / 100;
+      savePercent(x.entryId, scrollPercentRounded);
+    });
+
+    retrievePercent(x.entryId);
+
+    $(window).resize(() => {
+      retrievePercent(x.entryId);
+    });
+  }
 });