commentElement = (function(postId, author) {
separator = $("<span> · </span>").addClass("separator");
var commentElement = $("<div><span>Comment</span></div>").addClass("show-reply-form").click(function() {
- replyElement = $("#sone .post#" + postId + " .create-reply");
+ replyElement = $("#sone .post#post-" + postId + " .create-reply");
replyElement.removeClass("hidden");
replyElement.removeClass("light");
(function(replyElement) {
return;
}
if (data.success) {
- $("#sone .post#" + postId).slideUp();
+ $("#sone .post#post-" + postId).slideUp();
} else if (data.error == "invalid-post-id") {
/* pretend the post is already gone. */
getPost(postId).slideUp();
return;
}
if (data.success) {
- $("#sone .reply#" + replyId).slideUp();
+ $("#sone .reply#reply-" + replyId).slideUp();
} else if (data.error == "invalid-reply-id") {
/* pretend the reply is already gone. */
getReply(replyId).slideUp();
* @return The Sone ID
*/
function getMenuSone(element) {
- return $(element).closest(".sone-menu").find(".sone-id").text();
+ return $(element).closest(".sone-menu").find(".sone-menu-id").text();
}
/**
* @returns The element of the post
*/
function getPost(postId) {
- return $("#sone .post#" + postId);
+ return $("#sone .post#post-" + postId);
}
function getPostElement(element) {
}
function getPostId(element) {
- return getPostElement(element).attr("id");
+ return getPostElement(element).attr("id").substr(5);
}
function getPostTime(element) {
* @returns The element of the reply
*/
function getReply(replyId) {
- return $("#sone .reply#" + replyId);
+ return $("#sone .reply#reply-" + replyId);
}
function getReplyElement(element) {
}
function getReplyId(element) {
- return getReplyElement(element).attr("id");
+ return getReplyElement(element).attr("id").substr(6);
}
function getReplyTime(element) {
if ((data == null) || !data.success) {
return;
}
- $("#sone .post#" + postId + " > .inner-part > .status-line .like").addClass("hidden");
- $("#sone .post#" + postId + " > .inner-part > .status-line .unlike").removeClass("hidden");
+ $("#sone .post#post-" + postId + " > .inner-part > .status-line .like").addClass("hidden");
+ $("#sone .post#post-" + postId + " > .inner-part > .status-line .unlike").removeClass("hidden");
updatePostLikes(postId);
}, function(xmlHttpRequest, textStatus, error) {
/* ignore error. */
if ((data == null) || !data.success) {
return;
}
- $("#sone .post#" + postId + " > .inner-part > .status-line .unlike").addClass("hidden");
- $("#sone .post#" + postId + " > .inner-part > .status-line .like").removeClass("hidden");
+ $("#sone .post#post-" + postId + " > .inner-part > .status-line .unlike").addClass("hidden");
+ $("#sone .post#post-" + postId + " > .inner-part > .status-line .like").removeClass("hidden");
updatePostLikes(postId);
}, function(xmlHttpRequest, textStatus, error) {
/* ignore error. */
function updatePostLikes(postId) {
ajaxGet("getLikes.ajax", { "type": "post", "post": postId }, function(data, textStatus) {
if ((data != null) && data.success) {
- $("#sone .post#" + postId + " > .inner-part > .status-line .likes").toggleClass("hidden", data.likes == 0);
- $("#sone .post#" + postId + " > .inner-part > .status-line .likes span.like-count").text(data.likes);
- $("#sone .post#" + postId + " > .inner-part > .status-line .likes > span").attr("title", generateSoneList(data.sones));
+ $("#sone .post#post-" + postId + " > .inner-part > .status-line .likes").toggleClass("hidden", data.likes == 0);
+ $("#sone .post#post-" + postId + " > .inner-part > .status-line .likes span.like-count").text(data.likes);
+ $("#sone .post#post-" + postId + " > .inner-part > .status-line .likes > span").attr("title", generateSoneList(data.sones));
}
}, function(xmlHttpRequest, textStatus, error) {
/* ignore error. */
if ((data == null) || !data.success) {
return;
}
- $("#sone .reply#" + replyId + " .status-line .like").addClass("hidden");
- $("#sone .reply#" + replyId + " .status-line .unlike").removeClass("hidden");
+ $("#sone .reply#reply-" + replyId + " .status-line .like").addClass("hidden");
+ $("#sone .reply#reply-" + replyId + " .status-line .unlike").removeClass("hidden");
updateReplyLikes(replyId);
}, function(xmlHttpRequest, textStatus, error) {
/* ignore error. */
if ((data == null) || !data.success) {
return;
}
- $("#sone .reply#" + replyId + " .status-line .unlike").addClass("hidden");
- $("#sone .reply#" + replyId + " .status-line .like").removeClass("hidden");
+ $("#sone .reply#reply-" + replyId + " .status-line .unlike").addClass("hidden");
+ $("#sone .reply#reply-" + replyId + " .status-line .like").removeClass("hidden");
updateReplyLikes(replyId);
}, function(xmlHttpRequest, textStatus, error) {
/* ignore error. */
function updateReplyLikes(replyId) {
ajaxGet("getLikes.ajax", { "type": "reply", "reply": replyId }, function(data, textStatus) {
if ((data != null) && data.success) {
- $("#sone .reply#" + replyId + " .status-line .likes").toggleClass("hidden", data.likes == 0);
- $("#sone .reply#" + replyId + " .status-line .likes span.like-count").text(data.likes);
- $("#sone .reply#" + replyId + " .status-line .likes > span").attr("title", generateSoneList(data.sones));
+ $("#sone .reply#reply-" + replyId + " .status-line .likes").toggleClass("hidden", data.likes == 0);
+ $("#sone .reply#reply-" + replyId + " .status-line .likes span.like-count").text(data.likes);
+ $("#sone .reply#reply-" + replyId + " .status-line .likes > span").attr("title", generateSoneList(data.sones));
}
}, function(xmlHttpRequest, textStatus, error) {
/* ignore error. */
if (success) {
$(inputField).val("");
loadNewReply(replyId, soneId, postId);
- $("#sone .post#" + postId + " .create-reply").addClass("hidden");
- $("#sone .post#" + postId + " .create-reply .sender").hide();
- $("#sone .post#" + postId + " .create-reply .select-sender").show();
- $("#sone .post#" + postId + " .create-reply :input[name=sender]").val(getCurrentSoneId());
+ $("#sone .post#post-" + postId + " .create-reply").addClass("hidden");
+ $("#sone .post#post-" + postId + " .create-reply .sender").hide();
+ $("#sone .post#post-" + postId + " .create-reply .select-sender").show();
+ $("#sone .post#post-" + postId + " .create-reply :input[name=sender]").val(getCurrentSoneId());
} else {
alert(error);
}
/* convert “show source” link into javascript function. */
$(postElement).find(".show-source").each(function() {
$("a", this).click(function() {
+ post = getPostElement(this);
+ rawPostText = $(".post-text.raw-text", post);
+ rawPostText.toggleClass("hidden");
+ if (rawPostText.hasClass("hidden")) {
+ $(".post-text.short-text", post).removeClass("hidden");
+ $(".post-text.text", post).addClass("hidden");
+ $(".expand-post-text", post).removeClass("hidden");
+ $(".shrink-post-text", post).addClass("hidden");
+ } else {
+ $(".post-text.short-text", post).addClass("hidden");
+ $(".post-text.text", post).addClass("hidden");
+ $(".expand-post-text", post).addClass("hidden");
+ $(".shrink-post-text", post).addClass("hidden");
+ }
+ return false;
+ });
+ });
+
+ /* convert “show more” link into javascript function. */
+ $(postElement).find(".expand-post-text").each(function() {
+ $(this).click(function() {
$(".post-text.text", getPostElement(this)).toggleClass("hidden");
- $(".post-text.raw-text", getPostElement(this)).toggleClass("hidden");
+ $(".post-text.short-text", getPostElement(this)).toggleClass("hidden");
+ $(".expand-post-text", getPostElement(this)).toggleClass("hidden");
+ $(".shrink-post-text", getPostElement(this)).toggleClass("hidden");
return false;
});
});
+ $(postElement).find(".shrink-post-text").each(function() {
+ $(this).click(function() {
+ $(".post-text.text", getPostElement(this)).toggleClass("hidden");
+ $(".post-text.short-text", getPostElement(this)).toggleClass("hidden");
+ $(".expand-post-text", getPostElement(this)).toggleClass("hidden");
+ $(".shrink-post-text", getPostElement(this)).toggleClass("hidden");
+ return false;
+ })
+ });
+
+ /* ajaxify author/post links */
+ $(".post-status-line .permalink a", postElement).click(function() {
+ if (!$(".create-reply", postElement).hasClass("hidden")) {
+ textArea = $("input.reply-input", postElement).focus().data("textarea");
+ $(textArea).replaceSelection($(this).attr("href"));
+ }
+ return false;
+ });
/* add “comment” link. */
addCommentLink(getPostId(postElement), getPostAuthor(postElement), postElement, $(postElement).find(".post-status-line .permalink-author"));
/* show Sone menu when hovering over the avatar. */
$(postElement).find(".post-avatar").mouseover(function() {
- $(".sone-post-menu", postElement).mouseleave(function() {
- $(this).fadeOut();
- }).fadeIn();
- return false;
+ if (typeof currentSoneMenuTimeoutHandler != undefined) {
+ clearTimeout(currentSoneMenuTimeoutHandler);
+ }
+ currentSoneMenuId = getPostId(this);
+ currentSoneMenuTimeoutHandler = setTimeout(function() {
+ $(".sone-menu:visible").fadeOut();
+ $(".sone-post-menu", postElement).mouseleave(function() {
+ $(this).fadeOut();
+ }).fadeIn();
+ }, 1000);
+ }).mouseleave(function() {
+ if (currentSoneMenuId = getPostId(this)) {
+ clearTimeout(currentSoneMenuTimeoutHandler);
+ }
});
(function(postElement) {
- var soneId = $(".sone-id", postElement).text();
+ var soneId = $(".sone-menu-id", postElement).text();
$(".sone-post-menu .follow", postElement).click(function() {
var followElement = this;
ajaxGet("followSone.ajax", { "sone": soneId, "formPassword": getFormPassword() }, function() {
});
});
})(replyElement);
+
+ /* ajaxify author links */
+ $(".reply-status-line .permalink a", replyElement).click(function() {
+ if (!$(".create-reply", getPostElement(replyElement)).hasClass("hidden")) {
+ textArea = $("input.reply-input", getPostElement(replyElement)).focus().data("textarea");
+ $(textArea).replaceSelection($(this).attr("href"));
+ }
+ return false;
+ });
+
addCommentLink(getPostId(replyElement), getReplyAuthor(replyElement), replyElement, $(replyElement).find(".reply-status-line .permalink-author"));
/* convert “show source” link into javascript function. */
$(replyElement).find(".show-reply-source").each(function() {
$("a", this).click(function() {
+ reply = getReplyElement(this);
+ rawReplyText = $(".reply-text.raw-text", reply);
+ rawReplyText.toggleClass("hidden");
+ if (rawReplyText.hasClass("hidden")) {
+ $(".reply-text.short-text", reply).removeClass("hidden");
+ $(".reply-text.text", reply).addClass("hidden");
+ $(".expand-reply-text", reply).removeClass("hidden");
+ $(".shrink-reply-text", reply).addClass("hidden");
+ } else {
+ $(".reply-text.short-text", reply).addClass("hidden");
+ $(".reply-text.text", reply).addClass("hidden");
+ $(".expand-reply-text", reply).addClass("hidden");
+ $(".shrink-reply-text", reply).addClass("hidden");
+ }
+ return false;
+ });
+ });
+
+ /* convert “show more” link into javascript function. */
+ $(replyElement).find(".expand-reply-text").each(function() {
+ $(this).click(function() {
$(".reply-text.text", getReplyElement(this)).toggleClass("hidden");
- $(".reply-text.raw-text", getReplyElement(this)).toggleClass("hidden");
+ $(".reply-text.short-text", getReplyElement(this)).toggleClass("hidden");
+ $(".expand-reply-text", getReplyElement(this)).toggleClass("hidden");
+ $(".shrink-reply-text", getReplyElement(this)).toggleClass("hidden");
+ return false;
+ });
+ });
+ $(replyElement).find(".shrink-reply-text").each(function() {
+ $(this).click(function() {
+ $(".reply-text.text", getReplyElement(this)).toggleClass("hidden");
+ $(".reply-text.short-text", getReplyElement(this)).toggleClass("hidden");
+ $(".expand-reply-text", getReplyElement(this)).toggleClass("hidden");
+ $(".shrink-reply-text", getReplyElement(this)).toggleClass("hidden");
return false;
});
});
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 .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 .sone-menu").each(function() {
+ if (getMenuSone(this) == soneId) {
+ $(".follow", this).toggleClass("hidden", false);
+ $(".unfollow", this).toggleClass("hidden", true);
+ }
+ });
+ });
+ return false;
+ });
+ })(replyElement);
}
/**
* The new notification element
*/
function checkForRemovedReplies(oldNotification, newNotification) {
- if (getNotificationId(oldNotification) != "new-replies-notification") {
+ if (getNotificationId(oldNotification) != "new-reply-notification") {
return;
}
oldIds = getElementIds(oldNotification, ".reply-id");
postId = $(this).text();
markPostAsKnown(getPost(postId), true);
});
- } else if (notificationId == "new-replies-notification") {
+ } else if (notificationId == "new-reply-notification") {
$(".reply-id", this).each(function(index, element) {
replyId = $(this).text();
markReplyAsKnown(getReply(replyId), true);
* exists on the page, <code>false</code> otherwise
*/
function hasPost(postId) {
- return $(".post#" + postId).length > 0;
+ return $(".post#post-" + postId).length > 0;
}
/**
* exists on the page, <code>false</code> otherwise
*/
function hasReply(replyId) {
- return $("#sone .reply#" + replyId).length > 0;
+ return $("#sone .reply#reply-" + replyId).length > 0;
}
function loadNewPost(postId, soneId, recipientId, time) {
if (hasReply(data.reply.id)) {
return;
}
- $("#sone .post#" + data.reply.postId).each(function() {
+ $("#sone .post#post-" + data.reply.postId).each(function() {
var firstNewerReply = null;
$(this).find(".replies .reply").each(function() {
if (getReplyTime(this) > data.reply.time) {
function markPostAsKnown(postElements, skipRequest) {
$(postElements).each(function() {
postElement = this;
- if ($(postElement).hasClass("new") || ((typeof skipRequest != "undefined") && !skipRequest)) {
+ if ($(postElement).hasClass("new") || ((typeof skipRequest != "undefined"))) {
(function(postElement) {
$(postElement).removeClass("new");
if ((typeof skipRequest == "undefined") || !skipRequest) {
function markReplyAsKnown(replyElements, skipRequest) {
$(replyElements).each(function() {
replyElement = this;
- if ($(replyElement).hasClass("new") || ((typeof skipRequest != "undefined") && !skipRequest)) {
+ if ($(replyElement).hasClass("new") || ((typeof skipRequest != "undefined"))) {
(function(replyElement) {
$(replyElement).removeClass("new");
if ((typeof skipRequest == "undefined") || !skipRequest) {
var initiallyLoggedIn = $("#sone #loggedIn").text() == "true";
var notLoggedIn = !initiallyLoggedIn;
+/** ID of the next-to-show Sone context menu. */
+var currentSoneMenuId;
+
+/** Timeout handler for the next-to-show Sone context menu. */
+var currentSoneMenuTimeoutHandler;
+
$(document).ready(function() {
/* this initializes the status update input field. */
ajaxifyNotification($(this));
});
- /* disable all permalinks. */
- $(".permalink").click(function() {
- return false;
- });
-
/* activate status polling. */
setTimeout(getStatus, 5000);