]> git.ktnx.net Git - lsl.git/commitdiff
pop a "Check all" / "Clear all" button when multiple items are checked/cleared in...
authorDamyan Ivanov <dmn@debian.org>
Mon, 7 Mar 2022 21:33:54 +0000 (21:33 +0000)
committerDamyan Ivanov <dmn@debian.org>
Mon, 7 Mar 2022 21:33:54 +0000 (21:33 +0000)
public/css/style.css
public/javascripts/lsl.js
views/index.tt

index 4b1a73c0d751d6a76cf0b37f886d7ba651714e52..7ed1eef1778a010a3dae1aa876011e8a56397e61 100644 (file)
@@ -63,6 +63,7 @@ background-color: white;
 border: 3px solid #aaa;
 border-top: none;
 padding: 1em;
+box-sizing: border-box;
 }
 
 #sidebar {
@@ -280,3 +281,19 @@ ul#list-items {
     width: 100%;
     box-sizing: border-box;
 }
+#item-multi-action {
+    display: block;
+    position: fixed;
+    top: -3em;
+    opacity: 0;
+    transition: .5s cubic-bezier(0.0, 0.0, 0.0, 1.0);
+    background: white;
+    box-shadow: 0 0 1em 1ex white;
+}
+#item-multi-action.in-view {
+    top: 4em;
+    opacity: 1;
+}
+#item-multi-action button { display: none; }
+#item-multi-action.checking button#btn-check-all { display: block; }
+#item-multi-action.clearing button#btn-clear-all { display: block; }
index f7efa52f72236622f57796a2b84a501f4ec95e6e..bb9778e6e73b354cea06b1e516dac8134c03239c 100644 (file)
@@ -8,6 +8,7 @@ var uri_id_re = new RegExp('/(\\d+)$');
 var lists_version = -1;
 var lists = [];
 var selected_list;
+var last_item_action, last_item_action_stamp, item_action_streak = 0;
 
 function debug(...args) {
     if (devel_env)
@@ -373,10 +374,56 @@ function handle_new_list_item_submission(){
     )
     .done(new_list_item_submission_done);
 }
+function reposition_item_multi_action() {
+    var box = $('#item-multi-action');
+    var cnt = $('#content');
+    var cnt_x = cnt.offset().left;
+    var cnt_w = cnt.css('width').replace('px', '');
+    var box_w = box.width();
+
+    box.css('left', cnt_x + cnt_w / 2 - box_w / 2);
+}
 function handle_list_item_state_changed(ev) {
     var item = $(ev.target).closest('li');
     var cb = item.find('input[type="checkbox"]');
 
+    var action = cb.prop('checked') ? 'check' : 'clear';
+    var now = new Date();
+    var since_last_action = now - last_item_action_stamp;
+
+    console.debug(action, last_item_action, now - last_item_action_stamp, item_action_streak);
+    if (last_item_action
+        && last_item_action == action
+        && since_last_action < 3000)
+    {
+        item_action_streak ++;
+
+        if (item_action_streak > 2
+            && ( action == 'check' && $('#list-items input[type="checkbox"]').not(':checked').length
+                || action == 'clear' && $('#list-items input[type="checkbox"]').filter(':checked').length
+            )
+        ) {
+            var box = $('#item-multi-action')
+                .removeClass('checking clearing')
+                .addClass(action+'ing')
+                .addClass('in-view');
+            reposition_item_multi_action();
+            var old_timer = box.data('lsl-hide-timer');
+            if (old_timer)
+                window.clearTimeout(old_timer);
+
+            box.data('lsl-hide-timer', window.setTimeout(() => {
+                box.removeClass('in-view').data('lsl-hide-timer', false);
+            }, 3000));
+        }
+    }
+    else {
+        item_action_streak = 1;
+    }
+
+    last_item_action = action;
+    last_item_action_stamp = now;
+
     $.ajax(item.data('lsl-uri'),
         {   type: 'PUT',
             data: JSON.stringify({
@@ -450,5 +497,14 @@ $(function(){
     $('body').on('click', '.ui-widget-overlay', (ev) => {
         $(ev.target).siblings('.ui-dialog').find('.ui-dialog-content').dialog('close');
     });
+    $(window).on('resize', () => { reposition_item_multi_action(); });
+    $('#btn-check-all').click((ev) => {
+        $('#list-items input[type="checkbox"]').not(':checked').prop('checked', true).trigger('change');
+        return false;
+    });
+    $('#btn-clear-all').click((ev) => {
+        $('#list-items input[type="checkbox"]').filter(':checked').prop('checked', false).trigger('change');
+        return false;
+    });
 });
 })();
index 069f5f4df84251d3dee7f8ca99a511a96220e712..cacb56f511252e1d51e550793455b33e3632ff4e 100644 (file)
         <button id="add-list-item" class="ui-icon-plusthick">Add</button>
       </div>
     </div>
+    <div id="item-multi-action">
+      <button id="btn-check-all">Check all</button>
+      <button id="btn-clear-all">Clear all</button>
+    </div>
   </div>
 
   <div id="sidebar">
@@ -52,4 +56,5 @@
     </ul>
   </div>
 </div>
+
 <!-- vim: set ft=html sw=2 :-->