X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=9ecea9030a684f7ce2958f1099942f2ace8331b6;hp=e07a08b982ebd4e30b0b396a72dc9eeaaa085319;hb=dc1846ee73e3005aea42d74977627866f34ffd61;hpb=13871054ecbb38722714d7e0c88c4024103c3f86 diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index e07a08b..9ecea90 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -8,6 +8,9 @@ function ajaxGet(url, data, successCallback, errorCallback) { successCallback(data, textStatus); } }, "error": function(xmlHttpRequest, textStatus, errorThrown) { + if (xmlHttpRequest.status == 403) { + notLoggedIn = true; + } if (typeof errorCallback != "undefined") { errorCallback(); } else { @@ -80,7 +83,9 @@ function addCommentLink(postId, author, element, insertAfterThisElement) { }); })(replyElement); textArea = replyElement.find("input.reply-input").focus().data("textarea"); - textArea.val(textArea.val() + "@sone://" + author + " "); + if (author != getCurrentSoneId()) { + textArea.val(textArea.val() + "@sone://" + author + " "); + } }); return commentElement; })(postId, author); @@ -754,11 +759,43 @@ function ajaxifyPost(postElement) { /* convert “show source” link into javascript function. */ $(postElement).find(".show-source").each(function() { $("a", this).click(function() { + post = getPostElement(this); + rawPostText = $(".post-text.raw-text", post); + rawPostText.toggleClass("hidden"); + if (rawPostText.hasClass("hidden")) { + $(".post-text.short-text", post).removeClass("hidden"); + $(".post-text.text", post).addClass("hidden"); + $(".expand-post-text", post).removeClass("hidden"); + $(".shrink-post-text", post).addClass("hidden"); + } else { + $(".post-text.short-text", post).addClass("hidden"); + $(".post-text.text", post).addClass("hidden"); + $(".expand-post-text", post).addClass("hidden"); + $(".shrink-post-text", post).addClass("hidden"); + } + return false; + }); + }); + + /* convert “show more” link into javascript function. */ + $(postElement).find(".expand-post-text").each(function() { + $(this).click(function() { $(".post-text.text", getPostElement(this)).toggleClass("hidden"); - $(".post-text.raw-text", getPostElement(this)).toggleClass("hidden"); + $(".post-text.short-text", getPostElement(this)).toggleClass("hidden"); + $(".expand-post-text", getPostElement(this)).toggleClass("hidden"); + $(".shrink-post-text", getPostElement(this)).toggleClass("hidden"); return false; }); }); + $(postElement).find(".shrink-post-text").each(function() { + $(this).click(function() { + $(".post-text.text", getPostElement(this)).toggleClass("hidden"); + $(".post-text.short-text", getPostElement(this)).toggleClass("hidden"); + $(".expand-post-text", getPostElement(this)).toggleClass("hidden"); + $(".shrink-post-text", getPostElement(this)).toggleClass("hidden"); + return false; + }) + }); /* add “comment” link. */ addCommentLink(getPostId(postElement), getPostAuthor(postElement), postElement, $(postElement).find(".post-status-line .permalink-author")); @@ -826,8 +863,40 @@ function ajaxifyReply(replyElement) { /* convert “show source” link into javascript function. */ $(replyElement).find(".show-reply-source").each(function() { $("a", this).click(function() { + reply = getReplyElement(this); + rawReplyText = $(".reply-text.raw-text", reply); + rawReplyText.toggleClass("hidden"); + if (rawReplyText.hasClass("hidden")) { + $(".reply-text.short-text", reply).removeClass("hidden"); + $(".reply-text.text", reply).addClass("hidden"); + $(".expand-reply-text", reply).removeClass("hidden"); + $(".shrink-reply-text", reply).addClass("hidden"); + } else { + $(".reply-text.short-text", reply).addClass("hidden"); + $(".reply-text.text", reply).addClass("hidden"); + $(".expand-reply-text", reply).addClass("hidden"); + $(".shrink-reply-text", reply).addClass("hidden"); + } + return false; + }); + }); + + /* convert “show more” link into javascript function. */ + $(replyElement).find(".expand-reply-text").each(function() { + $(this).click(function() { + $(".reply-text.text", getReplyElement(this)).toggleClass("hidden"); + $(".reply-text.short-text", getReplyElement(this)).toggleClass("hidden"); + $(".expand-reply-text", getReplyElement(this)).toggleClass("hidden"); + $(".shrink-reply-text", getReplyElement(this)).toggleClass("hidden"); + return false; + }); + }); + $(replyElement).find(".shrink-reply-text").each(function() { + $(this).click(function() { $(".reply-text.text", getReplyElement(this)).toggleClass("hidden"); - $(".reply-text.raw-text", getReplyElement(this)).toggleClass("hidden"); + $(".reply-text.short-text", getReplyElement(this)).toggleClass("hidden"); + $(".expand-reply-text", getReplyElement(this)).toggleClass("hidden"); + $(".shrink-reply-text", getReplyElement(this)).toggleClass("hidden"); return false; }); }); @@ -863,7 +932,11 @@ function ajaxifyNotification(notification) { notification.find(".text").addClass("hidden"); } notification.find("form.mark-as-read button").click(function() { - ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": $(":input[name=type]", this.form).val(), "id": $(":input[name=id]", this.form).val()}); + allIds = $(":input[name=id]", this.form).val().split(" "); + for (index = 0; index < allIds.length; index += 16) { + ids = allIds.slice(index, index + 16).join(" "); + ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": $(":input[name=type]", this.form).val(), "id": ids}); + } }); notification.find("a[class^='link-']").each(function() { linkElement = $(this); @@ -976,6 +1049,10 @@ function getStatus() { $.each(data.sones, function(index, value) { updateSoneStatus(value.id, value.name, value.status, value.modified, value.locked, value.lastUpdatedUnknown ? null : value.lastUpdated, value.lastUpdatedText); }); + notLoggedIn = !data.loggedIn; + if (!notLoggedIn) { + showOfflineMarker(!online); + } /* search for removed notifications. */ $("#sone #notification-area .notification").each(function() { notificationId = $(this).attr("id"); @@ -1070,8 +1147,10 @@ function loadNotifications(notificationIds) { oldNotification.replaceWith(notification.show()); } else { $("#sone #notification-area").append(notification); - notification.slideDown(); - setActivity(); + if (value.id.substring(0, 5) != "local") { + notification.slideDown(); + setActivity(); + } } }); }); @@ -1202,7 +1281,7 @@ function loadNewPost(postId, soneId, recipientId, time) { } if (!isIndexPage() || (getPage(".pagination-index") > 1)) { if (!isViewPostPage() || (getShownPostId() != postId)) { - if (!isViewSonePage() || ((getShownSoneId() != soneId) && (getShownSoneId() != recipientId))) { + if (!isViewSonePage() || ((getShownSoneId() != soneId) && (getShownSoneId() != recipientId)) || (getPage(".post-navigation") > 1)) { return; } } @@ -1215,7 +1294,7 @@ function loadNewPost(postId, soneId, recipientId, time) { if (hasPost(data.post.id)) { return; } - if ((!isIndexPage() || (getPage(".pagination-index") > 1)) && !(isViewSonePage() && ((getShownSoneId() == data.post.sone) || (getShownSoneId() == data.post.recipient)))) { + if ((!isIndexPage() || (getPage(".pagination-index") > 1)) && !(isViewSonePage() && ((getShownSoneId() == data.post.sone) || (getShownSoneId() == data.post.recipient) || (getPage(".post-navigation") > 1)))) { return; } var firstOlderPost = null; @@ -1226,6 +1305,9 @@ function loadNewPost(postId, soneId, recipientId, time) { } }); newPost = $(data.post.html).addClass("hidden"); + if ($(".post-author-local", newPost).text() == "true") { + newPost.removeClass("new"); + } if (firstOlderPost != null) { newPost.insertBefore(firstOlderPost); } @@ -1259,6 +1341,14 @@ function loadNewReply(replyId, soneId, postId, postSoneId) { } }); newReply = $(data.reply.html).addClass("hidden"); + if ($(".reply-author-local", newReply).text() == "true") { + newReply.removeClass("new"); + (function(newReply) { + setTimeout(function() { + markReplyAsKnown(newReply, false); + }, 5000); + })(newReply); + } if (firstNewerReply != null) { newReply.insertBefore(firstNewerReply); } else { @@ -1299,7 +1389,7 @@ function markSoneAsKnown(soneElement, skipRequest) { function markPostAsKnown(postElements, skipRequest) { $(postElements).each(function() { postElement = this; - if ($(postElement).hasClass("new")) { + if ($(postElement).hasClass("new") || ((typeof skipRequest != "undefined") && !skipRequest)) { (function(postElement) { $(postElement).removeClass("new"); if ((typeof skipRequest == "undefined") || !skipRequest) { @@ -1315,7 +1405,7 @@ function markPostAsKnown(postElements, skipRequest) { function markReplyAsKnown(replyElements, skipRequest) { $(replyElements).each(function() { replyElement = this; - if ($(replyElement).hasClass("new")) { + if ($(replyElement).hasClass("new") || ((typeof skipRequest != "undefined") && !skipRequest)) { (function(replyElement) { $(replyElement).removeClass("new"); if ((typeof skipRequest == "undefined") || !skipRequest) { @@ -1586,7 +1676,7 @@ var statusRequestQueued = true; */ function ajaxError() { online = false; - toggleOfflineMarker(true); + showOfflineMarker(true); if (!statusRequestQueued) { setTimeout(getStatus, 5000); statusRequestQueued = true; @@ -1598,7 +1688,7 @@ function ajaxError() { */ function ajaxSuccess() { online = true; - toggleOfflineMarker(false); + showOfflineMarker(!online || (initiallyLoggedIn && notLoggedIn)); } /** @@ -1608,7 +1698,7 @@ function ajaxSuccess() { * {@code true} to display the offline marker, {@code false} to hide * it */ -function toggleOfflineMarker(visible) { +function showOfflineMarker(visible) { /* jQuery documentation says toggle() works the other way around?! */ $("#sone #offline-marker").toggle(visible); if (visible) { @@ -1624,6 +1714,8 @@ function toggleOfflineMarker(visible) { var focus = true; var online = true; +var initiallyLoggedIn = $("#sone #loggedIn").text() == "true"; +var notLoggedIn = !initiallyLoggedIn; $(document).ready(function() {