aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/static/scripts.js
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www/src/main/static/scripts.js')
-rw-r--r--juick-www/src/main/static/scripts.js235
1 files changed, 124 insertions, 111 deletions
diff --git a/juick-www/src/main/static/scripts.js b/juick-www/src/main/static/scripts.js
index d368cacd..8432c18a 100644
--- a/juick-www/src/main/static/scripts.js
+++ b/juick-www/src/main/static/scripts.js
@@ -12,19 +12,24 @@ if (!('remove' in Element.prototype)) { // Firefox <23
NodeList.prototype.forEach = Array.prototype.forEach;
HTMLCollection.prototype.forEach = Array.prototype.forEach;
-
+
+function isReadonly() {
+ return document.getElementById('body').getAttribute('data-readonly');
+}
+
var ws,
pageTitle;
function initWS() {
+ if (isReadonly()) { return }
var content = document.getElementById('content');
if (!content) { return }
var pageMID = content.getAttribute('data-mid');
if (!pageMID) { return }
var url = (window.location.protocol === 'https:' ? 'wss' : 'ws') + ':'
- + (typeof juickDebug !== 'undefined' ?
- '//ws.juick.com/_replies' : ('//ws.juick.com/' + pageMID)),
+ + (typeof juickDebug !== 'undefined' ?
+ '//ws.juick.com/_replies' : ('//ws.juick.com/' + pageMID)),
hash = document.getElementById('body').getAttribute('data-hash');
if (hash) {
@@ -145,12 +150,12 @@ function wsIncomingReply(msg) {
msgComment.style.display = 'none';
msgHeader.appendChild(msgAvatar);
msgHeader.appendChild(msgMenu);
- msgHeader.appendChild(msgTimestamp);
+ msgHeader.appendChild(msgTimestamp);
msgCont.appendChild(msgHeader);
msgCont.appendChild(msgTxt);
msgCont.appendChild(msgLinks);
msgCont.appendChild(msgComment);
- li.appendChild(msgCont);
+ li.appendChild(msgCont);
li.querySelector('.msg-txt').textContent = msg.body;
@@ -400,15 +405,15 @@ function showMessageLinksDialog(mid, rid) {
}
var hlinkenc = encodeURIComponent(hlink),
html = '<div class="dialogshare">Ссылка на сообщение:'
- + '<div onclick="this.selectText()" class="dialogl">' + hlink + '</div>'
- + 'Номер сообщения:'
- + '<div onclick="this.selectText()" class="dialogl">' + mlink + '</div>'
- + 'Поделиться:<ul>'
- + '<li><a href="https://www.facebook.com/sharer/sharer.php?u=' + hlinkenc + '" onclick="return openSocialWindow(this)"></a></li>'
- + '<li><a href="https://twitter.com/intent/tweet?url=' + hlinkenc + '" onclick="return openSocialWindow(this)" style="background-position: -32px 0;"></a></li>'
- + '<li><a href="https://vk.com/share.php?url=' + hlinkenc + '" onclick="return openSocialWindow(this)" style="background-position: -64px 0;"></a></li>'
- + '<li><a href="https://plus.google.com/share?url=' + hlinkenc + '" onclick="return openSocialWindow(this)" style="background-position: -96px 0;"></a></li>'
- + '</ul></div>';
+ + '<div onclick="this.selectText()" class="dialogl">' + hlink + '</div>'
+ + 'Номер сообщения:'
+ + '<div onclick="this.selectText()" class="dialogl">' + mlink + '</div>'
+ + 'Поделиться:<ul>'
+ + '<li><a href="https://www.facebook.com/sharer/sharer.php?u=' + hlinkenc + '" onclick="return openSocialWindow(this)"></a></li>'
+ + '<li><a href="https://twitter.com/intent/tweet?url=' + hlinkenc + '" onclick="return openSocialWindow(this)" style="background-position: -32px 0;"></a></li>'
+ + '<li><a href="https://vk.com/share.php?url=' + hlinkenc + '" onclick="return openSocialWindow(this)" style="background-position: -64px 0;"></a></li>'
+ + '<li><a href="https://plus.google.com/share?url=' + hlinkenc + '" onclick="return openSocialWindow(this)" style="background-position: -96px 0;"></a></li>'
+ + '</ul></div>';
openDialog(html);
}
@@ -507,8 +512,8 @@ function setPopular(e, mid, popular) {
fetch('//api.juick.com/messages/set_popular?mid=' + mid
+ '&popular=' + popular
+ '&hash=' + document.getElementById('body').getAttribute('data-hash'), {
- credentials: 'same-origin'
- })
+ credentials: 'same-origin'
+ })
.then(function () {
e.closest('article').append(resultMessage('OK!'));
});
@@ -518,8 +523,8 @@ function setPopular(e, mid, popular) {
function setPrivacy(e, mid) {
fetch('//api.juick.com/messages/set_privacy?mid=' + mid
+ '&hash=' + document.getElementById('body').getAttribute('data-hash'), {
- credentials: 'same-origin'
- })
+ credentials: 'same-origin'
+ })
.then(function () {
e.closest('article').append(resultMessage('OK!'));
});
@@ -551,50 +556,52 @@ function ready(fn) {
}
ready(function () {
- autosize(document.querySelectorAll('textarea'));
-
- var insertButtons = function (e) {
- var textarea = e.target;
- textarea.classList.add('narrow');
- var att = document.createElement('div');
- att.classList.add('attach-photo');
- att.addEventListener('click', function(e) {
- attachCommentPhoto(e.target);
- });
- textarea.parentNode.insertBefore(att, textarea.nextSibling);
- textarea.parentNode.insertAdjacentHTML('afterend', '<input type="submit" value="OK"/>');
- textarea.removeEventListener('click', insertButtons);
- e.preventDefault();
- };
- document.querySelectorAll('textarea.reply').forEach(function(e) {
- e.addEventListener('click', insertButtons);
- e.addEventListener('keypress', function(e) {
- postformListener(e.target, e);
+ if (!isReadonly()) {
+ autosize(document.querySelectorAll('textarea'));
+
+ var insertButtons = function (e) {
+ var textarea = e.target;
+ textarea.classList.add('narrow');
+ var att = document.createElement('div');
+ att.classList.add('attach-photo');
+ att.addEventListener('click', function (e) {
+ attachCommentPhoto(e.target);
+ });
+ textarea.parentNode.insertBefore(att, textarea.nextSibling);
+ textarea.parentNode.insertAdjacentHTML('afterend', '<input type="submit" value="OK"/>');
+ textarea.removeEventListener('click', insertButtons);
+ e.preventDefault();
+ };
+ document.querySelectorAll('textarea.reply').forEach(function (e) {
+ e.addEventListener('click', insertButtons);
+ e.addEventListener('keypress', function (e) {
+ postformListener(e.target, e);
+ });
});
- });
- var insertPMButtons = function (e) {
- e.target.classList.add('narrowpm');
- e.target.parentNode.insertAdjacentHTML('afterend', '<input type="submit" value="OK"/>');
- e.target.removeEventListener('click', insertPMButtons);
- e.preventDefault();
- };
- document.querySelectorAll('textarea.replypm').forEach(function(e) {
- e.addEventListener('click', insertPMButtons);
- });
+ var insertPMButtons = function (e) {
+ e.target.classList.add('narrowpm');
+ e.target.parentNode.insertAdjacentHTML('afterend', '<input type="submit" value="OK"/>');
+ e.target.removeEventListener('click', insertPMButtons);
+ e.preventDefault();
+ };
+ document.querySelectorAll('textarea.replypm').forEach(function (e) {
+ e.addEventListener('click', insertPMButtons);
+ });
+ }
var content = document.getElementById('content');
if (content) {
var pageMID = content.getAttribute('data-mid');
if (pageMID > 0) {
- document.querySelectorAll('.msg-comments').forEach(function(e) {
+ document.querySelectorAll('.msg-comments').forEach(function (e) {
e.addEventListener('click', function (e) {
var rid = e.target.closest('li').id;
showMoreReplies(e.target, rid);
e.preventDefault();
});
});
- document.querySelectorAll('.a-thread-comment').forEach(function(e) {
+ document.querySelectorAll('.a-thread-comment').forEach(function (e) {
e.addEventListener('click', function (e) {
var rid = e.target.closest('li').id;
showCommentForm(pageMID, rid);
@@ -604,23 +611,25 @@ ready(function () {
}
}
- document.querySelectorAll('.msg-menu a').forEach(function(el) {
- el.addEventListener('click', function(e) {
+ document.querySelectorAll('.msg-menu a').forEach(function (el) {
+ el.addEventListener('click', function (e) {
showMessageLinksDialog(
e.target.closest('section').getAttribute('data-mid'),
parseInt(e.target.closest('li').id)); // rid
e.preventDefault();
});
});
- document.querySelectorAll('.l .a-comment').forEach(function(e) {
- e.addEventListener('click', function (e) {
- showCommentFooter(
- e.target,
- e.target.closest('article').getAttribute('data-mid'));
- e.preventDefault();
+ if (!isReadonly()) {
+ document.querySelectorAll('.l .a-comment').forEach(function (e) {
+ e.addEventListener('click', function (e) {
+ showCommentFooter(
+ e.target,
+ e.target.closest('article').getAttribute('data-mid'));
+ e.preventDefault();
+ });
});
- });
- document.querySelectorAll('.l .a-privacy').forEach(function(e) {
+ }
+ document.querySelectorAll('.l .a-privacy').forEach(function (e) {
e.addEventListener('click', function (e) {
setPrivacy(
e.target,
@@ -628,34 +637,36 @@ ready(function () {
e.preventDefault();
});
});
- document.querySelectorAll('.l .a-popular-plus').forEach(function(e) {
- e.addEventListener('click', function (e) {
- setPopular(
- e.target,
- e.target.closest('article').getAttribute('data-mid'),
- 2);
- e.preventDefault();
+ if (!isReadonly()) {
+ document.querySelectorAll('.l .a-popular-plus').forEach(function (e) {
+ e.addEventListener('click', function (e) {
+ setPopular(
+ e.target,
+ e.target.closest('article').getAttribute('data-mid'),
+ 2);
+ e.preventDefault();
+ });
});
- });
- document.querySelectorAll('.l .a-popular-minus').forEach(function(e) {
- e.addEventListener('click', function (e) {
- setPopular(
- e.target,
- e.target.closest('article').getAttribute('data-mid'),
- -1);
- e.preventDefault();
+ document.querySelectorAll('.l .a-popular-minus').forEach(function (e) {
+ e.addEventListener('click', function (e) {
+ setPopular(
+ e.target,
+ e.target.closest('article').getAttribute('data-mid'),
+ -1);
+ e.preventDefault();
+ });
});
- });
- document.querySelectorAll('.l .a-popular-delete').forEach(function(e) {
- e.addEventListener('click', function (e) {
- setPopular(
- e.target,
- e.target.closest('article').getAttribute('data-mid'),
- -2);
- e.preventDefault();
+ document.querySelectorAll('.l .a-popular-delete').forEach(function (e) {
+ e.addEventListener('click', function (e) {
+ setPopular(
+ e.target,
+ e.target.closest('article').getAttribute('data-mid'),
+ -2);
+ e.preventDefault();
+ });
});
- });
- document.querySelectorAll('.ir a').forEach(function(e) {
+ }
+ document.querySelectorAll('.ir a').forEach(function (e) {
e.addEventListener('click', function (e) {
var fname = e.target.closest('[data-fname]').getAttribute('data-fname');
if (!showPhotoDialog(fname)) {
@@ -663,7 +674,7 @@ ready(function () {
}
});
});
- document.querySelectorAll('.social a').forEach(function(e) {
+ document.querySelectorAll('.social a').forEach(function (e) {
e.addEventListener('click', function (e) {
openSocialWindow(e.target);
e.preventDefault();
@@ -676,7 +687,7 @@ ready(function () {
});
}
- document.querySelectorAll('.l .a-like').forEach(function(e) {
+ document.querySelectorAll('.l .a-like').forEach(function (e) {
e.addEventListener('click', function (e) {
likeMessage(
e.target,
@@ -684,46 +695,48 @@ ready(function () {
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();
});
});
- document.querySelectorAll('.attach-photo').forEach(function(el) {
- el.addEventListener('click', function(e) {
+ document.querySelectorAll('.attach-photo').forEach(function (el) {
+ el.addEventListener('click', function (e) {
attachCommentPhoto(e.target);
});
});
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();
});
}
- var newMessageBlock = document.getElementById('newmessage');
- if (newMessageBlock) {
- var form = newMessageBlock.parentNode;
- form.addEventListener('submit', newMessage);
- newMessageBlock.querySelector('textarea').addEventListener('click', function(e) {
- var parent = e.target.parentNode;
- parent.querySelector('div').style.display = 'block';
- e.target.style.minHeight = '70px';
- e.target.addEventListener('keypress', function(e) {
- postformListener(e.target, e);
+ if (!isReadonly()) {
+ var newMessageBlock = document.getElementById('newmessage');
+ if (newMessageBlock) {
+ var form = newMessageBlock.parentNode;
+ form.addEventListener('submit', newMessage);
+ newMessageBlock.querySelector('textarea').addEventListener('click', function (e) {
+ var parent = e.target.parentNode;
+ parent.querySelector('div').style.display = 'block';
+ e.target.style.minHeight = '70px';
+ e.target.addEventListener('keypress', function (e) {
+ postformListener(e.target, e);
+ });
});
- });
- newMessageBlock.querySelector('a').addEventListener('click', function(e) {
- attachMessagePhoto(e.target);
- });
- }
- document.querySelectorAll('article').forEach(function(article) {
+ newMessageBlock.querySelector('a').addEventListener('click', function (e) {
+ attachMessagePhoto(e.target);
+ });
+ }
+ }
+ document.querySelectorAll('article').forEach(function (article) {
if (Array.prototype.some.call(
article.querySelectorAll('.u a'),
function (a) {
@@ -733,10 +746,10 @@ ready(function () {
var img = article.querySelector('.ir img');
if (img) {
img.style.opacity = 0.05;
- img.addEventListener('mouseover', function(e) {
+ img.addEventListener('mouseover', function (e) {
e.target.style.opacity = 1;
});
- img.addEventListener('mouseout', function(e) {
+ img.addEventListener('mouseout', function (e) {
e.target.style.opacity = 0.05;
});
}