X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=0cc6480b944121cabd86bf281abda8f7b755a091;hb=9d50dcb65cec8d10306fbdb0d73826f33af2afb9;hp=f872daeaa916bcb0151c3d815f0217fb9d55ff18;hpb=bd04c3d0948baacb29153d52bcb9f0a0b8b040dc;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index f872dae..0cc6480 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -8,23 +8,9 @@ function ajaxGet(url, data, successCallback, errorCallback) { successCallback(data, textStatus); } }, "error": function(xmlHttpRequest, textStatus, errorThrown) { - if (typeof errorCallback != "undefined") { - errorCallback(); - } else { - ajaxError(); - } - }}); - })(url, data, successCallback, errorCallback); -} - -function ajaxPost(url, data, successCallback, errorCallback) { - (function(url, data, successCallback, errorCallback) { - $.ajax({"type": "POST", "url": url, "data": data, "dataType": "json", "success": function(data, textStatus, xmlHttpRequest) { - ajaxSuccess(); - if (typeof successCallback != "undefined") { - successCallback(data, textStatus); + if (xmlHttpRequest.status == 403) { + notLoggedIn = true; } - }, "error": function(xmlHttpRequest, textStatus, errorThrown) { if (typeof errorCallback != "undefined") { errorCallback(); } else { @@ -97,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); @@ -880,7 +868,7 @@ function ajaxifyNotification(notification) { notification.find(".text").addClass("hidden"); } notification.find("form.mark-as-read button").click(function() { - ajaxPost("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": $(":input[name=type]", this.form).val(), "id": $(":input[name=id]", this.form).val()}); + ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": $(":input[name=type]", this.form).val(), "id": $(":input[name=id]", this.form).val()}); }); notification.find("a[class^='link-']").each(function() { linkElement = $(this); @@ -993,6 +981,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"); @@ -1219,7 +1211,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; } } @@ -1232,7 +1224,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; @@ -1243,6 +1235,14 @@ function loadNewPost(postId, soneId, recipientId, time) { } }); newPost = $(data.post.html).addClass("hidden"); + if ($(".post-author-local", newPost).text() == "true") { + newPost.removeClass("new"); + (function(newPost) { + setTimeout(function() { + markPostAsKnown(newPost, false); + }, 5000); + })(newPost); + } if (firstOlderPost != null) { newPost.insertBefore(firstOlderPost); } @@ -1276,6 +1276,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 { @@ -1316,15 +1324,15 @@ 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"); - $(".click-to-show", postElement).removeClass("new"); if ((typeof skipRequest == "undefined") || !skipRequest) { ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "post", "id": getPostId(postElement)}); } })(postElement); } + $(".click-to-show", postElement).removeClass("new"); }); markReplyAsKnown($(postElements).find(".reply")); } @@ -1332,7 +1340,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) { @@ -1603,7 +1611,7 @@ var statusRequestQueued = true; */ function ajaxError() { online = false; - toggleOfflineMarker(true); + showOfflineMarker(true); if (!statusRequestQueued) { setTimeout(getStatus, 5000); statusRequestQueued = true; @@ -1615,7 +1623,7 @@ function ajaxError() { */ function ajaxSuccess() { online = true; - toggleOfflineMarker(false); + showOfflineMarker(!online || (initiallyLoggedIn && notLoggedIn)); } /** @@ -1625,7 +1633,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) { @@ -1641,6 +1649,8 @@ function toggleOfflineMarker(visible) { var focus = true; var online = true; +var initiallyLoggedIn = $("#sone #loggedIn").text() == "true"; +var notLoggedIn = !initiallyLoggedIn; $(document).ready(function() { @@ -1726,7 +1736,7 @@ $(document).ready(function() { allReplies = $(this).find(".reply"); if (allReplies.length > 2) { newHidden = false; - for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) { + for (replyIndex = 0; !newHidden && (replyIndex < (allReplies.length - 2)); ++replyIndex) { $(allReplies[replyIndex]).addClass("hidden"); newHidden |= $(allReplies[replyIndex]).hasClass("new"); }