aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/default/js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/default/js')
-rw-r--r--assets/default/js/base.js62
1 files changed, 24 insertions, 38 deletions
diff --git a/assets/default/js/base.js b/assets/default/js/base.js
index 5cf037c2..99e03370 100644
--- a/assets/default/js/base.js
+++ b/assets/default/js/base.js
@@ -98,29 +98,6 @@ function htmlEntities(str) {
98 return str.replace(/[\u00A0-\u9999<>&]/gim, i => `&#${i.charCodeAt(0)};`); 98 return str.replace(/[\u00A0-\u9999<>&]/gim, i => `&#${i.charCodeAt(0)};`);
99} 99}
100 100
101function activateFirefoxSocial(node) {
102 const loc = location.href;
103 const baseURL = loc.substring(0, loc.lastIndexOf('/') + 1);
104
105 const data = {
106 name: document.title,
107 description: document.getElementById('translation-delete-link').innerHTML,
108 author: 'Shaarli',
109 version: '1.0.0',
110
111 iconURL: `${baseURL}/images/favicon.ico`,
112 icon32URL: `${baseURL}/images/favicon.ico`,
113 icon64URL: `${baseURL}/images/favicon.ico`,
114
115 shareURL: `${baseURL}?post=%{url}&title=%{title}&description=%{text}&source=firefoxsocialapi`,
116 homepageURL: baseURL,
117 };
118 node.setAttribute('data-service', JSON.stringify(data));
119
120 const activate = new CustomEvent('ActivateSocialFeature');
121 node.dispatchEvent(activate);
122}
123
124/** 101/**
125 * Add the class 'hidden' to city options not attached to the current selected continent. 102 * Add the class 'hidden' to city options not attached to the current selected continent.
126 * 103 *
@@ -433,16 +410,6 @@ function init(description) {
433 }); 410 });
434 }); 411 });
435 412
436 /**
437 * Firefox Social
438 */
439 const ffButton = document.getElementById('ff-social-button');
440 if (ffButton != null) {
441 ffButton.addEventListener('click', (event) => {
442 activateFirefoxSocial(event.target);
443 });
444 }
445
446 const continent = document.getElementById('continent'); 413 const continent = document.getElementById('continent');
447 const city = document.getElementById('city'); 414 const city = document.getElementById('city');
448 if (continent != null && city != null) { 415 if (continent != null && city != null) {
@@ -455,12 +422,12 @@ function init(description) {
455 /** 422 /**
456 * Bulk actions 423 * Bulk actions
457 */ 424 */
458 const linkCheckboxes = document.querySelectorAll('.delete-checkbox'); 425 const linkCheckboxes = document.querySelectorAll('.link-checkbox');
459 const bar = document.getElementById('actions'); 426 const bar = document.getElementById('actions');
460 [...linkCheckboxes].forEach((checkbox) => { 427 [...linkCheckboxes].forEach((checkbox) => {
461 checkbox.style.display = 'inline-block'; 428 checkbox.style.display = 'inline-block';
462 checkbox.addEventListener('click', () => { 429 checkbox.addEventListener('change', () => {
463 const linkCheckedCheckboxes = document.querySelectorAll('.delete-checkbox:checked'); 430 const linkCheckedCheckboxes = document.querySelectorAll('.link-checkbox:checked');
464 const count = [...linkCheckedCheckboxes].length; 431 const count = [...linkCheckedCheckboxes].length;
465 if (count === 0 && bar.classList.contains('open')) { 432 if (count === 0 && bar.classList.contains('open')) {
466 bar.classList.toggle('open'); 433 bar.classList.toggle('open');
@@ -477,7 +444,7 @@ function init(description) {
477 event.preventDefault(); 444 event.preventDefault();
478 445
479 const links = []; 446 const links = [];
480 const linkCheckedCheckboxes = document.querySelectorAll('.delete-checkbox:checked'); 447 const linkCheckedCheckboxes = document.querySelectorAll('.link-checkbox:checked');
481 [...linkCheckedCheckboxes].forEach((checkbox) => { 448 [...linkCheckedCheckboxes].forEach((checkbox) => {
482 links.push({ 449 links.push({
483 id: checkbox.value, 450 id: checkbox.value,
@@ -500,6 +467,25 @@ function init(description) {
500 } 467 }
501 468
502 /** 469 /**
470 * Select all button
471 */
472 const selectAllButtons = document.querySelectorAll('.select-all-button');
473 [...selectAllButtons].forEach((selectAllButton) => {
474 selectAllButton.addEventListener('click', (e) => {
475 e.preventDefault();
476 const checked = selectAllButton.classList.contains('filter-off');
477 [...selectAllButtons].forEach((selectAllButton2) => {
478 selectAllButton2.classList.toggle('filter-off');
479 selectAllButton2.classList.toggle('filter-on');
480 });
481 [...linkCheckboxes].forEach((linkCheckbox) => {
482 linkCheckbox.checked = checked;
483 linkCheckbox.dispatchEvent(new Event('change'));
484 });
485 });
486 });
487
488 /**
503 * Tag list operations 489 * Tag list operations
504 * 490 *
505 * TODO: support error code in the backend for AJAX requests 491 * TODO: support error code in the backend for AJAX requests
@@ -581,7 +567,7 @@ function init(description) {
581 event.preventDefault(); 567 event.preventDefault();
582 const block = findParent(event.target, 'div', { class: 'tag-list-item' }); 568 const block = findParent(event.target, 'div', { class: 'tag-list-item' });
583 const tag = block.getAttribute('data-tag'); 569 const tag = block.getAttribute('data-tag');
584 const refreshedToken = document.getElementById('token'); 570 const refreshedToken = document.getElementById('token').value;
585 571
586 if (confirm(`Are you sure you want to delete the tag "${tag}"?`)) { 572 if (confirm(`Are you sure you want to delete the tag "${tag}"?`)) {
587 const xhr = new XMLHttpRequest(); 573 const xhr = new XMLHttpRequest();