aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl/default/js
diff options
context:
space:
mode:
Diffstat (limited to 'tpl/default/js')
-rw-r--r--tpl/default/js/shaarli.js73
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
367function activateFirefoxSocial(node) { 420function activateFirefoxSocial(node) {
@@ -397,7 +450,7 @@ function activateFirefoxSocial(node) {
397 */ 450 */
398function hideTimezoneCities(cities, currentContinent, reset = false) { 451function 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 */
473function testEs6Compatibility()
474{
475 "use strict";
476
477 try { eval("var foo = (x)=>x+1"); }
478 catch (e) { return false; }
479 return true;
480}