]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - app/Resources/static/themes/_global/js/tools.js
Set progress
[github/wallabag/wallabag.git] / app / Resources / static / themes / _global / js / tools.js
index 774f45399b1efc147ae4b072bf3665d939518093..6386688ba58a32942270cffacb579de363e37cc9 100644 (file)
@@ -5,30 +5,58 @@ import './shortcuts/entry';
 /* Allows inline call qr-code call */
 import jrQrcode from 'jr-qrcode'; // eslint-disable-line
 
-function supportsLocalStorage() {
-  try {
-    return 'localStorage' in window && window.localStorage !== null;
-  } catch (e) {
-    return false;
-  }
-}
-
 function savePercent(id, percent) {
-  if (!supportsLocalStorage()) { return false; }
-  localStorage[`wallabag.article.${id}.percent`] = percent;
-  return true;
+  fetch(`/progress/${id}/${percent * 100}`, { credentials: 'include' });
 }
 
-function retrievePercent(id) {
-  if (!supportsLocalStorage()) { return false; }
-
-  const bheight = $(document).height();
-  const percent = localStorage[`wallabag.article.${id}.percent`];
-  const scroll = bheight * percent;
+function retrievePercent() {
+  const percent = $('#article').attr('data-progress');
+  console.log(percent);
+  const scroll = $(document).height() * percent;
 
   $('html,body').animate({ scrollTop: scroll }, 'fast');
+}
+
+function initFilters() {
+  // no display if filters not available
+  if ($('div').is('#filters')) {
+    $('#button_filters').show();
+    $('.js-filters-action').sideNav({ edge: 'right' });
+    $('#clear_form_filters').on('click', () => {
+      $('#filters input').val('');
+      $('#filters :checked').removeAttr('checked');
+      return false;
+    });
+  }
+}
+
+function initExport() {
+  // no display if export not available
+  if ($('div').is('#export')) {
+    $('#button_export').show();
+    $('.js-export-action').sideNav({ edge: 'right' });
+  }
+}
 
-  return true;
+function throttle(callback, delay) {
+  let last;
+  let timer;
+  return function () {
+    const context = this;
+    const now = new Date();
+    const args = arguments;
+    if (last && now < last + delay) {
+      // le délai n'est pas écoulé on reset le timer
+      clearTimeout(timer);
+      timer = setTimeout(function () {
+        last = now;
+        callback.apply(context, args);
+      }, delay);
+    } else {
+      last = now;
+      callback.apply(context, args);
+    }
+  };
 }
 
-export { savePercent, retrievePercent };
+export { savePercent, retrievePercent, initFilters, initExport, throttle };