diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-03-12 19:03:50 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-05-08 14:27:20 +0200 |
commit | 29a837f347f53f751b723d466a2cd05fd92fd34e (patch) | |
tree | 5f477d220b7b8c1987b2b337dd69ceb26edc3f0b /tpl/default/js | |
parent | bf67ac345f588130e98e784b4ee4740b0dad83fc (diff) | |
download | Shaarli-29a837f347f53f751b723d466a2cd05fd92fd34e.tar.gz Shaarli-29a837f347f53f751b723d466a2cd05fd92fd34e.tar.zst Shaarli-29a837f347f53f751b723d466a2cd05fd92fd34e.zip |
Bulk deletion
* Add a checkboxes in linklist which display a sub-header containing action buttons
* Strongly rely on JS
* Requires a modern browser (ES6 syntax support)
* Checkboxes are hidden if the browser is old or JS disabled
Diffstat (limited to 'tpl/default/js')
-rw-r--r-- | tpl/default/js/shaarli.js | 73 |
1 files changed, 71 insertions, 2 deletions
diff --git a/tpl/default/js/shaarli.js b/tpl/default/js/shaarli.js index 4d47fcd0..7abd20b2 100644 --- a/tpl/default/js/shaarli.js +++ b/tpl/default/js/shaarli.js | |||
@@ -357,11 +357,64 @@ window.onload = function () { | |||
357 | var continent = document.getElementById('continent'); | 357 | var continent = document.getElementById('continent'); |
358 | var city = document.getElementById('city'); | 358 | var city = document.getElementById('city'); |
359 | if (continent != null && city != null) { | 359 | if (continent != null && city != null) { |
360 | continent.addEventListener('change', function(event) { | 360 | continent.addEventListener('change', function (event) { |
361 | hideTimezoneCities(city, continent.options[continent.selectedIndex].value, true); | 361 | hideTimezoneCities(city, continent.options[continent.selectedIndex].value, true); |
362 | }); | 362 | }); |
363 | hideTimezoneCities(city, continent.options[continent.selectedIndex].value, false); | 363 | hideTimezoneCities(city, continent.options[continent.selectedIndex].value, false); |
364 | } | 364 | } |
365 | |||
366 | /** | ||
367 | * Bulk actions | ||
368 | * | ||
369 | * Note: Requires a modern browser. | ||
370 | */ | ||
371 | if (testEs6Compatibility()) { | ||
372 | let linkCheckboxes = document.querySelectorAll('.delete-checkbox'); | ||
373 | for(let checkbox of linkCheckboxes) { | ||
374 | checkbox.style.display = 'block'; | ||
375 | checkbox.addEventListener('click', function(event) { | ||
376 | let count = 0; | ||
377 | for(let checkbox of linkCheckboxes) { | ||
378 | count = checkbox.checked ? count + 1 : count; | ||
379 | } | ||
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 | }); | ||
387 | } | ||
388 | |||
389 | let deleteButton = document.getElementById('actions-delete'); | ||
390 | let token = document.querySelector('input[type="hidden"][name="token"]'); | ||
391 | if (deleteButton != null && token != null) { | ||
392 | deleteButton.addEventListener('click', function(event) { | ||
393 | event.preventDefault(); | ||
394 | |||
395 | let links = []; | ||
396 | for(let checkbox of linkCheckboxes) { | ||
397 | if (checkbox.checked) { | ||
398 | links.push({ | ||
399 | 'id': checkbox.value, | ||
400 | 'title': document.querySelector('.linklist-item[data-id="'+ checkbox.value +'"] .linklist-link').innerHTML | ||
401 | }); | ||
402 | } | ||
403 | } | ||
404 | |||
405 | let message = 'Are you sure you want to delete '+ links.length +' links?\n'; | ||
406 | message += 'This action is IRREVERSIBLE!\n\nTitles:\n'; | ||
407 | let ids = ''; | ||
408 | for (let item of links) { | ||
409 | message += ' - '+ item['title'] +'\n'; | ||
410 | ids += item['id'] +'+'; | ||
411 | } | ||
412 | if (window.confirm(message)) { | ||
413 | window.location = '?delete_link&lf_linkdate='+ ids +'&token='+ token.value; | ||
414 | } | ||
415 | }); | ||
416 | } | ||
417 | } | ||
365 | }; | 418 | }; |
366 | 419 | ||
367 | function activateFirefoxSocial(node) { | 420 | function activateFirefoxSocial(node) { |
@@ -397,7 +450,7 @@ function activateFirefoxSocial(node) { | |||
397 | */ | 450 | */ |
398 | function hideTimezoneCities(cities, currentContinent, reset = false) { | 451 | function hideTimezoneCities(cities, currentContinent, reset = false) { |
399 | var first = true; | 452 | var first = true; |
400 | [].forEach.call(cities, function(option) { | 453 | [].forEach.call(cities, function (option) { |
401 | if (option.getAttribute('data-continent') != currentContinent) { | 454 | if (option.getAttribute('data-continent') != currentContinent) { |
402 | option.className = 'hidden'; | 455 | option.className = 'hidden'; |
403 | } else { | 456 | } else { |
@@ -409,3 +462,19 @@ function hideTimezoneCities(cities, currentContinent, reset = false) { | |||
409 | } | 462 | } |
410 | }); | 463 | }); |
411 | } | 464 | } |
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 | */ | ||
473 | function testEs6Compatibility() | ||
474 | { | ||
475 | "use strict"; | ||
476 | |||
477 | try { eval("var foo = (x)=>x+1"); } | ||
478 | catch (e) { return false; } | ||
479 | return true; | ||
480 | } | ||