Bulk deletion: remove JS ES6 syntax

This commit is contained in:
ArthurHoaro 2017-03-27 19:14:52 +02:00
parent 29a837f347
commit 638364987a

View file

@ -216,14 +216,14 @@ window.onload = function () {
/** /**
* Autofocus text fields * Autofocus text fields
*/ */
// ES6 syntax var autofocusElements = document.querySelectorAll('.autofocus');
let autofocusElements = document.querySelectorAll('.autofocus'); var breakLoop = false;
for (let autofocusElement of autofocusElements) { [].forEach.call(autofocusElements, function(autofocusElement) {
if (autofocusElement.value == '') { if (autofocusElement.value == '' && ! breakLoop) {
autofocusElement.focus(); autofocusElement.focus();
break; breakLoop = true;
}
} }
});
/** /**
* Handle sub menus/forms * Handle sub menus/forms
@ -365,56 +365,53 @@ window.onload = function () {
/** /**
* Bulk actions * Bulk actions
*
* Note: Requires a modern browser.
*/ */
if (testEs6Compatibility()) { var linkCheckboxes = document.querySelectorAll('.delete-checkbox');
let linkCheckboxes = document.querySelectorAll('.delete-checkbox'); var bar = document.getElementById('actions');
for(let checkbox of linkCheckboxes) { [].forEach.call(linkCheckboxes, function(checkbox) {
checkbox.style.display = 'block'; checkbox.style.display = 'block';
checkbox.addEventListener('click', function(event) { checkbox.addEventListener('click', function(event) {
let count = 0; var count = 0;
for(let checkbox of linkCheckboxes) { var linkCheckedCheckboxes = document.querySelectorAll('.delete-checkbox:checked');
count = checkbox.checked ? count + 1 : count; [].forEach.call(linkCheckedCheckboxes, function(checkbox) {
} count++;
let bar = document.getElementById('actions'); });
if (count == 0 && bar.classList.contains('open')) { if (count == 0 && bar.classList.contains('open')) {
bar.classList.toggle('open'); bar.classList.toggle('open');
} else if (count > 0 && ! bar.classList.contains('open')) { } else if (count > 0 && ! bar.classList.contains('open')) {
bar.classList.toggle('open'); bar.classList.toggle('open');
} }
}); });
} });
let deleteButton = document.getElementById('actions-delete'); var deleteButton = document.getElementById('actions-delete');
let token = document.querySelector('input[type="hidden"][name="token"]'); var token = document.querySelector('input[type="hidden"][name="token"]');
if (deleteButton != null && token != null) { if (deleteButton != null && token != null) {
deleteButton.addEventListener('click', function(event) { deleteButton.addEventListener('click', function(event) {
event.preventDefault(); event.preventDefault();
let links = []; var links = [];
for(let checkbox of linkCheckboxes) { var linkCheckedCheckboxes = document.querySelectorAll('.delete-checkbox:checked');
if (checkbox.checked) { [].forEach.call(linkCheckedCheckboxes, function(checkbox) {
links.push({ links.push({
'id': checkbox.value, 'id': checkbox.value,
'title': document.querySelector('.linklist-item[data-id="'+ checkbox.value +'"] .linklist-link').innerHTML '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'; var message = 'Are you sure you want to delete '+ links.length +' links?\n';
message += 'This action is IRREVERSIBLE!\n\nTitles:\n'; message += 'This action is IRREVERSIBLE!\n\nTitles:\n';
let ids = ''; var ids = '';
for (let item of links) { links.forEach(function(item) {
message += ' - '+ item['title'] +'\n'; message += ' - '+ item['title'] +'\n';
ids += item['id'] +'+'; ids += item['id'] +'+';
} });
if (window.confirm(message)) { if (window.confirm(message)) {
window.location = '?delete_link&lf_linkdate='+ ids +'&token='+ token.value; window.location = '?delete_link&lf_linkdate='+ ids +'&token='+ token.value;
} }
}); });
} }
}
}; };
function activateFirefoxSocial(node) { function activateFirefoxSocial(node) {
@ -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;
}