]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Bulk deletion: remove JS ES6 syntax 819/head
authorArthurHoaro <arthur@hoa.ro>
Mon, 27 Mar 2017 17:14:52 +0000 (19:14 +0200)
committerArthurHoaro <arthur@hoa.ro>
Mon, 8 May 2017 12:28:19 +0000 (14:28 +0200)
tpl/default/js/shaarli.js

index 7abd20b24fc61c54b1359d0c08456c35d51ba612..ceb1d1b863fd096a437ff24e8ac1b661e07347f8 100644 (file)
@@ -216,14 +216,14 @@ window.onload = function () {
     /**
      * Autofocus text fields
      */
-    // ES6 syntax
-    let autofocusElements = document.querySelectorAll('.autofocus');
-    for (let autofocusElement of autofocusElements) {
-        if (autofocusElement.value == '') {
+    var autofocusElements = document.querySelectorAll('.autofocus');
+    var breakLoop = false;
+    [].forEach.call(autofocusElements, function(autofocusElement) {
+        if (autofocusElement.value == '' && ! breakLoop) {
             autofocusElement.focus();
-            break;
+            breakLoop = true;
         }
-    }
+    });
 
     /**
      * Handle sub menus/forms
@@ -365,55 +365,52 @@ window.onload = function () {
 
     /**
      * Bulk actions
-     *
-     * Note: Requires a modern browser.
      */
-    if (testEs6Compatibility()) {
-        let linkCheckboxes = document.querySelectorAll('.delete-checkbox');
-        for(let checkbox of linkCheckboxes) {
-            checkbox.style.display = 'block';
-            checkbox.addEventListener('click', function(event) {
-                let count = 0;
-                for(let checkbox of linkCheckboxes) {
-                    count = checkbox.checked ? count + 1 : count;
-                }
-                let bar = document.getElementById('actions');
-                if (count == 0 && bar.classList.contains('open')) {
-                    bar.classList.toggle('open');
-                } else if (count > 0 && ! bar.classList.contains('open')) {
-                    bar.classList.toggle('open');
-                }
+    var linkCheckboxes = document.querySelectorAll('.delete-checkbox');
+    var bar = document.getElementById('actions');
+    [].forEach.call(linkCheckboxes, function(checkbox) {
+        checkbox.style.display = 'block';
+        checkbox.addEventListener('click', function(event) {
+            var count = 0;
+            var linkCheckedCheckboxes = document.querySelectorAll('.delete-checkbox:checked');
+            [].forEach.call(linkCheckedCheckboxes, function(checkbox) {
+                count++;
             });
-        }
+            if (count == 0 && bar.classList.contains('open')) {
+                bar.classList.toggle('open');
+            } else if (count > 0 && ! bar.classList.contains('open')) {
+                bar.classList.toggle('open');
+            }
+        });
+    });
 
-        let deleteButton = document.getElementById('actions-delete');
-        let token = document.querySelector('input[type="hidden"][name="token"]');
-        if (deleteButton != null && token != null) {
-            deleteButton.addEventListener('click', function(event) {
-                event.preventDefault();
+    var deleteButton = document.getElementById('actions-delete');
+    var token = document.querySelector('input[type="hidden"][name="token"]');
+    if (deleteButton != null && token != null) {
+        deleteButton.addEventListener('click', function(event) {
+            event.preventDefault();
 
-                let links = [];
-                for(let checkbox of linkCheckboxes) {
-                    if (checkbox.checked) {
-                        links.push({
-                            'id': checkbox.value,
-                            'title': document.querySelector('.linklist-item[data-id="'+ checkbox.value +'"] .linklist-link').innerHTML
-                        });
-                    }
-                }
+            var links = [];
+            var linkCheckedCheckboxes = document.querySelectorAll('.delete-checkbox:checked');
+            [].forEach.call(linkCheckedCheckboxes, function(checkbox) {
+                links.push({
+                    'id': checkbox.value,
+                    'title': document.querySelector('.linklist-item[data-id="'+ checkbox.value +'"] .linklist-link').innerHTML
+                });
+            });
 
-                let message = 'Are you sure you want to delete '+ links.length +' links?\n';
-                message += 'This action is IRREVERSIBLE!\n\nTitles:\n';
-                let ids = '';
-                for (let item of links) {
-                    message += '  - '+ item['title'] +'\n';
-                    ids += item['id'] +'+';
-                }
-                if (window.confirm(message)) {
-                    window.location = '?delete_link&lf_linkdate='+ ids +'&token='+ token.value;
-                }
+            var message = 'Are you sure you want to delete '+ links.length +' links?\n';
+            message += 'This action is IRREVERSIBLE!\n\nTitles:\n';
+            var ids = '';
+            links.forEach(function(item) {
+                message += '  - '+ item['title'] +'\n';
+                ids += item['id'] +'+';
             });
-        }
+
+            if (window.confirm(message)) {
+                window.location = '?delete_link&lf_linkdate='+ ids +'&token='+ token.value;
+            }
+        });
     }
 };
 
@@ -462,19 +459,3 @@ function hideTimezoneCities(cities, currentContinent, reset = false) {
         }
     });
 }
-
-/**
- * Check if the browser is compatible with ECMAScript 6 syntax
- *
- * Source: http://stackoverflow.com/a/29046739/1484919
- *
- * @returns {boolean}
- */
-function testEs6Compatibility()
-{
-    "use strict";
-
-    try { eval("var foo = (x)=>x+1"); }
-    catch (e) { return false; }
-    return true;
-}