From ca59e1808d2015afe71198fce4db6676eede7c1f Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 27 Jul 2016 15:33:18 +0300 Subject: Rebase shit-less branch --- .gitignore | 4 ++-- juick-www/src/main/static/scripts.js | 36 +++++++++++++++++++++-------- src/test/java/com/juick/tests/ApiTests.java | 6 +---- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 6539508f..4074462b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,5 @@ deps/* **/build/** .gradle/** **/node_modules/** -juick-www/src/main/webapp/scripts.js -juick-www/src/main/webapp/style.css \ No newline at end of file +juick-www/src/main/webapp/scripts.js* +juick-www/src/main/webapp/style.css* \ No newline at end of file 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', '
'); + 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', ''); 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) { diff --git a/src/test/java/com/juick/tests/ApiTests.java b/src/test/java/com/juick/tests/ApiTests.java index 533b2428..13d13f7a 100644 --- a/src/test/java/com/juick/tests/ApiTests.java +++ b/src/test/java/com/juick/tests/ApiTests.java @@ -185,11 +185,7 @@ public class ApiTests { String allFeed = protocol.getReply(readerUser, "#").getJson().orElse(""); JSONArray allFeedMessages = new JSONArray(allFeed); assertEquals("messages count should match", 0, allFeedMessages.length()); - //assertEquals("number of message events should match", 1, newMessages.size()); - /* TODO: add asserts - protocol.getReply(user, "BL"); - protocol.getReply(user, "@me"); - protocol.getReply(user, "OFF"); */ + assertEquals("tag should be blacklisted", "yo", protocol.getReply(readerUser, "BL *yo").getDescription()); } } -- cgit v1.2.3