]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
tmp
authorArthurHoaro <arthur@hoa.ro>
Sat, 7 Jan 2017 17:12:24 +0000 (18:12 +0100)
committerArthurHoaro <arthur@hoa.ro>
Sat, 7 Jan 2017 17:12:24 +0000 (18:12 +0100)
tpl/default/js/shaarli.js
tpl/default/linklist.paging.html

index a382a7ebe9d83cc83c28b7b925192c7022c8fcb4..ebe0b5218e91328233462e23b58e95677f08c157 100644 (file)
@@ -56,46 +56,79 @@ function getParentByClass(el, className) {
 /**
  * Fold/Expand shaares description and thumbnail.
  */
-var foldButtons = document.querySelectorAll('.fold-button');
-[].forEach.call(foldButtons, function(foldButton) {
-    // Retrieve description
-    var description = null;
-    var thumbnail = null;
-    var linklistItem = getParentByClass(foldButton, 'linklist-item');
-    if (linklistItem != null) {
-        description = linklistItem.querySelector('.linklist-item-description');
-        thumbnail = linklistItem.querySelector('.linklist-item-thumbnail');
-        if (description != null || thumbnail != null) {
-            foldButton.style.display = 'inline';
+(function (window, document) {
+    var foldAllButtons = document.getElementsByClassName('fold-all');
+    var foldButtons = document.getElementsByClassName('fold-button');
+
+    [].forEach.call(foldButtons, function (foldButton) {
+        // Retrieve description
+        var description = null;
+        var thumbnail = null;
+        var linklistItem = getParentByClass(foldButton, 'linklist-item');
+        if (linklistItem != null) {
+            description = linklistItem.querySelector('.linklist-item-description');
+            thumbnail = linklistItem.querySelector('.linklist-item-thumbnail');
+            if (description != null || thumbnail != null) {
+                foldButton.style.display = 'inline';
+            }
         }
-    }
 
-    foldButton.addEventListener('click', function(event) {
-        event.preventDefault();
+        foldButton.addEventListener('click', function (event) {
+            event.preventDefault();
+            toggleFold(event.target, description, thumbnail);
+        });
+    });
 
-        // Switch fold/expand - up = fold
-        if (event.target.classList.contains('fa-chevron-up')) {
-            event.target.title = 'Expand';
-            if (description != null) {
-                description.style.display = 'none';
-            }
-            if (thumbnail != null) {
-                thumbnail.style.display = 'none';
-            }
+    if (foldAllButtons != null) {
+        [].forEach.call(foldAllButtons, function (foldAllButton) {
+            foldAllButton.addEventListener('click', function (event) {
+                event.preventDefault();
+                [].forEach.call(foldButtons, function (foldButton) {
+                    // Retrieve description
+                    var description = null;
+                    var thumbnail = null;
+                    var linklistItem = getParentByClass(foldButton, 'linklist-item');
+                    if (linklistItem != null) {
+                        description = linklistItem.querySelector('.linklist-item-description');
+                        thumbnail = linklistItem.querySelector('.linklist-item-thumbnail');
+                        if (description != null || thumbnail != null) {
+                            foldButton.style.display = 'inline';
+                        }
+                    }
+
+                    toggleFold(foldButton.firstElementChild, description, thumbnail);
+                });
+                foldAllButton.firstElementChild.classList.toggle('fa-chevron-down');
+                foldAllButton.firstElementChild.classList.toggle('fa-chevron-up');
+            });
+        });
+    }
+})(this, this.document);
+
+function toggleFold(button, description, thumb)
+{
+    // Switch fold/expand - up = fold
+    if (button.classList.contains('fa-chevron-up')) {
+        button.title = 'Expand';
+        if (description != null) {
+            description.style.display = 'none';
         }
-        else {
-            event.target.title = 'Fold';
-            if (description != null) {
-                description.style.display = 'block';
-            }
-            if (thumbnail != null) {
-                thumbnail.style.display = 'block';
-            }
+        if (thumb != null) {
+            thumb.style.display = 'none';
         }
-        event.target.classList.toggle('fa-chevron-down');
-        event.target.classList.toggle('fa-chevron-up');
-    });
-});
+    }
+    else {
+        button.title = 'Fold';
+        if (description != null) {
+            description.style.display = 'block';
+        }
+        if (thumb != null) {
+            thumb.style.display = 'block';
+        }
+    }
+    button.classList.toggle('fa-chevron-down');
+    button.classList.toggle('fa-chevron-up');
+}
 
 /**
  * Confirmation message before deletion.
index 0b71c9d2e04e8959bd1b1339976e72193faf74be..a48f4c184d88f24ef292842fc0361dfbfd45980b 100644 (file)
@@ -13,6 +13,9 @@
                  class={if="$privateonly"}"filter-on"{else}"filter-off"{/if}
               ><i class="fa fa-key"></i></a>
             {/if}
+            <a href="#" class="filter-off fold-all" title="Fold all">
+              <i class="fa fa-chevron-up"></i>
+            </a>
             {loop="$action_plugin"}
               {$value.attr.class=isset($value.attr.class) ? $value.attr.class : ''}
               {$value.attr.class=!empty($value.on) ? $value.attr.class .' filter-on' : $value.attr.class .' filter-off'}