Răsfoiți Sursa

memory list sort by column

El RIDO 5 ani în urmă
părinte
comite
b2751ca444
3 a modificat fișierele cu 55 adăugiri și 2 ștergeri
  1. 53 0
      js/privatebin.js
  2. 1 1
      tpl/bootstrap.php
  3. 1 1
      tpl/page.php

+ 53 - 0
js/privatebin.js

@@ -4359,6 +4359,53 @@ jQuery.PrivateBin = (function($, RawDeflate) {
             ).length > 0;
             ).length > 0;
         }
         }
 
 
+        /**
+         * sort the memory list by the given column offset
+         *
+         * @name   Memory.sort
+         * @private
+         * @function
+         * @param  {int} column
+         */
+        function sort(column)
+        {
+            let i, x, y, shouldSwitch, dir, switchcount = 0;
+            let table = $('#sidebar-wrapper table')[0];
+            let header = $('#sidebar-wrapper table thead tr th')[column];
+            let switching = true;
+            if (header.dataset.direction == 'asc') {
+                header.dataset.direction = 'desc';
+            } else {
+                header.dataset.direction = 'asc';
+            }
+            while (switching) {
+                switching = false;
+                let rows = table.rows;
+                // skip first row, containing headers
+                for (i = 1; i < (rows.length - 1); i++) {
+                    shouldSwitch = false;
+                    x = rows[i].getElementsByTagName("td")[column];
+                    y = rows[i + 1].getElementsByTagName("td")[column];
+                    if (header.dataset.direction == 'asc') {
+                        if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
+                            shouldSwitch = true;
+                            break;
+                        }
+                    } else if (header.dataset.direction == 'desc') {
+                        if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
+                            shouldSwitch = true;
+                            break;
+                        }
+                    }
+                }
+                if (shouldSwitch) {
+                    rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
+                    switching = true;
+                    switchcount ++;
+                }
+            }
+        }
+
         /**
         /**
          * called after successfully connecting to the indexedDB
          * called after successfully connecting to the indexedDB
          *
          *
@@ -4577,6 +4624,12 @@ jQuery.PrivateBin = (function($, RawDeflate) {
                 if (me.add(window.location.href))
                 if (me.add(window.location.href))
                     $('#menu-toggle').click();
                     $('#menu-toggle').click();
             });
             });
+            const headers = $('#sidebar-wrapper table thead tr th');
+            for (let i = 1; i < headers.length; i++) {
+                headers[i].addEventListener('click', function(e) {
+                    sort(i);
+                });
+            }
         };
         };
 
 
         return me;
         return me;

+ 1 - 1
tpl/bootstrap.php

@@ -72,7 +72,7 @@ endif;
 ?>
 ?>
 		<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.14.js" integrity="sha512-kbLhjIj/m/AW++o2eErCfqPueoX2btJo7VznhEC2YQRbVR/+Eup3w7thwDZwoCZ/gLrPxTX3W4H2KzupLg2PKA==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.14.js" integrity="sha512-kbLhjIj/m/AW++o2eErCfqPueoX2btJo7VznhEC2YQRbVR/+Eup3w7thwDZwoCZ/gLrPxTX3W4H2KzupLg2PKA==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
-		<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-nQ7uXojx+snSWAOLTI/kLNlNUL7w14Dm7Uy3hsgF5KQDUFjBb0Sbppg6RbsbjBtTvUnpkiNkK8YOFBTIPpxXZg==" crossorigin="anonymous"></script>
+		<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-HHR606wkEJVvf3XzEq81itazhXqfj3z54F2Hp2HfBPpUpXjvsI3DAxohlhOR669XLLS/k4v9+QCsQLNWegEA7A==" crossorigin="anonymous"></script>
 		<!-- icon -->
 		<!-- icon -->
 		<link rel="apple-touch-icon" href="<?php echo I18n::encode($BASEPATH); ?>img/apple-touch-icon.png" sizes="180x180" />
 		<link rel="apple-touch-icon" href="<?php echo I18n::encode($BASEPATH); ?>img/apple-touch-icon.png" sizes="180x180" />
 		<link rel="icon" type="image/png" href="img/favicon-32x32.png" sizes="32x32" />
 		<link rel="icon" type="image/png" href="img/favicon-32x32.png" sizes="32x32" />

+ 1 - 1
tpl/page.php

@@ -50,7 +50,7 @@ endif;
 ?>
 ?>
 		<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.14.js" integrity="sha512-kbLhjIj/m/AW++o2eErCfqPueoX2btJo7VznhEC2YQRbVR/+Eup3w7thwDZwoCZ/gLrPxTX3W4H2KzupLg2PKA==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.14.js" integrity="sha512-kbLhjIj/m/AW++o2eErCfqPueoX2btJo7VznhEC2YQRbVR/+Eup3w7thwDZwoCZ/gLrPxTX3W4H2KzupLg2PKA==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
-		<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-nQ7uXojx+snSWAOLTI/kLNlNUL7w14Dm7Uy3hsgF5KQDUFjBb0Sbppg6RbsbjBtTvUnpkiNkK8YOFBTIPpxXZg==" crossorigin="anonymous"></script>
+		<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-HHR606wkEJVvf3XzEq81itazhXqfj3z54F2Hp2HfBPpUpXjvsI3DAxohlhOR669XLLS/k4v9+QCsQLNWegEA7A==" crossorigin="anonymous"></script>
 		<!-- icon -->
 		<!-- icon -->
 		<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
 		<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
 		<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />
 		<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />