aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-07-27 15:33:18 +0300
committerGravatar Vitaly Takmazov2016-07-28 01:20:26 +0300
commitca59e1808d2015afe71198fce4db6676eede7c1f (patch)
treeda23a6e802d37a75b5005ac35da6061629c2b07e /juick-www/src
parent2b39fae3478e2063de436be36b5cd2169f409dd6 (diff)
Rebase shit-less branch
Diffstat (limited to 'juick-www/src')
-rw-r--r--juick-www/src/main/static/scripts.js36
1 files changed, 26 insertions, 10 deletions
diff --git a/juick-www/src/main/static/scripts.js b/juick-www/src/main/static/scripts.js
index 2d50cc92..a7052cfa 100644
--- a/juick-www/src/main/static/scripts.js
+++ b/juick-www/src/main/static/scripts.js
@@ -363,13 +363,14 @@ function attachMessagePhoto(div) {
}
function unfoldReply() {
- if ((0 + window.location.hash.substring(1)) > 0) {
- var el = window.location.hash;
- //https://developer.mozilla.org/en/docs/Web/API/Element/matches#Polyfill
- while (el.matches('[type="hidden"]')) {
- el = el.previousSibling();
+ var anchor = window.location.hash.substring(1);
+ if ((0 + anchor) > 0) {
+ var el = document.getElementById(anchor);
+ if (!el) { return }
+ while (el.style.display !== 'block') {
+ el = el.previousElementSibling;
}
- showMoreReplies(el.getAttribute('id'));
+ showMoreReplies(el);
window.location.replace(window.location.hash);
}
}
@@ -469,7 +470,8 @@ function resultMessage(str) {
function likeMessage(e, mid) {
if (confirm('Are you sure?')) {
fetch('//juick.com/like?mid=' + mid, {
- method: 'POST'
+ method: 'POST',
+ credentials: 'same-origin'
})
.then(function (response) {
if (response.ok) {
@@ -488,7 +490,9 @@ function likeMessage(e, mid) {
function setPopular(e, mid, popular) {
fetch('//api.juick.com/messages/set_popular?mid=' + mid
+ '&popular=' + popular
- + '&hash=' + document.getElementById('body').getAttribute('data-hash'))
+ + '&hash=' + document.getElementById('body').getAttribute('data-hash'), {
+ credentials: 'same-origin'
+ })
.then(function () {
e.closest('article').append(resultMessage('OK!'));
});
@@ -497,7 +501,9 @@ 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'))
+ + '&hash=' + document.getElementById('body').getAttribute('data-hash'), {
+ credentials: 'same-origin'
+ })
.then(function () {
e.closest('article').append(resultMessage('OK!'));
});
@@ -534,7 +540,12 @@ ready(function () {
var insertButtons = function (e) {
var textarea = e.target;
textarea.classList.add('narrow');
- textarea.insertAdjacentHTML('afterend', '<div class="attach-photo" onclick="attachCommentPhoto(this)"/>');
+ 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();
@@ -660,6 +671,11 @@ ready(function () {
e.preventDefault();
});
});
+ 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) {