aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets
diff options
context:
space:
mode:
Diffstat (limited to 'assets')
-rw-r--r--assets/common/js/thumbnails-update.js8
-rw-r--r--assets/default/js/base.js27
2 files changed, 22 insertions, 13 deletions
diff --git a/assets/common/js/thumbnails-update.js b/assets/common/js/thumbnails-update.js
index 060a730e..35608169 100644
--- a/assets/common/js/thumbnails-update.js
+++ b/assets/common/js/thumbnails-update.js
@@ -10,13 +10,14 @@
10 * It contains a recursive call to retrieve the thumb of the next link when it succeed. 10 * It contains a recursive call to retrieve the thumb of the next link when it succeed.
11 * It also update the progress bar and other visual feedback elements. 11 * It also update the progress bar and other visual feedback elements.
12 * 12 *
13 * @param {string} basePath Shaarli subfolder for XHR requests
13 * @param {array} ids List of LinkID to update 14 * @param {array} ids List of LinkID to update
14 * @param {int} i Current index in ids 15 * @param {int} i Current index in ids
15 * @param {object} elements List of DOM element to avoid retrieving them at each iteration 16 * @param {object} elements List of DOM element to avoid retrieving them at each iteration
16 */ 17 */
17function updateThumb(ids, i, elements) { 18function updateThumb(basePath, ids, i, elements) {
18 const xhr = new XMLHttpRequest(); 19 const xhr = new XMLHttpRequest();
19 xhr.open('POST', './?do=ajax_thumb_update'); 20 xhr.open('POST', `${basePath}/?do=ajax_thumb_update`);
20 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 21 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
21 xhr.responseType = 'json'; 22 xhr.responseType = 'json';
22 xhr.onload = () => { 23 xhr.onload = () => {
@@ -40,6 +41,7 @@ function updateThumb(ids, i, elements) {
40} 41}
41 42
42(() => { 43(() => {
44 const basePath = document.querySelector('input[name="js_base_path"]').value;
43 const ids = document.getElementsByName('ids')[0].value.split(','); 45 const ids = document.getElementsByName('ids')[0].value.split(',');
44 const elements = { 46 const elements = {
45 progressBar: document.querySelector('.progressbar > div'), 47 progressBar: document.querySelector('.progressbar > div'),
@@ -47,5 +49,5 @@ function updateThumb(ids, i, elements) {
47 thumbnail: document.querySelector('.thumbnail-placeholder'), 49 thumbnail: document.querySelector('.thumbnail-placeholder'),
48 title: document.querySelector('.thumbnail-link-title'), 50 title: document.querySelector('.thumbnail-link-title'),
49 }; 51 };
50 updateThumb(ids, 0, elements); 52 updateThumb(basePath, ids, 0, elements);
51})(); 53})();
diff --git a/assets/default/js/base.js b/assets/default/js/base.js
index 8cc7eed5..b428a420 100644
--- a/assets/default/js/base.js
+++ b/assets/default/js/base.js
@@ -25,9 +25,9 @@ function findParent(element, tagName, attributes) {
25/** 25/**
26 * Ajax request to refresh the CSRF token. 26 * Ajax request to refresh the CSRF token.
27 */ 27 */
28function refreshToken() { 28function refreshToken(basePath) {
29 const xhr = new XMLHttpRequest(); 29 const xhr = new XMLHttpRequest();
30 xhr.open('GET', './?do=token'); 30 xhr.open('GET', `${basePath}/?do=token`);
31 xhr.onload = () => { 31 xhr.onload = () => {
32 const token = document.getElementById('token'); 32 const token = document.getElementById('token');
33 token.setAttribute('value', xhr.responseText); 33 token.setAttribute('value', xhr.responseText);
@@ -215,6 +215,8 @@ function init(description) {
215} 215}
216 216
217(() => { 217(() => {
218 const basePath = document.querySelector('input[name="js_base_path"]').value;
219
218 /** 220 /**
219 * Handle responsive menu. 221 * Handle responsive menu.
220 * Source: http://purecss.io/layouts/tucked-menu-vertical/ 222 * Source: http://purecss.io/layouts/tucked-menu-vertical/
@@ -461,7 +463,7 @@ function init(description) {
461 }); 463 });
462 464
463 if (window.confirm(message)) { 465 if (window.confirm(message)) {
464 window.location = `?delete_link&lf_linkdate=${ids.join('+')}&token=${token.value}`; 466 window.location = `${basePath}/?delete_link&lf_linkdate=${ids.join('+')}&token=${token.value}`;
465 } 467 }
466 }); 468 });
467 } 469 }
@@ -483,7 +485,8 @@ function init(description) {
483 }); 485 });
484 486
485 const ids = links.map(item => item.id); 487 const ids = links.map(item => item.id);
486 window.location = `?change_visibility&token=${token.value}&newVisibility=${visibility}&ids=${ids.join('+')}`; 488 window.location =
489 `${basePath}/?change_visibility&token=${token.value}&newVisibility=${visibility}&ids=${ids.join('+')}`;
487 }); 490 });
488 }); 491 });
489 } 492 }
@@ -546,7 +549,7 @@ function init(description) {
546 const refreshedToken = document.getElementById('token').value; 549 const refreshedToken = document.getElementById('token').value;
547 const fromtag = block.getAttribute('data-tag'); 550 const fromtag = block.getAttribute('data-tag');
548 const xhr = new XMLHttpRequest(); 551 const xhr = new XMLHttpRequest();
549 xhr.open('POST', './manage-tags'); 552 xhr.open('POST', `${basePath}/manage-tags`);
550 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 553 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
551 xhr.onload = () => { 554 xhr.onload = () => {
552 if (xhr.status !== 200) { 555 if (xhr.status !== 200) {
@@ -558,8 +561,12 @@ function init(description) {
558 input.setAttribute('value', totag); 561 input.setAttribute('value', totag);
559 findParent(input, 'div', { class: 'rename-tag-form' }).style.display = 'none'; 562 findParent(input, 'div', { class: 'rename-tag-form' }).style.display = 'none';
560 block.querySelector('a.tag-link').innerHTML = htmlEntities(totag); 563 block.querySelector('a.tag-link').innerHTML = htmlEntities(totag);
561 block.querySelector('a.tag-link').setAttribute('href', `./?searchtags=${encodeURIComponent(totag)}`); 564 block
562 block.querySelector('a.rename-tag').setAttribute('href', `./manage-tags?fromtag=${encodeURIComponent(totag)}`); 565 .querySelector('a.tag-link')
566 .setAttribute('href', `${basePath}/?searchtags=${encodeURIComponent(totag)}`);
567 block
568 .querySelector('a.rename-tag')
569 .setAttribute('href', `${basePath}/manage-tags?fromtag=${encodeURIComponent(totag)}`);
563 570
564 // Refresh awesomplete values 571 // Refresh awesomplete values
565 existingTags = existingTags.map(tag => (tag === fromtag ? totag : tag)); 572 existingTags = existingTags.map(tag => (tag === fromtag ? totag : tag));
@@ -567,7 +574,7 @@ function init(description) {
567 } 574 }
568 }; 575 };
569 xhr.send(`renametag=1&fromtag=${encodeURIComponent(fromtag)}&totag=${encodeURIComponent(totag)}&token=${refreshedToken}`); 576 xhr.send(`renametag=1&fromtag=${encodeURIComponent(fromtag)}&totag=${encodeURIComponent(totag)}&token=${refreshedToken}`);
570 refreshToken(); 577 refreshToken(basePath);
571 }); 578 });
572 }); 579 });
573 580
@@ -593,13 +600,13 @@ function init(description) {
593 600
594 if (confirm(`Are you sure you want to delete the tag "${tag}"?`)) { 601 if (confirm(`Are you sure you want to delete the tag "${tag}"?`)) {
595 const xhr = new XMLHttpRequest(); 602 const xhr = new XMLHttpRequest();
596 xhr.open('POST', './manage-tags'); 603 xhr.open('POST', `${basePath}/manage-tags`);
597 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 604 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
598 xhr.onload = () => { 605 xhr.onload = () => {
599 block.remove(); 606 block.remove();
600 }; 607 };
601 xhr.send(encodeURI(`deletetag=1&fromtag=${tag}&token=${refreshedToken}`)); 608 xhr.send(encodeURI(`deletetag=1&fromtag=${tag}&token=${refreshedToken}`));
602 refreshToken(); 609 refreshToken(basePath);
603 610
604 existingTags = existingTags.filter(tagItem => tagItem !== tag); 611 existingTags = existingTags.filter(tagItem => tagItem !== tag);
605 awesomepletes = updateAwesompleteList('.rename-tag-input', existingTags, awesomepletes); 612 awesomepletes = updateAwesompleteList('.rename-tag-input', existingTags, awesomepletes);