X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=b3f5c8342cf64b4c3bc1e309e5d5a960616774b5;hb=19e49c0a2463b90c3468903672d8ba600da217d2;hp=07c5b3dad3546cf62eea589a74e42be9ccdc902c;hpb=498c363779cd180e803a46f3444bdd397ace7dcf;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 07c5b3d..b3f5c83 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -718,6 +718,7 @@ function ajaxifyPost(postElement) { sone.find(".post#post-" + postId + " .create-reply .sender").hide(); sone.find(".post#post-" + postId + " .create-reply .select-sender").show(); sone.find(".post#post-" + postId + " .create-reply :input[name=sender]").val(getCurrentSoneId()); + updateReplyTimes(replyId); } else { alert(error); } @@ -1193,7 +1194,13 @@ function checkForRemovedReplies(oldNotification, newNotification) { } function getStatus() { - ajaxGet("getStatus.ajax", isViewSonePage() ? {"soneIds": getShownSoneId() } : isKnownSonesPage() ? {"soneIds": getShownSoneIds() } : {}, function(data, textStatus) { + var parameters = isViewSonePage() ? {"soneIds": getShownSoneId() } : isKnownSonesPage() ? {"soneIds": getShownSoneIds() } : {}; + $.extend(parameters, { + "elements": JSON.stringify($(".linked-element.not-loaded").map(function () { + return $(this).attr("title"); + }).toArray()) + }); + ajaxGet("getStatus.ajax", parameters, function(data, textStatus) { if ((data != null) && data.success) { /* process Sone information. */ $.each(data.sones, function(index, value) { @@ -1215,6 +1222,9 @@ function getStatus() { loadNewReply(value.id, value.sone, value.post, value.postSone); }); } + if (data.linkedElements) { + loadLinkedElements(data.linkedElements) + } /* do it again in 5 seconds. */ setTimeout(getStatus, 5000); } else { @@ -1519,6 +1529,41 @@ function loadNewReply(replyId, soneId, postId, postSoneId) { }); } +function loadLinkedElements(links) { + var failedElements = links.filter(function(element) { + return element.failed; + }); + if (failedElements.length > 0) { + failedElements.forEach(function(element) { + getLinkedElements(element.link).each(function() { + $(this).remove() + }); + }); + } + var loadedElements = links.filter(function(element) { + return !element.loading && !element.failed; + }); + if (loadedElements.length > 0) { + ajaxGet("getLinkedElement.ajax", { + "elements": JSON.stringify(loadedElements.map(function(element) { + return element.link; + })) + }, function (data, textStatus) { + if ((data != null) && (data.success)) { + data.linkedElements.forEach(function (linkedElement) { + getLinkedElements(linkedElement.link).each(function() { + $(this).replaceWith(linkedElement.html); + }); + }); + } + }); + } +} + +function getLinkedElements(link) { + return $(".linked-element[title='" + link + "']") +} + /** * Marks the given Sone as known if it is still new. *