]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - app/Resources/static/themes/material/index.js
Added mass actions for Material design in list view
[github/wallabag/wallabag.git] / app / Resources / static / themes / material / index.js
index 2926cad11c1d55fdaacd2af0054fe0b140e56f36..1c28401d907c7aec290cad75709489837616d777 100755 (executable)
@@ -17,6 +17,36 @@ import './js/shortcuts/entry';
 /* Theme style */
 import './css/index.scss';
 
+const stickyNav = () => {
+  const nav = $('.js-entry-nav-top');
+  $('[data-toggle="actions"]').click(() => {
+    nav.toggleClass('entry-nav-top--sticky');
+  });
+};
+
+const articleScroll = () => {
+  const articleEl = $('#article');
+  if (articleEl.length > 0) {
+    $(window).scroll(() => {
+      const s = $(window).scrollTop();
+      const d = $(document).height();
+      const c = $(window).height();
+      const articleElBottom = articleEl.offset().top + articleEl.height();
+      const scrollPercent = (s / (d - c)) * 100;
+      $('.progress .determinate').css('width', `${scrollPercent}%`);
+      const fixedActionBtn = $('.js-fixed-action-btn');
+      const toggleScrollDataName = 'toggle-auto';
+      if ((s + c) > articleElBottom) {
+        fixedActionBtn.data(toggleScrollDataName, true);
+        fixedActionBtn.openFAB();
+      } else if (fixedActionBtn.data(toggleScrollDataName) === true) {
+        fixedActionBtn.data(toggleScrollDataName, false);
+        fixedActionBtn.closeFAB();
+      }
+    });
+  }
+};
+
 $(document).ready(() => {
   // sideNav
   $('.button-collapse').sideNav();
@@ -27,15 +57,17 @@ $(document).ready(() => {
   $('.datepicker').pickadate({
     selectMonths: true,
     selectYears: 15,
-    formatSubmit: 'dd/mm/yyyy',
-    hiddenName: true,
-    format: 'dd/mm/yyyy',
+    formatSubmit: 'yyyy-mm-dd',
+    hiddenName: false,
+    format: 'yyyy-mm-dd',
     container: 'body',
   });
 
   initFilters();
   initExport();
   initRandom();
+  stickyNav();
+  articleScroll();
 
   const toggleNav = (toShow, toFocus) => {
     $('.nav-panel-actions').hide(100);
@@ -74,11 +106,16 @@ $(document).ready(() => {
     return false;
   });
 
-  $(window).scroll(() => {
-    const s = $(window).scrollTop();
-    const d = $(document).height();
-    const c = $(window).height();
-    const scrollPercent = (s / (d - c)) * 100;
-    $('.progress .determinate').css('width', `${scrollPercent}%`);
-  });
+  const mainCheckboxes = document.querySelectorAll('[data-js="checkboxes-toggle"]');
+  if (mainCheckboxes.length) {
+    [...mainCheckboxes].forEach((el) => {
+      el.addEventListener('click', () => {
+        const checkboxes = document.querySelectorAll(el.dataset.toggle);
+        [...checkboxes].forEach((checkbox) => {
+          const checkboxClone = checkbox;
+          checkboxClone.checked = el.checked;
+        });
+      });
+    });
+  }
 });