X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fresources%2Fstatic%2Fjavascript%2Fsone.js;h=36db543ec605b38933ad557bf5c353ff8695ec3c;hb=6004444a6a2f604b46d1440cd7f0fbe6502245d5;hp=35b53e3c22f07f4dffbc08b846b3db864059dca6;hpb=1c39d47c0f0d91ce8c355cbb0a0ae7f244f16328;p=Sone.git diff --git a/src/main/resources/static/javascript/sone.js b/src/main/resources/static/javascript/sone.js index 35b53e3..36db543 100644 --- a/src/main/resources/static/javascript/sone.js +++ b/src/main/resources/static/javascript/sone.js @@ -537,6 +537,56 @@ function getReply(replyId, callbackFunction) { } /** + * Ajaxifies the given Sone by enhancing all eligible elements with AJAX. + * + * @param soneElement + * The Sone to ajaxify + */ +function ajaxifySone(soneElement) { + /* + * convert all “follow”, “unfollow”, “lock”, and “unlock” links to something + * nicer. + */ + $(".follow", soneElement).submit(function() { + var followElement = this; + $.getJSON("followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() { + $(followElement).addClass("hidden"); + $(followElement).parent().find(".unfollow").removeClass("hidden"); + }); + return false; + }); + $(".unfollow", soneElement).submit(function() { + var unfollowElement = this; + $.getJSON("unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() { + $(unfollowElement).addClass("hidden"); + $(unfollowElement).parent().find(".follow").removeClass("hidden"); + }); + return false; + }); + $(".lock", soneElement).submit(function() { + var lockElement = this; + $.getJSON("lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() { + $(lockElement).addClass("hidden"); + $(lockElement).parent().find(".unlock").removeClass("hidden"); + }); + return false; + }); + $(".unlock", soneElement).submit(function() { + var unlockElement = this; + $.getJSON("unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() { + $(unlockElement).addClass("hidden"); + $(unlockElement).parent().find(".lock").removeClass("hidden"); + }); + return false; + }); + + /* mark Sone as known when clicking it. */ + $(soneElement).click(function() { + markSoneAsKnown(soneElement); + }); +} + +/** * Ajaxifies the given post by enhancing all eligible elements with AJAX. * * @param postElement @@ -692,9 +742,17 @@ function ajaxifyReply(replyElement) { * jQuery object representing the notification. */ function ajaxifyNotification(notification) { - notification.find("form.dismiss").submit(function() { + notification.find("form").submit(function() { return false; }); + notification.find("input[name=returnPage]").val($.url.attr("relative")); + if (notification.find(".short-text").length > 0) { + notification.find(".short-text").removeClass("hidden"); + notification.find(".text").addClass("hidden"); + } + notification.find("form.mark-as-read button").click(function() { + $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": $(":input[name=type]", this.form).val(), "id": $(":input[name=id]", this.form).val()}); + }); notification.find("form.dismiss button").click(function() { $.getJSON("dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) { /* dismiss in case of error, too. */ @@ -718,6 +776,11 @@ function getStatus() { oldNotification = $("#sone #notification-area .notification#" + value.id); notification = ajaxifyNotification(createNotification(value.id, value.text, value.dismissable)).hide(); if (oldNotification.length != 0) { + if ((oldNotification.find(".short-text").length > 0) && (notification.find(".short-text").length > 0)) { + opened = oldNotification.find(".short-text").hasClass("hidden"); + notification.find(".short-text").toggleClass("hidden", opened); + notification.find(".text").toggleClass("hidden", !opened); + } oldNotification.replaceWith(notification.show()); } else { $("#sone #notification-area").append(notification); @@ -931,12 +994,26 @@ function loadNewReply(replyId, soneId, postId, postSoneId) { }); } +/** + * Marks the given Sone as known if it is still new. + * + * @param soneElement + * The Sone to mark as known + */ +function markSoneAsKnown(soneElement) { + if ($(".new", soneElement).length > 0) { + $.getJSON("maskAsKnown.ajax", {"formPassword": getFormPassword(), "type": "sone", "id": getSoneId(soneElement)}, function(data, textStatus) { + $(soneElement).removeClass("new"); + }); + } +} + function markPostAsKnown(postElements) { $(postElements).each(function() { postElement = this; if ($(postElement).hasClass("new")) { (function(postElement) { - $.getJSON("markPostAsKnown.ajax", {"formPassword": getFormPassword(), "post": getPostId(postElement)}, function(data, textStatus) { + $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "post", "id": getPostId(postElement)}, function(data, textStatus) { $(postElement).removeClass("new"); $(".click-to-show", postElement).removeClass("new"); }); @@ -951,7 +1028,7 @@ function markReplyAsKnown(replyElements) { replyElement = this; if ($(replyElement).hasClass("new")) { (function(replyElement) { - $.getJSON("markReplyAsKnown.ajax", {"formPassword": getFormPassword(), "reply": getReplyId(replyElement)}, function(data, textStatus) { + $.getJSON("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "reply", "id": getReplyId(replyElement)}, function(data, textStatus) { $(replyElement).removeClass("new"); }); })(replyElement); @@ -1004,8 +1081,8 @@ function createNotification(id, text, dismissable) { * The ID of the notification */ function showNotificationDetails(notificationId) { - $("#sone .notification#" + notificationId + " .text").show(); - $("#sone .notification#" + notificationId + " .short-text").hide(); + $("#sone .notification#" + notificationId + " .text").removeClass("hidden"); + $("#sone .notification#" + notificationId + " .short-text").addClass("hidden"); } /** @@ -1174,41 +1251,8 @@ $(document).ready(function() { }); } - /* - * convert all “follow”, “unfollow”, “lock”, and “unlock” links to something - * nicer. - */ - $("#sone .follow").submit(function() { - var followElement = this; - $.getJSON("followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() { - $(followElement).addClass("hidden"); - $(followElement).parent().find(".unfollow").removeClass("hidden"); - }); - return false; - }); - $("#sone .unfollow").submit(function() { - var unfollowElement = this; - $.getJSON("unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() { - $(unfollowElement).addClass("hidden"); - $(unfollowElement).parent().find(".follow").removeClass("hidden"); - }); - return false; - }); - $("#sone .lock").submit(function() { - var lockElement = this; - $.getJSON("lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() { - $(lockElement).addClass("hidden"); - $(lockElement).parent().find(".unlock").removeClass("hidden"); - }); - return false; - }); - $("#sone .unlock").submit(function() { - var unlockElement = this; - $.getJSON("unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() { - $(unlockElement).addClass("hidden"); - $(unlockElement).parent().find(".lock").removeClass("hidden"); - }); - return false; + $("#sone .sone").each(function() { + ajaxifySone($(this)); }); /* process all existing notifications, ajaxify dismiss buttons. */