From 8706a64c522ecfcd54577b4aac575a5ca4dba124 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 5 Oct 2018 17:07:10 +0300 Subject: getReply fix and VSCode script indent --- juick-server/src/main/assets/scripts.js | 131 ++++++++++++++++---------------- 1 file changed, 67 insertions(+), 64 deletions(-) (limited to 'juick-server/src/main/assets') diff --git a/juick-server/src/main/assets/scripts.js b/juick-server/src/main/assets/scripts.js index 6cc51d82..89c5c45f 100644 --- a/juick-server/src/main/assets/scripts.js +++ b/juick-server/src/main/assets/scripts.js @@ -5,7 +5,7 @@ require('url-search-params-polyfill'); import * as killy from './embed'; if (!('remove' in Element.prototype)) { // Firefox <23 - Element.prototype.remove = function () { + Element.prototype.remove = function() { if (this.parentNode) { this.parentNode.removeChild(this); } @@ -18,7 +18,7 @@ HTMLCollection.prototype.forEach = Array.prototype.forEach; NodeList.prototype.filter = Array.prototype.filter; HTMLCollection.prototype.filter = Array.prototype.filter; -Element.prototype.selectText = function () { +Element.prototype.selectText = function() { let d = document; if (d.body.createTextRange) { let range = d.body.createTextRange(); @@ -38,7 +38,7 @@ function autosize(el) { ? (el.offsetHeight - el.clientHeight) : (el.offsetHeight + parseInt(window.getComputedStyle(el, null).getPropertyValue('border-top-width'))); - let resize = function (el) { + let resize = function(el) { el.style.height = 'auto'; el.style.height = (el.scrollHeight + offset) + 'px'; }; @@ -142,7 +142,7 @@ function initWS() { } ws = new WebSocket(url); - ws.onopen = function () { + ws.onopen = function() { console.log('online'); if (!document.querySelector('#wsthread')) { var d = document.createElement('div'); @@ -152,14 +152,14 @@ function initWS() { pageTitle = document.title; } }; - ws.onclose = function () { + ws.onclose = function() { console.log('offline'); ws = false; - setTimeout(function () { + setTimeout(function() { initWS(); }, 2000); }; - ws.onmessage = function (msg) { + ws.onmessage = function(msg) { if (msg.data == ' ') { ws.send(' '); } else { @@ -190,7 +190,7 @@ function wsSendKeepAlive() { function wsShutdown() { if (ws) { - ws.onclose = function () { }; + ws.onclose = function() { }; ws.close(); } } @@ -230,7 +230,7 @@ function wsIncomingReply(msg) { li.innerHTML = msgContHtml; li.addEventListener('click', newReply); li.addEventListener('mouseover', newReply); - li.querySelector('a.msg-reply-link').addEventListener('click', function (e) { + li.querySelector('a.msg-reply-link').addEventListener('click', function(e) { showCommentForm(msg.mid, msg.rid); e.preventDefault(); }); @@ -395,7 +395,7 @@ function attachCommentPhoto(div) { div.classList.remove('attach-photo-active'); } else { let newInput = attachInput(); - newInput.addEventListener('change', function () { + newInput.addEventListener('change', function() { div.classList.add('attach-photo-active'); }); newInput.click(); @@ -411,7 +411,7 @@ function attachMessagePhoto(div) { inp.style.float = 'left'; inp.style.width = 0; inp.style.height = 0; - inp.addEventListener('change', function () { + inp.addEventListener('change', function() { div.textContent = i18n('postForm.upload') + ' (✓)'; }); f.appendChild(inp); @@ -519,10 +519,10 @@ function checkUsername() { style = document.querySelector('#username').style; fetch('/api/users?uname=' + uname) .then(handleErrors) - .then(function () { + .then(function() { style.background = '#FFCCCC'; }) - .catch(function () { + .catch(function() { style.background = '#CCFFCC'; }); } @@ -563,12 +563,12 @@ function likeMessage(e, mid) { credentials: 'omit' }) .then(handleErrors) - .then(function (response) { + .then(function(response) { if (response.ok) { e.closest('article').appendChild(resultMessage('OK!')); } }) - .catch(function () { + .catch(function() { e.closest('article').appendChild(resultMessage(i18n('error.error'))); }); } @@ -582,7 +582,7 @@ function subscribeMessage(e, mid) { credentials: 'omit' }) .then(handleErrors) - .then(function (response) { + .then(function(response) { if (response.ok) { window.location.reload(true); } else { @@ -604,7 +604,7 @@ function setPopular(e, mid, popular) { credentials: 'same-origin' }) .then(handleErrors) - .then(function () { + .then(function() { e.closest('article').append(resultMessage('OK!')); }); return false; @@ -616,7 +616,7 @@ function setPrivacy(e, mid) { credentials: 'same-origin' }) .then(handleErrors) - .then(function () { + .then(function() { e.closest('article').append(resultMessage('OK!')); }); return false; @@ -667,25 +667,25 @@ function ready(fn) { } } -ready(function () { +ready(function() { document.querySelectorAll('textarea').forEach((ta) => { autosize(ta); }); - var insertPMButtons = function (e) { + var insertPMButtons = function(e) { e.target.classList.add('narrowpm'); e.target.parentNode.insertAdjacentHTML('afterend', ''); e.target.removeEventListener('click', insertPMButtons); e.preventDefault(); }; - document.querySelectorAll('textarea.replypm').forEach(function (e) { + document.querySelectorAll('textarea.replypm').forEach(function(e) { e.addEventListener('click', insertPMButtons); - e.addEventListener('keypress', function (e) { + e.addEventListener('keypress', function(e) { postformListener(e.target, e); }); }); - document.querySelectorAll('#postmsg textarea').forEach(function (e) { - e.addEventListener('keypress', function (e) { + document.querySelectorAll('#postmsg textarea').forEach(function(e) { + e.addEventListener('keypress', function(e) { postformListener(e.target, e); }); }); @@ -697,7 +697,7 @@ ready(function () { document.querySelectorAll('li.msg').forEach(li => { let showReplyFormBtn = li.querySelector('.a-thread-comment'); if (showReplyFormBtn) { - showReplyFormBtn.addEventListener('click', function (e) { + showReplyFormBtn.addEventListener('click', function(e) { showCommentForm(pageMID, li.id); e.preventDefault(); }); @@ -780,8 +780,8 @@ ready(function () { }); }); - document.querySelectorAll('.msg-menu').forEach(function (el) { - el.addEventListener('click', function (e) { + document.querySelectorAll('.msg-menu').forEach(function(el) { + el.addEventListener('click', function(e) { var reply = e.target.closest('li'); var rid = reply ? parseInt(reply.id) : 0; var message = e.target.closest('section'); @@ -790,73 +790,73 @@ ready(function () { e.preventDefault(); }); }); - document.querySelectorAll('.l .a-privacy').forEach(function (e) { - e.addEventListener('click', function (e) { + document.querySelectorAll('.l .a-privacy').forEach(function(e) { + e.addEventListener('click', function(e) { setPrivacy( e.target, e.target.closest('article').getAttribute('data-mid')); e.preventDefault(); }); }); - document.querySelectorAll('.ir a[data-fname], .msg-media a[data-fname]').forEach(function (el) { - el.addEventListener('click', function (e) { + document.querySelectorAll('.ir a[data-fname], .msg-media a[data-fname]').forEach(function(el) { + el.addEventListener('click', function(e) { let fname = e.target.closest('[data-fname]').getAttribute('data-fname'); if (!showPhotoDialog(fname)) { e.preventDefault(); } }); }); - document.querySelectorAll('.social a').forEach(function (e) { - e.addEventListener('click', function (e) { + document.querySelectorAll('.social a').forEach(function(e) { + e.addEventListener('click', function(e) { openSocialWindow(e.target); e.preventDefault(); }); }); var username = document.getElementById('username'); if (username) { - username.addEventListener('blur', function () { + username.addEventListener('blur', function() { checkUsername(); }); } - document.querySelectorAll('.l .a-like').forEach(function (e) { - e.addEventListener('click', function (e) { + document.querySelectorAll('.l .a-like').forEach(function(e) { + e.addEventListener('click', function(e) { likeMessage( e.target, e.target.closest('article').getAttribute('data-mid')); e.preventDefault(); }); }); - document.querySelectorAll('.l .a-sub').forEach(function (e) { - e.addEventListener('click', function (e) { + document.querySelectorAll('.l .a-sub').forEach(function(e) { + e.addEventListener('click', function(e) { subscribeMessage( e.target, document.getElementById('content').getAttribute('data-mid')); e.preventDefault(); }); }); - document.querySelectorAll('.a-login').forEach(function (el) { - el.addEventListener('click', function (e) { + document.querySelectorAll('.a-login').forEach(function(el) { + el.addEventListener('click', function(e) { openDialogLogin(); e.preventDefault(); }); }); var unfoldall = document.getElementById('unfoldall'); if (unfoldall) { - unfoldall.addEventListener('click', function (e) { - document.querySelectorAll('#replies>li').forEach(function (e) { + unfoldall.addEventListener('click', function(e) { + document.querySelectorAll('#replies>li').forEach(function(e) { e.style.display = 'block'; }); - document.querySelectorAll('#replies .msg-comments').forEach(function (e) { + document.querySelectorAll('#replies .msg-comments').forEach(function(e) { e.style.display = 'none'; }); e.preventDefault(); }); } - document.querySelectorAll('article').forEach(function (article) { + document.querySelectorAll('article').forEach(function(article) { if (Array.prototype.some.call( article.querySelectorAll('.msg-tags a'), - function (a) { + function(a) { return a.textContent === 'NSFW'; } )) { @@ -864,22 +864,25 @@ ready(function () { } }); document.querySelectorAll('[data-uri]').forEach(el => { - fetchUserUri(el.getAttribute('data-uri'), user => { - let header = el.closest('.msg-header'); - header.querySelectorAll('.a-username').forEach(a => { - a.setAttribute('href', user.uri); - let img = a.querySelector('img'); - if (img && user.avatar) { - img.setAttribute('src', user.avatar); - img.setAttribute('alt', user.uname); - } - let textNode = a.childNodes[0]; - if (textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue.trim().length > 0) { - let uname = document.createTextNode(user.uname); - a.replaceChild(uname, a.firstChild); - } + let dataUri = el.getAttribute('data-uri'); + if (dataUri) { + fetchUserUri(dataUri, user => { + let header = el.closest('.msg-header'); + header.querySelectorAll('.a-username').forEach(a => { + a.setAttribute('href', user.uri); + let img = a.querySelector('img'); + if (img && user.avatar) { + img.setAttribute('src', user.avatar); + img.setAttribute('alt', user.uname); + } + let textNode = a.childNodes[0]; + if (textNode.nodeType === Node.TEXT_NODE && textNode.nodeValue.trim().length > 0) { + let uname = document.createTextNode(user.uname); + a.replaceChild(uname, a.firstChild); + } + }); }); - }); + } }); initWS(); @@ -900,14 +903,14 @@ ready(function () { wScrollBefore = 0, wScrollDiff = 0, - throttle = function (delay, fn) { + throttle = function(delay, fn) { var last, deferTimer; - return function () { + return function() { var context = this, args = arguments, now = +new Date; if (last && now < last + delay) { clearTimeout(deferTimer); deferTimer = setTimeout( - function () { + function() { last = now; fn.apply(context, args); }, @@ -919,7 +922,7 @@ ready(function () { }; }; - window.addEventListener('scroll', throttle(throttleTimeout, function () { + window.addEventListener('scroll', throttle(throttleTimeout, function() { dHeight = document.body.offsetHeight; wHeight = window.innerHeight; wScrollCurrent = window.pageYOffset; -- cgit v1.2.3