aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/default/js/base.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/default/js/base.js')
-rw-r--r--assets/default/js/base.js29
1 files changed, 18 insertions, 11 deletions
diff --git a/assets/default/js/base.js b/assets/default/js/base.js
index 27938823..be986ae0 100644
--- a/assets/default/js/base.js
+++ b/assets/default/js/base.js
@@ -10,7 +10,7 @@ import Awesomplete from 'awesomplete';
10 * @returns Found element or null. 10 * @returns Found element or null.
11 */ 11 */
12function findParent(element, tagName, attributes) { 12function findParent(element, tagName, attributes) {
13 const parentMatch = key => attributes[key] !== '' && element.getAttribute(key).indexOf(attributes[key]) !== -1; 13 const parentMatch = (key) => attributes[key] !== '' && element.getAttribute(key).indexOf(attributes[key]) !== -1;
14 while (element) { 14 while (element) {
15 if (element.tagName.toLowerCase() === tagName) { 15 if (element.tagName.toLowerCase() === tagName) {
16 if (Object.keys(attributes).find(parentMatch)) { 16 if (Object.keys(attributes).find(parentMatch)) {
@@ -101,7 +101,7 @@ function updateAwesompleteList(selector, tags, instances) {
101 * @see http://stackoverflow.com/questions/18749591/encode-html-entities-in-javascript 101 * @see http://stackoverflow.com/questions/18749591/encode-html-entities-in-javascript
102 */ 102 */
103function htmlEntities(str) { 103function htmlEntities(str) {
104 return str.replace(/[\u00A0-\u9999<>&]/gim, i => `&#${i.charCodeAt(0)};`); 104 return str.replace(/[\u00A0-\u9999<>&]/gim, (i) => `&#${i.charCodeAt(0)};`);
105} 105}
106 106
107/** 107/**
@@ -194,8 +194,8 @@ function removeClass(element, classname) {
194function init(description) { 194function init(description) {
195 function resize() { 195 function resize() {
196 /* Fix jumpy resizing: https://stackoverflow.com/a/18262927/1484919 */ 196 /* Fix jumpy resizing: https://stackoverflow.com/a/18262927/1484919 */
197 const scrollTop = window.pageYOffset || 197 const scrollTop = window.pageYOffset
198 (document.documentElement || document.body.parentNode || document.body).scrollTop; 198 || (document.documentElement || document.body.parentNode || document.body).scrollTop;
199 199
200 description.style.height = 'auto'; 200 description.style.height = 'auto';
201 description.style.height = `${description.scrollHeight + 10}px`; 201 description.style.height = `${description.scrollHeight + 10}px`;
@@ -490,9 +490,10 @@ function init(description) {
490 }); 490 });
491 }); 491 });
492 492
493 const ids = links.map(item => item.id); 493 const ids = links.map((item) => item.id);
494 window.location = 494 window.location = (
495 `${basePath}/admin/shaare/visibility?token=${token.value}&newVisibility=${visibility}&id=${ids.join('+')}`; 495 `${basePath}/admin/shaare/visibility?token=${token.value}&newVisibility=${visibility}&id=${ids.join('+')}`
496 );
496 }); 497 });
497 }); 498 });
498 } 499 }
@@ -554,6 +555,7 @@ function init(description) {
554 } 555 }
555 const refreshedToken = document.getElementById('token').value; 556 const refreshedToken = document.getElementById('token').value;
556 const fromtag = block.getAttribute('data-tag'); 557 const fromtag = block.getAttribute('data-tag');
558 const fromtagUrl = block.getAttribute('data-tag-url');
557 const xhr = new XMLHttpRequest(); 559 const xhr = new XMLHttpRequest();
558 xhr.open('POST', `${basePath}/admin/tags`); 560 xhr.open('POST', `${basePath}/admin/tags`);
559 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 561 xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
@@ -563,6 +565,7 @@ function init(description) {
563 location.reload(); 565 location.reload();
564 } else { 566 } else {
565 block.setAttribute('data-tag', totag); 567 block.setAttribute('data-tag', totag);
568 block.setAttribute('data-tag-url', encodeURIComponent(totag));
566 input.setAttribute('name', totag); 569 input.setAttribute('name', totag);
567 input.setAttribute('value', totag); 570 input.setAttribute('value', totag);
568 findParent(input, 'div', { class: 'rename-tag-form' }).style.display = 'none'; 571 findParent(input, 'div', { class: 'rename-tag-form' }).style.display = 'none';
@@ -571,15 +574,18 @@ function init(description) {
571 .querySelector('a.tag-link') 574 .querySelector('a.tag-link')
572 .setAttribute('href', `${basePath}/?searchtags=${encodeURIComponent(totag)}`); 575 .setAttribute('href', `${basePath}/?searchtags=${encodeURIComponent(totag)}`);
573 block 576 block
577 .querySelector('a.count')
578 .setAttribute('href', `${basePath}/add-tag/${encodeURIComponent(totag)}`);
579 block
574 .querySelector('a.rename-tag') 580 .querySelector('a.rename-tag')
575 .setAttribute('href', `${basePath}/admin/tags?fromtag=${encodeURIComponent(totag)}`); 581 .setAttribute('href', `${basePath}/admin/tags?fromtag=${encodeURIComponent(totag)}`);
576 582
577 // Refresh awesomplete values 583 // Refresh awesomplete values
578 existingTags = existingTags.map(tag => (tag === fromtag ? totag : tag)); 584 existingTags = existingTags.map((tag) => (tag === fromtag ? totag : tag));
579 awesomepletes = updateAwesompleteList('.rename-tag-input', existingTags, awesomepletes); 585 awesomepletes = updateAwesompleteList('.rename-tag-input', existingTags, awesomepletes);
580 } 586 }
581 }; 587 };
582 xhr.send(`renametag=1&fromtag=${encodeURIComponent(fromtag)}&totag=${encodeURIComponent(totag)}&token=${refreshedToken}`); 588 xhr.send(`renametag=1&fromtag=${fromtagUrl}&totag=${encodeURIComponent(totag)}&token=${refreshedToken}`);
583 refreshToken(basePath); 589 refreshToken(basePath);
584 }); 590 });
585 }); 591 });
@@ -602,6 +608,7 @@ function init(description) {
602 event.preventDefault(); 608 event.preventDefault();
603 const block = findParent(event.target, 'div', { class: 'tag-list-item' }); 609 const block = findParent(event.target, 'div', { class: 'tag-list-item' });
604 const tag = block.getAttribute('data-tag'); 610 const tag = block.getAttribute('data-tag');
611 const tagUrl = block.getAttribute('data-tag-url');
605 const refreshedToken = document.getElementById('token').value; 612 const refreshedToken = document.getElementById('token').value;
606 613
607 if (confirm(`Are you sure you want to delete the tag "${tag}"?`)) { 614 if (confirm(`Are you sure you want to delete the tag "${tag}"?`)) {
@@ -611,10 +618,10 @@ function init(description) {
611 xhr.onload = () => { 618 xhr.onload = () => {
612 block.remove(); 619 block.remove();
613 }; 620 };
614 xhr.send(encodeURI(`deletetag=1&fromtag=${tag}&token=${refreshedToken}`)); 621 xhr.send(`deletetag=1&fromtag=${tagUrl}&token=${refreshedToken}`);
615 refreshToken(basePath); 622 refreshToken(basePath);
616 623
617 existingTags = existingTags.filter(tagItem => tagItem !== tag); 624 existingTags = existingTags.filter((tagItem) => tagItem !== tag);
618 awesomepletes = updateAwesompleteList('.rename-tag-input', existingTags, awesomepletes); 625 awesomepletes = updateAwesompleteList('.rename-tag-input', existingTags, awesomepletes);
619 } 626 }
620 }); 627 });