]> 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 96310d81fdb3ca635a5e86ea307c5b895bfe19eb..1c28401d907c7aec290cad75709489837616d777 100755 (executable)
@@ -8,7 +8,7 @@ import 'materialize-css/dist/js/materialize';
 import '../_global/index';
 
 /* Tools */
-import { initExport, initFilters } from './js/tools';
+import { initExport, initFilters, initRandom } from './js/tools';
 
 /* Import shortcuts */
 import './js/shortcuts/main';
@@ -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,13 +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);
@@ -48,30 +82,40 @@ $(document).ready(() => {
     $('#tag_label').focus();
     return false;
   });
+
   $('#nav-btn-add').on('click', () => {
     toggleNav('.nav-panel-add', '#entry_url');
     return false;
   });
+
   const materialAddForm = $('.nav-panel-add');
   materialAddForm.on('submit', () => {
     materialAddForm.addClass('disabled');
     $('input#entry_url', materialAddForm).prop('readonly', true).trigger('blur');
   });
+
   $('#nav-btn-search').on('click', () => {
     toggleNav('.nav-panel-search', '#search_entry_term');
     return false;
   });
+
   $('.close').on('click', (e) => {
     $(e.target).parent('.nav-panel-item').hide(100);
     $('.nav-panel-actions').show(100);
     $('.nav-panels').css('background', 'transparent');
     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;
+        });
+      });
+    });
+  }
 });