X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=accfabca8b86a30d59cad23a98ea9ff7b65feed3;hp=90bd58b9fbae42e3bb3a5026985a8cb106f0cf7a;hb=275ef92e9690ed28eaf97200493b1e4c04719f52;hpb=25d95a78644c18f7b8f5e92e430776c5cd3d8c9d diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 90bd58b..accfabc 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -847,12 +847,14 @@ function ajaxifyPost(postElement) { }); /* mark everything as known on click. */ - $(postElement).click(function(event) { - if ($(event.target).hasClass("click-to-show")) { - return false; - } - markPostAsKnown(this); - }); + (function(postElement) { + $(postElement).click(function(event) { + if ($(event.target).hasClass("click-to-show")) { + return false; + } + markPostAsKnown(postElement, false); + }); + })(postElement); /* hide reply input field. */ $(postElement).find(".create-reply").addClass("hidden"); @@ -870,7 +872,7 @@ function ajaxifyPost(postElement) { }).fadeIn(); }, 1000); }).mouseleave(function() { - if (currentSoneMenuId = getPostId(this)) { + if (currentSoneMenuId == getPostId(this)) { clearTimeout(currentSoneMenuTimeoutHandler); } }); @@ -1009,7 +1011,7 @@ function ajaxifyReply(replyElement) { }).fadeIn(); }, 1000); }).mouseleave(function() { - if (currentSoneMenuId = getPostId(this) + "-" + getReplyId(this)) { + if (currentSoneMenuId == getPostId(this) + "-" + getReplyId(this)) { clearTimeout(currentSoneMenuTimeoutHandler); } }); @@ -1191,7 +1193,7 @@ function checkForRemovedReplies(oldNotification, newNotification) { } function getStatus() { - ajaxGet("getStatus.ajax", isViewSonePage() ? {"soneIds": getShownSoneId() } : {"loadAllSones": isKnownSonesPage()}, function(data, textStatus) { + ajaxGet("getStatus.ajax", isViewSonePage() ? {"soneIds": getShownSoneId() } : isKnownSonesPage() ? {"soneIds": getShownSoneIds() } : {}, function(data, textStatus) { if ((data != null) && data.success) { /* process Sone information. */ $.each(data.sones, function(index, value) { @@ -1204,15 +1206,15 @@ function getStatus() { if (data.notificationHash != getNotificationHash()) { console.log("Old hash: ", getNotificationHash(), ", new hash: ", data.notificationHash); requestNotifications(); + /* process new posts. */ + $.each(data.newPosts, function(index, value) { + loadNewPost(value.id, value.sone, value.recipient, value.time); + }); + /* process new replies. */ + $.each(data.newReplies, function(index, value) { + loadNewReply(value.id, value.sone, value.post, value.postSone); + }); } - /* process new posts. */ - $.each(data.newPosts, function(index, value) { - loadNewPost(value.id, value.sone, value.recipient, value.time); - }); - /* process new replies. */ - $.each(data.newReplies, function(index, value) { - loadNewReply(value.id, value.sone, value.post, value.postSone); - }); /* do it again in 5 seconds. */ setTimeout(getStatus, 5000); } else { @@ -1357,6 +1359,20 @@ function getShownSoneId() { } /** + * Returns the ID of all currently visible Sones. This is mainly used on the + * “Known Sones” page. + * + * @returns The ID of the currently shown Sones + */ +function getShownSoneIds() { + var soneIds = new Array(); + $("#sone #known-sones .sone .id").each(function() { + soneIds.push($(this).text()); + }); + return soneIds.join(","); +} + +/** * Returns whether the current page is a “view post” page. * * @returns {Boolean} true if the current page is a “view post” @@ -1513,7 +1529,7 @@ function loadNewReply(replyId, soneId, postId, postSoneId) { * request */ function markSoneAsKnown(soneElement, skipRequest) { - if ($(soneElement).is(".new")) { + if ($(soneElement).hasClass("new")) { $(soneElement).removeClass("new"); if ((typeof skipRequest == "undefined") || !skipRequest) { ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "sone", "id": getSoneId(soneElement)}); @@ -1536,7 +1552,7 @@ function markPostAsKnown(postElements, skipRequest) { } $(".click-to-show", postElement).removeClass("new"); }); - markReplyAsKnown($(postElements).find(".reply")); + markReplyAsKnown($(postElements).find(".reply"), true); } function markReplyAsKnown(replyElements, skipRequest) { @@ -1863,6 +1879,14 @@ var currentSoneMenuTimeoutHandler; $(document).ready(function() { + /* rip out the status update textarea. */ + $("#sone .rip-out").each(function() { + var oldElement = $(this); + newElement = $(""); + newElement.attr("class", oldElement.attr("class")).attr("name", oldElement.attr("name")); + oldElement.before(newElement).remove(); + }); + /* this initializes the status update input field. */ getTranslation("WebInterface.DefaultText.StatusUpdate", function(defaultText) { registerInputTextareaSwap("#sone #update-status .status-input", defaultText, "text", false, false); @@ -1947,7 +1971,7 @@ $(document).ready(function() { allReplies = $(this).find(".reply"); if (allReplies.length > 2) { newHidden = false; - for (replyIndex = 0; !newHidden && (replyIndex < (allReplies.length - 2)); ++replyIndex) { + for (replyIndex = 0; replyIndex < (allReplies.length - 2); ++replyIndex) { $(allReplies[replyIndex]).addClass("hidden"); newHidden |= $(allReplies[replyIndex]).hasClass("new"); }