+ /* convert trust control buttons to javascript functions. */
+ $(replyElement).find(".reply-trust").submit(function() {
+ trustSone(getReplyAuthor(this));
+ return false;
+ });
+ $(replyElement).find(".reply-distrust").submit(function() {
+ distrustSone(getReplyAuthor(this));
+ return false;
+ });
+ $(replyElement).find(".reply-untrust").submit(function() {
+ untrustSone(getReplyAuthor(this));
+ return false;
+ });
+
+ /* show Sone menu when hovering over the avatar. */
+ $(replyElement).find(".reply-avatar").mouseover(function() {
+ if (typeof currentSoneMenuTimeoutHandler != undefined) {
+ clearTimeout(currentSoneMenuTimeoutHandler);
+ }
+ currentSoneMenuId = getPostId(this) + "-" + getReplyId(this);
+ currentSoneMenuTimeoutHandler = setTimeout(function() {
+ $(".sone-menu:visible").fadeOut();
+ $(".sone-reply-menu", replyElement).mouseleave(function() {
+ $(this).fadeOut();
+ }).fadeIn();
+ }, 1000);
+ }).mouseleave(function() {
+ if (currentSoneMenuId == getPostId(this) + "-" + getReplyId(this)) {
+ clearTimeout(currentSoneMenuTimeoutHandler);
+ }
+ });
+ (function(replyElement) {
+ var soneId = $(".sone-menu-id", replyElement).text();
+ $(".sone-menu .follow", replyElement).click(function() {
+ var followElement = this;
+ ajaxGet("followSone.ajax", { "sone": soneId, "formPassword": getFormPassword() }, function() {
+ $(followElement).addClass("hidden");
+ $(followElement).parent().find(".unfollow").removeClass("hidden");
+ sone.find(".sone-menu").each(function() {
+ if (getMenuSone(this) == soneId) {
+ $(".follow", this).toggleClass("hidden", true);
+ $(".unfollow", this).toggleClass("hidden", false);
+ }
+ });
+ });
+ return false;
+ });
+ $(".sone-menu .unfollow", replyElement).click(function() {
+ var unfollowElement = this;
+ ajaxGet("unfollowSone.ajax", { "sone": soneId, "formPassword": getFormPassword() }, function() {
+ $(unfollowElement).addClass("hidden");
+ $(unfollowElement).parent().find(".follow").removeClass("hidden");
+ sone.find(".sone-menu").each(function() {
+ if (getMenuSone(this) == soneId) {
+ $(".follow", this).toggleClass("hidden", false);
+ $(".unfollow", this).toggleClass("hidden", true);
+ }
+ });
+ });
+ return false;
+ });
+ })(replyElement);
+}
+
+/**
+ * Ajaxifies the given notification by replacing the form with AJAX.
+ *
+ * @param notification
+ * jQuery object representing the notification.
+ */
+function ajaxifyNotification(notification) {
+ 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() {
+ allIds = $(":input[name=id]", this.form).val().split(" ");
+ for (var 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);
+ if (linkElement.is("[href^='viewPost']")) {
+ id = linkElement.attr("class").substr(5);
+ if (hasPost(id)) {
+ linkElement.attr("href", "#post-" + id).addClass("in-page-link");
+ }
+ }
+ });
+ notification.find("form.dismiss button").click(function() {
+ ajaxGet("dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
+ /* dismiss in case of error, too. */
+ notification.slideUp();
+ }, function(xmlHttpRequest, textStatus, error) {
+ /* ignore error. */
+ });
+ });
+ return notification;
+}
+
+/**
+ * Returns the notification hash. This hash is used in {@link #getStatus()} to
+ * determine whether the notifications changed and need to be reloaded.
+ */
+function getNotificationHash() {
+ return sone.find("#notification-area #notification-hash").text();
+}
+
+/**
+ * Sets the notification hash.
+ *
+ * @param notificationHash
+ * The new notification hash
+ */
+function setNotificationHash(notificationHash) {
+ sone.find("#notification-area #notification-hash").text(notificationHash);
+}
+
+/**
+ * Retrieves element IDs from notification elements.
+ *
+ * @param notification
+ * The notification element
+ * @param selector
+ * The selector of the element containing the ID as text
+ * @returns All extracted IDs
+ */
+function getElementIds(notification, selector) {
+ elementIds = [];
+ $(selector, notification).each(function() {
+ elementIds.push($(this).text());
+ });
+ return elementIds;
+}
+
+/**
+ * Compares the given notification elements and calls {@link #markSoneAsKnown()}
+ * for every ID that is contained in the old notification but not in the new.
+ *
+ * @param oldNotification
+ * The old notification element
+ * @param newNotification
+ * The new notification element
+ */
+function checkForRemovedSones(oldNotification, newNotification) {
+ if (getNotificationId(oldNotification) != "new-sone-notification") {
+ return;
+ }
+ oldIds = getElementIds(oldNotification, ".new-sone-id");
+ newIds = getElementIds(newNotification, ".new-sone-id");
+ $.each(oldIds, function(index, value) {
+ if ($.inArray(value, newIds) == -1) {
+ markSoneAsKnown(getSone(value), true);
+ }
+ });
+}
+
+/**
+ * Compares the given notification elements and calls {@link #markPostAsKnown()}
+ * for every ID that is contained in the old notification but not in the new.
+ *
+ * @param oldNotification
+ * The old notification element
+ * @param newNotification
+ * The new notification element
+ */
+function checkForRemovedPosts(oldNotification, newNotification) {
+ if (getNotificationId(oldNotification) != "new-post-notification") {
+ return;
+ }
+ oldIds = getElementIds(oldNotification, ".post-id");
+ newIds = getElementIds(newNotification, ".post-id");
+ $.each(oldIds, function(index, value) {
+ if ($.inArray(value, newIds) == -1) {
+ markPostAsKnown(getPost(value), true);
+ }
+ });
+}
+
+/**
+ * Compares the given notification elements and calls
+ * {@link #markReplyAsKnown()} for every ID that is contained in the old
+ * notification but not in the new.
+ *
+ * @param oldNotification
+ * The old notification element
+ * @param newNotification
+ * The new notification element
+ */
+function checkForRemovedReplies(oldNotification, newNotification) {
+ if (getNotificationId(oldNotification) != "new-reply-notification") {
+ return;
+ }
+ oldIds = getElementIds(oldNotification, ".reply-id");
+ newIds = getElementIds(newNotification, ".reply-id");
+ $.each(oldIds, function(index, value) {
+ if ($.inArray(value, newIds) == -1) {
+ markReplyAsKnown(getReply(value), true);
+ }
+ });
+}
+
+function getStatus() {
+ ajaxGet("getStatus.ajax", isViewSonePage() ? {"soneIds": getShownSoneId() } : isKnownSonesPage() ? {"soneIds": getShownSoneIds() } : {}, function(data, textStatus) {
+ if ((data != null) && data.success) {