diff options
author | KillyMXI | 2017-06-17 20:46:19 +0300 |
---|---|---|
committer | KillyMXI | 2017-06-17 20:46:19 +0300 |
commit | 894886e808cb8957e83c05921d2452421f1defd4 (patch) | |
tree | 57007ed3c8c02abca6e771e100d5c736b441f162 /juick-www/src/main/static | |
parent | 7df7e7c75d83bf030a436805f80f4669953a4a44 (diff) |
juick-www: incoming reply format and photo
Diffstat (limited to 'juick-www/src/main/static')
-rw-r--r-- | juick-www/src/main/static/scripts.js | 97 |
1 files changed, 35 insertions, 62 deletions
diff --git a/juick-www/src/main/static/scripts.js b/juick-www/src/main/static/scripts.js index e3d2445a..22731671 100644 --- a/juick-www/src/main/static/scripts.js +++ b/juick-www/src/main/static/scripts.js @@ -85,79 +85,52 @@ function isTreeMode() { } function wsIncomingReply(msg) { - var li = document.createElement('li'); + const unsetProto = (url) => url.replace(/^(https?:)?(?=\/\/)/i, ''); + let msgNum = '/' + msg.rid; + if (msg.replyto > 0) { + msgNum += ` в ответ на <a href="#${msg.replyto}">/${msg.replyto}</a>`; + } + let photoDiv = (msg.photo === undefined) ? '' : ` + <div class="msg-media"><a href="//i.juick.com/p/${msg.mid}.${msg.attach}"> + <img src="${unsetProto(msg.photo.small)}"/></a> + </div>`; + let msgContHtml = ` + <div class="msg-cont"> + <div class="msg-header"> + @<a href="/${msg.user.uname}/">${msg.user.uname}</a>: + <div class="msg-avatar"> + <a href="/${msg.user.uname}/"><img src="//i.juick.com/a/${msg.user.uid}.png" alt="${msg.user.uname}"/></a> + </div> + <div class="msg-menu"><a href="#" class="a-thread-links"></a></div> + <div class="msg-ts"> + <a href="/${msg.mid}#${msg.rid}" title="${msg.timestamp}GMT">${msg.timestamp}</a> + </div> + </div> + <div class="msg-txt">${killy.format(msg.body, msg.mid, false)}</div>${photoDiv} + <div class="msg-links">${msgNum} · <a class="msg-reply-link" href="#">Ответить</a></div> + <div class="msg-comment" style="display: none;"></div> + </div>`; + + let li = document.createElement('li'); li.setAttribute('class', 'msg reply-new'); li.setAttribute('id', msg.rid); + li.innerHTML = msgContHtml; li.addEventListener('click', newReply); li.addEventListener('mouseover', newReply); - var msgAvatar = document.createElement('div'); - msgAvatar.setAttribute('class', 'msg-avatar'); - var msgAvatarLink = document.createElement('a'); - msgAvatarLink.setAttribute('href', '/' + msg.user.uname + '/'); - var msgAvatarImg = document.createElement('img'); - msgAvatarImg.setAttribute('src', '//i.juick.com/a/' + msg.user.uid + '.png'); - msgAvatarLink.appendChild(msgAvatarImg); - msgAvatar.appendChild(msgAvatarLink); - - var msgCont = document.createElement('div'); - msgCont.setAttribute('class', 'msg-cont'); - var msgMenu = document.createElement('div'); - msgMenu.setAttribute('class', 'msg-menu'); - msgCont.appendChild(msgMenu); - var msgMenuLink = document.createElement('a'); - msgMenuLink.setAttribute('href', '#'); - msgMenuLink.addEventListener('click', function (e) { + li.querySelector('.msg-menu > a').addEventListener('click', function (e) { showMessageLinksDialog(msg.mid, msg.rid); e.preventDefault(); }); - msgMenu.appendChild(msgMenuLink); - var msgHeader = document.createElement('div'); - msgHeader.setAttribute('class', 'msg-header'); - var msgHeaderLink = document.createElement('a'); - msgHeaderLink.setAttribute('href', '/' + msg.user.uname + '/'); - msgHeaderLink.textContent = '@' + msg.user.uname + ':'; - msgHeader.appendChild(msgHeaderLink); - var msgTimestamp = document.createElement('div'); - msgTimestamp.setAttribute('class', 'msg-ts'); - var msgTimestampLink = document.createElement('a'); - msgTimestampLink.setAttribute('href', '/' + msg.mid + '#' + msg.rid); - msgTimestampLink.setAttribute('title', msg.timestamp + ' GMT'); - msgTimestampLink.textContent = msg.timestamp; - msgTimestamp.appendChild(msgTimestampLink); - var msgTxt = document.createElement('div'); - msgTxt.setAttribute('class', 'msg-txt'); - var msgLinks = document.createElement('div'); - msgLinks.setAttribute('class', 'msg-links'); - var msgNum = '/' + msg.rid; - if (msg.replyto > 0) { - msgNum += ' в ответ на <a href="#' + msg.replyto + '">/' + msg.replyto + '</a>'; - } - msgLinks.innerHTML = msgNum + ' · '; - var msgLinksLink = document.createElement('a'); - msgLinksLink.setAttribute('href', '#'); - msgLinksLink.textContent = 'Ответить'; - msgLinksLink.addEventListener('click', function (e) { + li.querySelector('a.msg-reply-link').addEventListener('click', function (e) { showCommentForm(msg.mid, msg.rid); e.preventDefault(); }); - msgLinks.appendChild(msgLinksLink); - var msgComment = document.createElement('div'); - msgComment.setAttribute('class', 'msg-comment'); - msgComment.style.display = 'none'; - msgHeader.appendChild(msgAvatar); - msgHeader.appendChild(msgMenu); - msgHeader.appendChild(msgTimestamp); - msgCont.appendChild(msgHeader); - msgCont.appendChild(msgTxt); - msgCont.appendChild(msgLinks); - msgCont.appendChild(msgComment); - li.appendChild(msgCont); - - li.querySelector('.msg-txt').textContent = msg.body; + + killy.embedLinksToX(li.querySelector('.msg-cont'), '.msg-links', '.msg-txt a'); if (isTreeMode() && (msg.replyto > 0)) { - var p = document.getElementById(msg.replyto); - var m = parseInt(p.style.marginLeft) + 20; + let p = document.getElementById(msg.replyto); + let m = parseInt(p.style.marginLeft) + 20; while (p.nextElementSibling && (parseInt(p.nextElementSibling.style.marginLeft) >= m)) { p = p.nextElementSibling; } li.style.marginLeft = m + 'px'; p.parentNode.insertBefore(li, p.nextSibling); @@ -748,5 +721,5 @@ ready(function () { window.addEventListener('pagehide', wsShutdown); - killy.embed(); + killy.embedAll(); }); |