aboutsummaryrefslogtreecommitdiff
path: root/src/main/assets
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/assets')
-rw-r--r--src/main/assets/scripts.js54
1 files changed, 30 insertions, 24 deletions
diff --git a/src/main/assets/scripts.js b/src/main/assets/scripts.js
index d5ceb86e..87fdf7a4 100644
--- a/src/main/assets/scripts.js
+++ b/src/main/assets/scripts.js
@@ -9,13 +9,14 @@ import svg4everybody from 'svg4everybody';
/**
* Autosize textarea
+ *
* @param {HTMLTextAreaElement} el textarea element
*/
function autosize(el) {
let offset = el.offsetHeight - el.clientHeight;
el.addEventListener('input', (ev) => {
- const textarea = /** @type HTMLTextAreaElement */ (ev.target);
+ const textarea = /** @type {HTMLTextAreaElement} */ (ev.target);
textarea.style.height = 'auto';
textarea.style.height = (textarea.scrollHeight + offset) + 'px';
});
@@ -23,8 +24,9 @@ function autosize(el) {
/**
* Display an icon from the evil-icons set
+ *
* @param {string} name Icon name from the iconset
- * @returns HTML markup for the selected icon
+ * @returns {string} HTML markup for the selected icon
*/
function evilIcon(name) {
return `<div class="icon icon--${name}"><svg class="icon__cnt"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/sprite.svg#${name}-icon"></use></svg></div>`;
@@ -87,6 +89,7 @@ const translations = {
/**
* Detect window language
+ *
* @returns {string} Detected language
*/
function getLang() {
@@ -223,6 +226,7 @@ function updateRepliesCounter() {
/**
* Submit form on Ctrl+Enter
+ *
* @param {HTMLElement} formEl Target form element
* @param {KeyboardEvent} ev Keyboard event
*/
@@ -230,17 +234,18 @@ function postformListener(formEl, ev) {
if (ev.ctrlKey && (ev.keyCode == 10 || ev.keyCode == 13)) {
let form = formEl.closest('form');
if (!form.onsubmit || form.submit()) {
- /** @type HTMLInputElement */ (form.querySelector('input[type="submit"]')).click();
+ /** @type {HTMLInputElement} */ (form.querySelector('input[type="submit"]')).click();
}
}
}
/**
* Close dialog on Esc
+ *
* @param {KeyboardEvent} ev Keyboard event
*/
function closeDialogListener(ev) {
- ev = ev || /** @type KeyboardEvent */ (window.event);
+ ev = ev || /** @type {KeyboardEvent} */ (window.event);
if (ev.keyCode == 27) {
closeDialog();
}
@@ -273,13 +278,13 @@ function showCommentForm(mid, rid) {
formTarget.remove();
let form = reply.querySelector('form');
- let submitButton = /** @type HTMLInputElement */ (form.querySelector('input[type="submit"]'));
+ let submitButton = /** @type {HTMLInputElement} */ (form.querySelector('input[type="submit"]'));
let attachButton = form.querySelector('.msg-comment .attach-photo');
- attachButton.addEventListener('click', e => attachCommentPhoto(/** @type HTMLDivElement */ (e.target)));
+ attachButton.addEventListener('click', e => attachCommentPhoto(/** @type {HTMLDivElement} */ (e.target)));
- let textarea = /** @type HTMLTextAreaElement */ (form.querySelector('.msg-comment textarea'));
- textarea.addEventListener('keypress', e => postformListener(/** @type HTMLElement */ (e.target), e));
+ let textarea = /** @type {HTMLTextAreaElement} */ (form.querySelector('.msg-comment textarea'));
+ textarea.addEventListener('keypress', e => postformListener(/** @type {HTMLElement} */ (e.target), e));
autosize(textarea);
let validateMessage = () => {
@@ -318,7 +323,7 @@ function showCommentForm(mid, rid) {
e.preventDefault();
});
}
- /** @type HTMLTextAreaElement */ (reply.querySelector('.msg-comment textarea')).focus();
+ /** @type {HTMLTextAreaElement} */ (reply.querySelector('.msg-comment textarea')).focus();
}
function attachInput() {
@@ -332,6 +337,7 @@ function attachInput() {
/**
* "Attach" button
+ *
* @param {HTMLDivElement} div
*/
function attachCommentPhoto(div) {
@@ -395,7 +401,7 @@ function closeDialog() {
function checkUsername() {
var uname = document.querySelector('#username').textContent,
- style = /** @type HTMLElement */ (document.querySelector('#username')).style;
+ style = /** @type {HTMLElement} */ (document.querySelector('#username')).style;
fetch('/api/users?uname=' + uname)
.then(handleErrors)
.then(function() {
@@ -554,15 +560,15 @@ ready(() => {
e.target.removeEventListener('click', insertPMButtons);
e.preventDefault();
};
- /** @type HTMLTextAreaElement[] */ (Array.from(document.querySelectorAll('textarea.replypm'))).forEach(function(e) {
+ /** @type {HTMLTextAreaElement[]} */ (Array.from(document.querySelectorAll('textarea.replypm'))).forEach(function(e) {
e.addEventListener('click', insertPMButtons);
e.addEventListener('keypress', function(e) {
- postformListener(/** @type HTMLElement */ (e.target), e);
+ postformListener(/** @type {HTMLElement} */ (e.target), e);
});
});
- /** @type HTMLTextAreaElement[] */ (Array.from(document.querySelectorAll('#postmsg textarea'))).forEach(function(e) {
+ /** @type {HTMLTextAreaElement[]} */ (Array.from(document.querySelectorAll('#postmsg textarea'))).forEach(function(e) {
e.addEventListener('keypress', function(e) {
- postformListener(/** @type HTMLElement */ (e.target), e);
+ postformListener(/** @type {HTMLElement} */ (e.target), e);
});
});
@@ -581,10 +587,10 @@ ready(() => {
});
let opMessage = document.querySelector('.msgthread');
if (opMessage) {
- let replyTextarea = /** @type HTMLTextAreaElement */ (opMessage.querySelector('textarea.reply'));
+ let replyTextarea = /** @type {HTMLTextAreaElement} */ (opMessage.querySelector('textarea.reply'));
if (replyTextarea) {
replyTextarea.addEventListener('focus', e => showCommentForm(pageMID, 0));
- replyTextarea.addEventListener('keypress', e => postformListener(/** @type HTMLElement */ (e.target), e));
+ replyTextarea.addEventListener('keypress', e => postformListener(/** @type {HTMLElement} */ (e.target), e));
if (!window.location.hash) {
replyTextarea.focus();
}
@@ -593,7 +599,7 @@ ready(() => {
}
}
- var postmsg = /** @type HTMLFormElement */(document.getElementById('postmsg'));
+ var postmsg = /** @type {HTMLFormElement} */(document.getElementById('postmsg'));
if (postmsg) {
Array.from(document.querySelectorAll('a')).filter(t => t.href.indexOf('?') >= 0).forEach(t => {
t.addEventListener('click', e => {
@@ -629,7 +635,7 @@ ready(() => {
e.preventDefault();
});
}
- /** @type HTMLFormElement[] */ (Array.from(document.querySelectorAll('.pmmsg'))).forEach(pmmsg => {
+ /** @type {HTMLFormElement[]} */ (Array.from(document.querySelectorAll('.pmmsg'))).forEach(pmmsg => {
pmmsg.addEventListener('submit', e => {
let formData = new FormData(pmmsg);
fetch('/api/pm' + '?hash=' + document.getElementById('body').getAttribute('data-hash'), {
@@ -660,13 +666,13 @@ ready(() => {
e.addEventListener('click', function(e) {
setPrivacy(
e.target,
- /** @type HTMLElement */(e.target).closest('article').getAttribute('data-mid'));
+ /** @type {HTMLElement} */(e.target).closest('article').getAttribute('data-mid'));
e.preventDefault();
});
});
Array.from(document.querySelectorAll('.ir a[data-fname], .msg-media a[data-fname]')).forEach(function(el) {
el.addEventListener('click', function(e) {
- let fname = /** @type HTMLElement */ (e.target).closest('[data-fname]').getAttribute('data-fname');
+ let fname = /** @type {HTMLElement} */ (e.target).closest('[data-fname]').getAttribute('data-fname');
if (!showPhotoDialog(fname)) {
e.preventDefault();
}
@@ -684,7 +690,7 @@ ready(() => {
e.addEventListener('click', function(e) {
likeMessage(
e.target,
- /** @type HTMLElement */(e.target).closest('article').getAttribute('data-mid'));
+ /** @type {HTMLElement} */(e.target).closest('article').getAttribute('data-mid'));
e.preventDefault();
});
});
@@ -705,10 +711,10 @@ ready(() => {
var unfoldall = document.getElementById('unfoldall');
if (unfoldall) {
unfoldall.addEventListener('click', function(e) {
- /** @type HTMLElement[] */ (Array.from(document.querySelectorAll('#replies>li'))).forEach(function(e) {
+ /** @type {HTMLElement[]} */ (Array.from(document.querySelectorAll('#replies>li'))).forEach(function(e) {
e.style.display = 'block';
});
- /** @type HTMLElement[] */ (Array.from(document.querySelectorAll('#replies .msg-comments'))).forEach(function(e) {
+ /** @type {HTMLElement[]} */ (Array.from(document.querySelectorAll('#replies .msg-comments'))).forEach(function(e) {
e.style.display = 'none';
});
e.preventDefault();
@@ -758,7 +764,7 @@ ready(() => {
}
});
let location = window.location.href;
- /** @type HTMLLinkElement[] */ (Array.from(document.querySelectorAll('#header_wrapper a'))).forEach(el => {
+ /** @type {HTMLLinkElement[]} */ (Array.from(document.querySelectorAll('#header_wrapper a'))).forEach(el => {
if (el.href === location) {
el.classList.add('active');
el.setAttribute('disabled', 'disabled');