diff options
Diffstat (limited to 'assets/default')
-rw-r--r-- | assets/default/js/base.js | 27 |
1 files changed, 17 insertions, 10 deletions
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 | */ |
28 | function refreshToken() { | 28 | function 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); |