aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl/default/js/shaarli.js
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-03-27 19:14:52 +0200
committerArthurHoaro <arthur@hoa.ro>2017-05-08 14:28:19 +0200
commit638364987a42f8f48665ac29fdcbfc83de1de9e3 (patch)
tree97a09313699caa3fb2aabdf5a3874d0c245dfc85 /tpl/default/js/shaarli.js
parent29a837f347f53f751b723d466a2cd05fd92fd34e (diff)
downloadShaarli-638364987a42f8f48665ac29fdcbfc83de1de9e3.tar.gz
Shaarli-638364987a42f8f48665ac29fdcbfc83de1de9e3.tar.zst
Shaarli-638364987a42f8f48665ac29fdcbfc83de1de9e3.zip
Bulk deletion: remove JS ES6 syntax
Diffstat (limited to 'tpl/default/js/shaarli.js')
-rw-r--r--tpl/default/js/shaarli.js111
1 files changed, 46 insertions, 65 deletions
diff --git a/tpl/default/js/shaarli.js b/tpl/default/js/shaarli.js
index 7abd20b2..ceb1d1b8 100644
--- a/tpl/default/js/shaarli.js
+++ b/tpl/default/js/shaarli.js
@@ -216,14 +216,14 @@ window.onload = function () {
216 /** 216 /**
217 * Autofocus text fields 217 * Autofocus text fields
218 */ 218 */
219 // ES6 syntax 219 var autofocusElements = document.querySelectorAll('.autofocus');
220 let autofocusElements = document.querySelectorAll('.autofocus'); 220 var breakLoop = false;
221 for (let autofocusElement of autofocusElements) { 221 [].forEach.call(autofocusElements, function(autofocusElement) {
222 if (autofocusElement.value == '') { 222 if (autofocusElement.value == '' && ! breakLoop) {
223 autofocusElement.focus(); 223 autofocusElement.focus();
224 break; 224 breakLoop = true;
225 } 225 }
226 } 226 });
227 227
228 /** 228 /**
229 * Handle sub menus/forms 229 * Handle sub menus/forms
@@ -365,55 +365,52 @@ window.onload = function () {
365 365
366 /** 366 /**
367 * Bulk actions 367 * Bulk actions
368 *
369 * Note: Requires a modern browser.
370 */ 368 */
371 if (testEs6Compatibility()) { 369 var linkCheckboxes = document.querySelectorAll('.delete-checkbox');
372 let linkCheckboxes = document.querySelectorAll('.delete-checkbox'); 370 var bar = document.getElementById('actions');
373 for(let checkbox of linkCheckboxes) { 371 [].forEach.call(linkCheckboxes, function(checkbox) {
374 checkbox.style.display = 'block'; 372 checkbox.style.display = 'block';
375 checkbox.addEventListener('click', function(event) { 373 checkbox.addEventListener('click', function(event) {
376 let count = 0; 374 var count = 0;
377 for(let checkbox of linkCheckboxes) { 375 var linkCheckedCheckboxes = document.querySelectorAll('.delete-checkbox:checked');
378 count = checkbox.checked ? count + 1 : count; 376 [].forEach.call(linkCheckedCheckboxes, function(checkbox) {
379 } 377 count++;
380 let bar = document.getElementById('actions');
381 if (count == 0 && bar.classList.contains('open')) {
382 bar.classList.toggle('open');
383 } else if (count > 0 && ! bar.classList.contains('open')) {
384 bar.classList.toggle('open');
385 }
386 }); 378 });
387 } 379 if (count == 0 && bar.classList.contains('open')) {
380 bar.classList.toggle('open');
381 } else if (count > 0 && ! bar.classList.contains('open')) {
382 bar.classList.toggle('open');
383 }
384 });
385 });
388 386
389 let deleteButton = document.getElementById('actions-delete'); 387 var deleteButton = document.getElementById('actions-delete');
390 let token = document.querySelector('input[type="hidden"][name="token"]'); 388 var token = document.querySelector('input[type="hidden"][name="token"]');
391 if (deleteButton != null && token != null) { 389 if (deleteButton != null && token != null) {
392 deleteButton.addEventListener('click', function(event) { 390 deleteButton.addEventListener('click', function(event) {
393 event.preventDefault(); 391 event.preventDefault();
394 392
395 let links = []; 393 var links = [];
396 for(let checkbox of linkCheckboxes) { 394 var linkCheckedCheckboxes = document.querySelectorAll('.delete-checkbox:checked');
397 if (checkbox.checked) { 395 [].forEach.call(linkCheckedCheckboxes, function(checkbox) {
398 links.push({ 396 links.push({
399 'id': checkbox.value, 397 'id': checkbox.value,
400 'title': document.querySelector('.linklist-item[data-id="'+ checkbox.value +'"] .linklist-link').innerHTML 398 'title': document.querySelector('.linklist-item[data-id="'+ checkbox.value +'"] .linklist-link').innerHTML
401 }); 399 });
402 } 400 });
403 }
404 401
405 let message = 'Are you sure you want to delete '+ links.length +' links?\n'; 402 var message = 'Are you sure you want to delete '+ links.length +' links?\n';
406 message += 'This action is IRREVERSIBLE!\n\nTitles:\n'; 403 message += 'This action is IRREVERSIBLE!\n\nTitles:\n';
407 let ids = ''; 404 var ids = '';
408 for (let item of links) { 405 links.forEach(function(item) {
409 message += ' - '+ item['title'] +'\n'; 406 message += ' - '+ item['title'] +'\n';
410 ids += item['id'] +'+'; 407 ids += item['id'] +'+';
411 }
412 if (window.confirm(message)) {
413 window.location = '?delete_link&lf_linkdate='+ ids +'&token='+ token.value;
414 }
415 }); 408 });
416 } 409
410 if (window.confirm(message)) {
411 window.location = '?delete_link&lf_linkdate='+ ids +'&token='+ token.value;
412 }
413 });
417 } 414 }
418}; 415};
419 416
@@ -462,19 +459,3 @@ function hideTimezoneCities(cities, currentContinent, reset = false) {
462 } 459 }
463 }); 460 });
464} 461}
465
466/**
467 * Check if the browser is compatible with ECMAScript 6 syntax
468 *
469 * Source: http://stackoverflow.com/a/29046739/1484919
470 *
471 * @returns {boolean}
472 */
473function testEs6Compatibility()
474{
475 "use strict";
476
477 try { eval("var foo = (x)=>x+1"); }
478 catch (e) { return false; }
479 return true;
480}