1 /* Sone JavaScript functions. */
3 function ajaxGet(url, data, successCallback, errorCallback) {
4 (function(url, data, successCallback, errorCallback) {
5 $.ajax({"type": "GET", "url": url, "data": data, "dataType": "json", "success": function(data, textStatus, xmlHttpRequest) {
7 if (typeof successCallback != "undefined") {
8 successCallback(data, textStatus);
10 }, "error": function(xmlHttpRequest, textStatus, errorThrown) {
11 if (xmlHttpRequest.status == 403) {
14 if (typeof errorCallback != "undefined") {
20 })(url, data, successCallback, errorCallback);
23 function registerInputTextareaSwap(inputElement, defaultText, inputFieldName, optional, dontUseTextarea) {
24 $(inputElement).each(function() {
25 textarea = $(dontUseTextarea ? "<input type=\"text\" name=\"" + inputFieldName + "\">" : "<textarea name=\"" + inputFieldName + "\"></textarea>").blur(function() {
26 if ($(this).val() == "") {
28 inputField = $(this).data("inputField");
29 inputField.show().removeAttr("disabled").addClass("default");
30 inputField.val(defaultText);
32 }).hide().data("inputField", $(this)).val($(this).val());
33 $(this).data("textarea", textarea).after(textarea);
34 (function(inputField, textarea) {
35 inputField.focus(function() {
36 $(this).hide().attr("disabled", "disabled");
37 /* no, show(), “display: block” is not what I need. */
38 textarea.attr("style", "display: inline").focus();
40 if (inputField.val() == "") {
41 inputField.addClass("default");
42 inputField.val(defaultText);
44 inputField.hide().attr("disabled", "disabled");
47 $(inputField.get(0).form).submit(function() {
48 inputField.attr("disabled", "disabled");
49 if (!optional && (textarea.val() == "")) {
50 inputField.removeAttr("disabled").focus();
54 })($(this), textarea);
59 * Adds a “comment” link to all status lines contained in the given element.
64 * The element to add a “comment” link to
66 function addCommentLink(postId, author, element, insertAfterThisElement) {
67 if (($(element).find(".show-reply-form").length > 0) || (getPostElement(element).find(".create-reply").length == 0)) {
70 commentElement = (function(postId, author) {
71 separator = $("<span> · </span>").addClass("separator");
72 var commentElement = $("<div><span>Comment</span></div>").addClass("show-reply-form").click(function() {
73 replyElement = $("#sone .post#" + postId + " .create-reply");
74 replyElement.removeClass("hidden");
75 replyElement.removeClass("light");
76 (function(replyElement) {
77 replyElement.find("input.reply-input").blur(function() {
78 if ($(this).hasClass("default")) {
79 replyElement.addClass("light");
82 replyElement.removeClass("light");
85 textArea = replyElement.find("input.reply-input").focus().data("textarea");
86 if (author != getCurrentSoneId()) {
87 textArea.val(textArea.val() + "@sone://" + author + " ");
90 return commentElement;
92 $(insertAfterThisElement).after(commentElement.clone(true));
93 $(insertAfterThisElement).after(separator);
96 var translations = {};
99 * Retrieves the translation for the given key and calls the callback function.
100 * The callback function takes a single parameter, the translated string.
103 * The key of the translation string
105 * The callback function
107 function getTranslation(key, callback) {
108 if (key in translations) {
109 callback(translations[key]);
112 ajaxGet("getTranslation.ajax", {"key": key}, function(data, textStatus) {
113 if ((data != null) && data.success) {
114 translations[key] = data.value;
115 callback(data.value);
121 * Filters the given Sone ID, replacing all “~” characters by an underscore.
124 * The Sone ID to filter
125 * @returns The filtered Sone ID
127 function filterSoneId(soneId) {
128 return soneId.replace(/[^a-zA-Z0-9-]/g, "_");
132 * Updates the status of the given Sone.
135 * The ID of the Sone to update
137 * The status of the Sone (“idle”, “unknown”, “inserting”,
140 * Whether the Sone is modified
142 * Whether the Sone is locked
144 * The date and time of the last update (formatted for display)
146 function updateSoneStatus(soneId, name, status, modified, locked, lastUpdated, lastUpdatedText) {
147 $("#sone .sone." + filterSoneId(soneId)).
148 toggleClass("unknown", status == "unknown").
149 toggleClass("idle", status == "idle").
150 toggleClass("inserting", status == "inserting").
151 toggleClass("downloading", status == "downloading").
152 toggleClass("modified", modified);
153 $("#sone .sone." + filterSoneId(soneId) + " .lock").toggleClass("hidden", locked);
154 $("#sone .sone." + filterSoneId(soneId) + " .unlock").toggleClass("hidden", !locked);
155 if (lastUpdated != null) {
156 $("#sone .sone." + filterSoneId(soneId) + " .last-update span.time").attr("title", lastUpdated).text(lastUpdatedText);
158 getTranslation("View.Sone.Text.UnknownDate", function(unknown) {
159 $("#sone .sone." + filterSoneId(soneId) + " .last-update span.time").text(unknown);
162 $("#sone .sone." + filterSoneId(soneId) + " .profile-link a").text(name);
166 * Enhances a “delete” button so that the confirmation is done on the same page.
171 * The text to show on the button
172 * @param deleteCallback
173 * The callback that actually deletes something
175 function enhanceDeleteButton(button, text, deleteCallback) {
177 newButton = $("<button></button>").addClass("confirm").hide().text(text).click(function() {
178 $(this).fadeOut("slow");
181 }).insertAfter(button);
182 (function(button, newButton) {
183 button.click(function() {
184 button.fadeOut("slow", function() {
185 newButton.fadeIn("slow");
186 $(document).one("click", function() {
187 if (this != newButton.get(0)) {
188 newButton.fadeOut(function() {
196 })(button, newButton);
201 * Enhances a post’s “delete” button.
206 * The ID of the post to delete
208 * The text to replace the button with
210 function enhanceDeletePostButton(button, postId, text) {
211 enhanceDeleteButton(button, text, function() {
212 ajaxGet("deletePost.ajax", { "post": postId, "formPassword": getFormPassword() }, function(data, textStatus) {
217 $("#sone .post#" + postId).slideUp();
218 } else if (data.error == "invalid-post-id") {
219 /* pretend the post is already gone. */
220 getPost(postId).slideUp();
221 } else if (data.error == "auth-required") {
222 alert("You need to be logged in.");
223 } else if (data.error == "not-authorized") {
224 alert("You are not allowed to delete this post.");
226 }, function(xmlHttpRequest, textStatus, error) {
233 * Enhances a reply’s “delete” button.
238 * The ID of the reply to delete
240 * The text to replace the button with
242 function enhanceDeleteReplyButton(button, replyId, text) {
243 enhanceDeleteButton(button, text, function() {
244 ajaxGet("deleteReply.ajax", { "reply": replyId, "formPassword": $("#sone #formPassword").text() }, function(data, textStatus) {
249 $("#sone .reply#" + replyId).slideUp();
250 } else if (data.error == "invalid-reply-id") {
251 /* pretend the reply is already gone. */
252 getReply(replyId).slideUp();
253 } else if (data.error == "auth-required") {
254 alert("You need to be logged in.");
255 } else if (data.error == "not-authorized") {
256 alert("You are not allowed to delete this reply.");
258 }, function(xmlHttpRequest, textStatus, error) {
264 function getFormPassword() {
265 return $("#sone #formPassword").text();
269 * Returns the element of the Sone with the given ID.
273 * @returns All Sone elements with the given ID
275 function getSone(soneId) {
276 return $("#sone .sone").filter(function(index) {
277 return $(".id", this).text() == soneId;
281 function getSoneElement(element) {
282 return $(element).closest(".sone");
286 * Returns the ID of the sone of the context menu that contains the given
290 * The element within a context menu to get the Sone ID for
291 * @return The Sone ID
293 function getMenuSone(element) {
294 return $(element).closest(".sone-menu").find(".sone-id").text();
298 * Generates a list of Sones by concatening the names of the given sones with a
299 * new line character (“\n”).
302 * The sones to format
303 * @returns {String} The created string
305 function generateSoneList(sones) {
307 $.each(sones, function() {
308 if (soneList != "") {
311 soneList += this.name;
317 * Returns the ID of the Sone that this element belongs to.
320 * The element to locate the matching Sone ID for
321 * @returns The ID of the Sone, or undefined
323 function getSoneId(element) {
324 return getSoneElement(element).find(".id").text();
328 * Returns the element of the post with the given ID.
332 * @returns The element of the post
334 function getPost(postId) {
335 return $("#sone .post#" + postId);
338 function getPostElement(element) {
339 return $(element).closest(".post");
342 function getPostId(element) {
343 return getPostElement(element).attr("id");
346 function getPostTime(element) {
347 return getPostElement(element).find(".post-time").text();
351 * Returns the author of the post the given element belongs to.
354 * The element whose post to get the author for
355 * @returns The ID of the authoring Sone
357 function getPostAuthor(element) {
358 return getPostElement(element).find(".post-author").text();
362 * Returns the element of the reply with the given ID.
365 * The ID of the reply
366 * @returns The element of the reply
368 function getReply(replyId) {
369 return $("#sone .reply#" + replyId);
372 function getReplyElement(element) {
373 return $(element).closest(".reply");
376 function getReplyId(element) {
377 return getReplyElement(element).attr("id");
380 function getReplyTime(element) {
381 return getReplyElement(element).find(".reply-time").text();
385 * Returns the author of the reply the given element belongs to.
388 * The element whose reply to get the author for
389 * @returns The ID of the authoring Sone
391 function getReplyAuthor(element) {
392 return getReplyElement(element).find(".reply-author").text();
396 * Returns the notification with the given ID.
398 * @param notificationId
399 * The ID of the notification
400 * @returns The notification element
402 function getNotification(notificationId) {
403 return $("#sone #notification-area .notification#" + notificationId);
407 * Returns the notification element closest to the given element.
410 * The element to get the closest notification of
411 * @return The closest notification element
413 function getNotificationElement(element) {
414 return $(element).closest(".notification");
418 * Returns the ID of the notification element.
420 * @param notificationElement
421 * The notification element
422 * @returns The ID of the notification
424 function getNotificationId(notificationElement) {
425 return $(notificationElement).attr("id");
429 * Returns the time the notification was last updated.
431 * @param notificationElement
432 * The notification element
433 * @returns The last update time of the notification
435 function getNotificationLastUpdatedTime(notificationElement) {
436 return $(notificationElement).attr("lastUpdatedTime");
439 function likePost(postId) {
440 ajaxGet("like.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
441 if ((data == null) || !data.success) {
444 $("#sone .post#" + postId + " > .inner-part > .status-line .like").addClass("hidden");
445 $("#sone .post#" + postId + " > .inner-part > .status-line .unlike").removeClass("hidden");
446 updatePostLikes(postId);
447 }, function(xmlHttpRequest, textStatus, error) {
452 function unlikePost(postId) {
453 ajaxGet("unlike.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
454 if ((data == null) || !data.success) {
457 $("#sone .post#" + postId + " > .inner-part > .status-line .unlike").addClass("hidden");
458 $("#sone .post#" + postId + " > .inner-part > .status-line .like").removeClass("hidden");
459 updatePostLikes(postId);
460 }, function(xmlHttpRequest, textStatus, error) {
465 function updatePostLikes(postId) {
466 ajaxGet("getLikes.ajax", { "type": "post", "post": postId }, function(data, textStatus) {
467 if ((data != null) && data.success) {
468 $("#sone .post#" + postId + " > .inner-part > .status-line .likes").toggleClass("hidden", data.likes == 0);
469 $("#sone .post#" + postId + " > .inner-part > .status-line .likes span.like-count").text(data.likes);
470 $("#sone .post#" + postId + " > .inner-part > .status-line .likes > span").attr("title", generateSoneList(data.sones));
472 }, function(xmlHttpRequest, textStatus, error) {
477 function likeReply(replyId) {
478 ajaxGet("like.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
479 if ((data == null) || !data.success) {
482 $("#sone .reply#" + replyId + " .status-line .like").addClass("hidden");
483 $("#sone .reply#" + replyId + " .status-line .unlike").removeClass("hidden");
484 updateReplyLikes(replyId);
485 }, function(xmlHttpRequest, textStatus, error) {
490 function unlikeReply(replyId) {
491 ajaxGet("unlike.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
492 if ((data == null) || !data.success) {
495 $("#sone .reply#" + replyId + " .status-line .unlike").addClass("hidden");
496 $("#sone .reply#" + replyId + " .status-line .like").removeClass("hidden");
497 updateReplyLikes(replyId);
498 }, function(xmlHttpRequest, textStatus, error) {
504 * Trusts the Sone with the given ID.
507 * The ID of the Sone to trust
509 function trustSone(soneId) {
510 ajaxGet("trustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data, textStatus) {
511 if ((data != null) && data.success) {
512 updateTrustControls(soneId, data.trustValue);
518 * Distrusts the Sone with the given ID, i.e. assigns a negative trust value.
521 * The ID of the Sone to distrust
523 function distrustSone(soneId) {
524 ajaxGet("distrustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data, textStatus) {
525 if ((data != null) && data.success) {
526 updateTrustControls(soneId, data.trustValue);
532 * Untrusts the Sone with the given ID, i.e. removes any trust assignment.
535 * The ID of the Sone to untrust
537 function untrustSone(soneId) {
538 ajaxGet("untrustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data, textStatus) {
539 if ((data != null) && data.success) {
540 updateTrustControls(soneId, data.trustValue);
546 * Updates the trust controls for all posts and replies of the given Sone,
547 * according to the given trust value.
550 * The ID of the Sone to update all trust controls for
552 * The trust value for the Sone
554 function updateTrustControls(soneId, trustValue) {
555 $("#sone .post").each(function() {
556 if (getPostAuthor(this) == soneId) {
557 getPostElement(this).find(".post-trust").toggleClass("hidden", trustValue != null);
558 getPostElement(this).find(".post-distrust").toggleClass("hidden", trustValue != null);
559 getPostElement(this).find(".post-untrust").toggleClass("hidden", trustValue == null);
562 $("#sone .reply").each(function() {
563 if (getReplyAuthor(this) == soneId) {
564 getReplyElement(this).find(".reply-trust").toggleClass("hidden", trustValue != null);
565 getReplyElement(this).find(".reply-distrust").toggleClass("hidden", trustValue != null);
566 getReplyElement(this).find(".reply-untrust").toggleClass("hidden", trustValue == null);
572 * Bookmarks the post with the given ID.
575 * The ID of the post to bookmark
577 function bookmarkPost(postId) {
579 ajaxGet("bookmark.ajax", {"formPassword": getFormPassword(), "type": "post", "post": postId}, function(data, textStatus) {
580 if ((data != null) && data.success) {
581 getPost(postId).find(".bookmark").toggleClass("hidden", true);
582 getPost(postId).find(".unbookmark").toggleClass("hidden", false);
589 * Unbookmarks the post with the given ID.
592 * The ID of the post to unbookmark
594 function unbookmarkPost(postId) {
595 ajaxGet("unbookmark.ajax", {"formPassword": getFormPassword(), "type": "post", "post": postId}, function(data, textStatus) {
596 if ((data != null) && data.success) {
597 getPost(postId).find(".bookmark").toggleClass("hidden", false);
598 getPost(postId).find(".unbookmark").toggleClass("hidden", true);
603 function updateReplyLikes(replyId) {
604 ajaxGet("getLikes.ajax", { "type": "reply", "reply": replyId }, function(data, textStatus) {
605 if ((data != null) && data.success) {
606 $("#sone .reply#" + replyId + " .status-line .likes").toggleClass("hidden", data.likes == 0);
607 $("#sone .reply#" + replyId + " .status-line .likes span.like-count").text(data.likes);
608 $("#sone .reply#" + replyId + " .status-line .likes > span").attr("title", generateSoneList(data.sones));
610 }, function(xmlHttpRequest, textStatus, error) {
616 * Posts a reply and calls the given callback when the request finishes.
619 * The ID of the sender
621 * The ID of the post the reply refers to
624 * @param callbackFunction
625 * The callback function to call when the request finishes (takes 3
626 * parameters: success, error, replyId)
628 function postReply(sender, postId, text, callbackFunction) {
629 ajaxGet("createReply.ajax", { "formPassword" : getFormPassword(), "sender": sender, "post" : postId, "text": text }, function(data, textStatus) {
631 /* TODO - show error */
635 callbackFunction(true, null, data.reply, data.sone);
637 callbackFunction(false, data.error);
639 }, function(xmlHttpRequest, textStatus, error) {
645 * Ajaxifies the given Sone by enhancing all eligible elements with AJAX.
648 * The Sone to ajaxify
650 function ajaxifySone(soneElement) {
652 * convert all “follow”, “unfollow”, “lock”, and “unlock” links to something
655 $(".follow", soneElement).submit(function() {
656 var followElement = this;
657 ajaxGet("followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
658 $(followElement).addClass("hidden");
659 $(followElement).parent().find(".unfollow").removeClass("hidden");
663 $(".unfollow", soneElement).submit(function() {
664 var unfollowElement = this;
665 ajaxGet("unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
666 $(unfollowElement).addClass("hidden");
667 $(unfollowElement).parent().find(".follow").removeClass("hidden");
671 $(".lock", soneElement).submit(function() {
672 var lockElement = this;
673 ajaxGet("lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
674 $(lockElement).addClass("hidden");
675 $(lockElement).parent().find(".unlock").removeClass("hidden");
679 $(".unlock", soneElement).submit(function() {
680 var unlockElement = this;
681 ajaxGet("unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
682 $(unlockElement).addClass("hidden");
683 $(unlockElement).parent().find(".lock").removeClass("hidden");
688 /* mark Sone as known when clicking it. */
689 $(soneElement).click(function() {
690 markSoneAsKnown(this);
695 * Ajaxifies the given post by enhancing all eligible elements with AJAX.
698 * The post element to ajaxify
700 function ajaxifyPost(postElement) {
701 $(postElement).find("form").submit(function() {
704 $(postElement).find(".create-reply button:submit").click(function() {
706 button.attr("disabled", "disabled");
707 sender = $(this.form).find(":input[name=sender]").val();
708 inputField = $(this.form).find(":input[name=text]:enabled").get(0);
709 postId = getPostId(this);
710 text = $(inputField).val();
711 (function(sender, postId, text, inputField) {
712 postReply(sender, postId, text, function(success, error, replyId, soneId) {
714 $(inputField).val("");
715 loadNewReply(replyId, soneId, postId);
716 $("#sone .post#" + postId + " .create-reply").addClass("hidden");
717 $("#sone .post#" + postId + " .create-reply .sender").hide();
718 $("#sone .post#" + postId + " .create-reply .select-sender").show();
719 $("#sone .post#" + postId + " .create-reply :input[name=sender]").val(getCurrentSoneId());
723 button.removeAttr("disabled");
725 })(sender, postId, text, inputField);
729 /* replace all “delete” buttons with javascript. */
730 (function(postElement) {
731 getTranslation("WebInterface.Confirmation.DeletePostButton", function(deletePostText) {
732 postId = getPostId(postElement);
733 enhanceDeletePostButton($(postElement).find(".delete-post button"), postId, deletePostText);
737 /* convert all “like” buttons to javascript functions. */
738 $(postElement).find(".like-post").submit(function() {
739 likePost(getPostId(this));
742 $(postElement).find(".unlike-post").submit(function() {
743 unlikePost(getPostId(this));
747 /* convert trust control buttons to javascript functions. */
748 $(postElement).find(".post-trust").submit(function() {
749 trustSone(getPostAuthor(this));
752 $(postElement).find(".post-distrust").submit(function() {
753 distrustSone(getPostAuthor(this));
756 $(postElement).find(".post-untrust").submit(function() {
757 untrustSone(getPostAuthor(this));
761 /* convert bookmark/unbookmark buttons to javascript functions. */
762 $(postElement).find(".bookmark").submit(function() {
763 bookmarkPost(getPostId(this));
766 $(postElement).find(".unbookmark").submit(function() {
767 unbookmarkPost(getPostId(this));
771 /* convert “show source” link into javascript function. */
772 $(postElement).find(".show-source").each(function() {
773 $("a", this).click(function() {
774 $(".post-text.text", getPostElement(this)).toggleClass("hidden");
775 $(".post-text.raw-text", getPostElement(this)).toggleClass("hidden");
780 /* add “comment” link. */
781 addCommentLink(getPostId(postElement), getPostAuthor(postElement), postElement, $(postElement).find(".post-status-line .permalink-author"));
783 /* process all replies. */
785 $(postElement).find(".reply").each(function() {
786 replyIds.push(getReplyId(this));
789 updateReplyTimes(replyIds.join(","));
791 /* process reply input fields. */
792 getTranslation("WebInterface.DefaultText.Reply", function(text) {
793 $(postElement).find("input.reply-input").each(function() {
794 registerInputTextareaSwap(this, text, "text", false, false);
798 /* process sender selection. */
799 $(".select-sender", postElement).css("display", "inline");
800 $(".sender", postElement).hide();
801 $(".select-sender button", postElement).click(function() {
802 $(".sender", postElement).show();
803 $(".select-sender", postElement).hide();
807 /* mark everything as known on click. */
808 $(postElement).click(function(event) {
809 if ($(event.target).hasClass("click-to-show")) {
812 markPostAsKnown(this);
815 /* hide reply input field. */
816 $(postElement).find(".create-reply").addClass("hidden");
818 /* show Sone menu when hovering over the avatar. */
819 $(postElement).find(".post-avatar").mouseover(function() {
820 $(".sone-post-menu", postElement).mouseleave(function() {
825 (function(postElement) {
826 var soneId = $(".sone-id", postElement).text();
827 $(".sone-post-menu .follow", postElement).click(function() {
828 var followElement = this;
829 ajaxGet("followSone.ajax", { "sone": soneId, "formPassword": getFormPassword() }, function() {
830 $(followElement).addClass("hidden");
831 $(followElement).parent().find(".unfollow").removeClass("hidden");
832 $("#sone .sone-menu").each(function() {
833 if (getMenuSone(this) == soneId) {
834 $(".follow", this).toggleClass("hidden", true);
835 $(".unfollow", this).toggleClass("hidden", false);
841 $(".sone-post-menu .unfollow", postElement).click(function() {
842 var unfollowElement = this;
843 ajaxGet("unfollowSone.ajax", { "sone": soneId, "formPassword": getFormPassword() }, function() {
844 $(unfollowElement).addClass("hidden");
845 $(unfollowElement).parent().find(".follow").removeClass("hidden");
846 $("#sone .sone-menu").each(function() {
847 if (getMenuSone(this) == soneId) {
848 $(".follow", this).toggleClass("hidden", false);
849 $(".unfollow", this).toggleClass("hidden", true);
859 * Ajaxifies the given reply element.
861 * @param replyElement
862 * The reply element to ajaxify
864 function ajaxifyReply(replyElement) {
865 $(replyElement).find(".like-reply").submit(function() {
866 likeReply(getReplyId(this));
869 $(replyElement).find(".unlike-reply").submit(function() {
870 unlikeReply(getReplyId(this));
873 (function(replyElement) {
874 getTranslation("WebInterface.Confirmation.DeleteReplyButton", function(deleteReplyText) {
875 $(replyElement).find(".delete-reply button").each(function() {
876 enhanceDeleteReplyButton(this, getReplyId(replyElement), deleteReplyText);
880 addCommentLink(getPostId(replyElement), getReplyAuthor(replyElement), replyElement, $(replyElement).find(".reply-status-line .permalink-author"));
882 /* convert “show source” link into javascript function. */
883 $(replyElement).find(".show-reply-source").each(function() {
884 $("a", this).click(function() {
885 $(".reply-text.text", getReplyElement(this)).toggleClass("hidden");
886 $(".reply-text.raw-text", getReplyElement(this)).toggleClass("hidden");
891 /* convert trust control buttons to javascript functions. */
892 $(replyElement).find(".reply-trust").submit(function() {
893 trustSone(getReplyAuthor(this));
896 $(replyElement).find(".reply-distrust").submit(function() {
897 distrustSone(getReplyAuthor(this));
900 $(replyElement).find(".reply-untrust").submit(function() {
901 untrustSone(getReplyAuthor(this));
905 /* show Sone menu when hovering over the avatar. */
906 $(replyElement).find(".reply-avatar").mouseover(function() {
907 $(".sone-reply-menu", replyElement).mouseleave(function() {
912 (function(replyElement) {
913 var soneId = $(".sone-id", replyElement).text();
914 $(".sone-menu .follow", replyElement).click(function() {
915 var followElement = this;
916 ajaxGet("followSone.ajax", { "sone": soneId, "formPassword": getFormPassword() }, function() {
917 $(followElement).addClass("hidden");
918 $(followElement).parent().find(".unfollow").removeClass("hidden");
919 $("#sone .sone-menu").each(function() {
920 if (getMenuSone(this) == soneId) {
921 $(".follow", this).toggleClass("hidden", true);
922 $(".unfollow", this).toggleClass("hidden", false);
928 $(".sone-menu .unfollow", replyElement).click(function() {
929 var unfollowElement = this;
930 ajaxGet("unfollowSone.ajax", { "sone": soneId, "formPassword": getFormPassword() }, function() {
931 $(unfollowElement).addClass("hidden");
932 $(unfollowElement).parent().find(".follow").removeClass("hidden");
933 $("#sone .sone-menu").each(function() {
934 if (getMenuSone(this) == soneId) {
935 $(".follow", this).toggleClass("hidden", false);
936 $(".unfollow", this).toggleClass("hidden", true);
946 * Ajaxifies the given notification by replacing the form with AJAX.
948 * @param notification
949 * jQuery object representing the notification.
951 function ajaxifyNotification(notification) {
952 notification.find("form").submit(function() {
955 notification.find("input[name=returnPage]").val($.url.attr("relative"));
956 if (notification.find(".short-text").length > 0) {
957 notification.find(".short-text").removeClass("hidden");
958 notification.find(".text").addClass("hidden");
960 notification.find("form.mark-as-read button").click(function() {
961 allIds = $(":input[name=id]", this.form).val().split(" ");
962 for (index = 0; index < allIds.length; index += 16) {
963 ids = allIds.slice(index, index + 16).join(" ");
964 ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": $(":input[name=type]", this.form).val(), "id": ids});
967 notification.find("a[class^='link-']").each(function() {
968 linkElement = $(this);
969 if (linkElement.is("[href^='viewPost']")) {
970 id = linkElement.attr("class").substr(5);
972 linkElement.attr("href", "#post-" + id).addClass("in-page-link");
976 notification.find("form.dismiss button").click(function() {
977 ajaxGet("dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
978 /* dismiss in case of error, too. */
979 notification.slideUp();
980 }, function(xmlHttpRequest, textStatus, error) {
988 * Retrieves element IDs from notification elements.
990 * @param notification
991 * The notification element
993 * The selector of the element containing the ID as text
994 * @returns All extracted IDs
996 function getElementIds(notification, selector) {
998 $(selector, notification).each(function() {
999 elementIds.push($(this).text());
1005 * Compares the given notification elements and calls {@link #markSoneAsKnown()}
1006 * for every ID that is contained in the old notification but not in the new.
1008 * @param oldNotification
1009 * The old notification element
1010 * @param newNotification
1011 * The new notification element
1013 function checkForRemovedSones(oldNotification, newNotification) {
1014 if (getNotificationId(oldNotification) != "new-sone-notification") {
1017 oldIds = getElementIds(oldNotification, ".new-sone-id");
1018 newIds = getElementIds(newNotification, ".new-sone-id");
1019 $.each(oldIds, function(index, value) {
1020 if ($.inArray(value, newIds) == -1) {
1021 markSoneAsKnown(getSone(value), true);
1027 * Compares the given notification elements and calls {@link #markPostAsKnown()}
1028 * for every ID that is contained in the old notification but not in the new.
1030 * @param oldNotification
1031 * The old notification element
1032 * @param newNotification
1033 * The new notification element
1035 function checkForRemovedPosts(oldNotification, newNotification) {
1036 if (getNotificationId(oldNotification) != "new-post-notification") {
1039 oldIds = getElementIds(oldNotification, ".post-id");
1040 newIds = getElementIds(newNotification, ".post-id");
1041 $.each(oldIds, function(index, value) {
1042 if ($.inArray(value, newIds) == -1) {
1043 markPostAsKnown(getPost(value), true);
1049 * Compares the given notification elements and calls
1050 * {@link #markReplyAsKnown()} for every ID that is contained in the old
1051 * notification but not in the new.
1053 * @param oldNotification
1054 * The old notification element
1055 * @param newNotification
1056 * The new notification element
1058 function checkForRemovedReplies(oldNotification, newNotification) {
1059 if (getNotificationId(oldNotification) != "new-replies-notification") {
1062 oldIds = getElementIds(oldNotification, ".reply-id");
1063 newIds = getElementIds(newNotification, ".reply-id");
1064 $.each(oldIds, function(index, value) {
1065 if ($.inArray(value, newIds) == -1) {
1066 markReplyAsKnown(getReply(value), true);
1071 function getStatus() {
1072 ajaxGet("getStatus.ajax", isViewSonePage() ? {"soneIds": getShownSoneId() } : {"loadAllSones": isKnownSonesPage()}, function(data, textStatus) {
1073 if ((data != null) && data.success) {
1074 /* process Sone information. */
1075 $.each(data.sones, function(index, value) {
1076 updateSoneStatus(value.id, value.name, value.status, value.modified, value.locked, value.lastUpdatedUnknown ? null : value.lastUpdated, value.lastUpdatedText);
1078 notLoggedIn = !data.loggedIn;
1080 showOfflineMarker(!online);
1082 /* search for removed notifications. */
1083 $("#sone #notification-area .notification").each(function() {
1084 notificationId = $(this).attr("id");
1085 foundNotification = false;
1086 $.each(data.notifications, function(index, value) {
1087 if (value.id == notificationId) {
1088 foundNotification = true;
1092 if (!foundNotification) {
1093 if (notificationId == "new-sone-notification") {
1094 $(".new-sone-id", this).each(function(index, element) {
1095 soneId = $(this).text();
1096 markSoneAsKnown(getSone(soneId), true);
1098 } else if (notificationId == "new-post-notification") {
1099 $(".post-id", this).each(function(index, element) {
1100 postId = $(this).text();
1101 markPostAsKnown(getPost(postId), true);
1103 } else if (notificationId == "new-replies-notification") {
1104 $(".reply-id", this).each(function(index, element) {
1105 replyId = $(this).text();
1106 markReplyAsKnown(getReply(replyId), true);
1109 $(this).slideUp("normal", function() {
1111 /* remove activity when no notifications are visible. */
1112 if ($("#sone #notification-area .notification").length == 0) {
1118 /* process notifications. */
1119 notificationIds = [];
1120 $.each(data.notifications, function(index, value) {
1121 oldNotification = getNotification(value.id);
1122 if ((oldNotification.length == 0) || (value.lastUpdatedTime > getNotificationLastUpdatedTime(oldNotification))) {
1123 notificationIds.push(value.id);
1126 if (notificationIds.length > 0) {
1127 loadNotifications(notificationIds);
1129 /* process new posts. */
1130 $.each(data.newPosts, function(index, value) {
1131 loadNewPost(value.id, value.sone, value.recipient, value.time);
1133 /* process new replies. */
1134 $.each(data.newReplies, function(index, value) {
1135 loadNewReply(value.id, value.sone, value.post, value.postSone);
1137 /* do it again in 5 seconds. */
1138 setTimeout(getStatus, 5000);
1140 /* data.success was false, wait 30 seconds. */
1141 setTimeout(getStatus, 30000);
1144 statusRequestQueued = false;
1150 * Requests multiple notifications from Sone and displays them.
1152 * @param notificationIds
1153 * Array of IDs of the notifications to load
1155 function loadNotifications(notificationIds) {
1156 ajaxGet("getNotification.ajax", {"notifications": notificationIds.join(",")}, function(data, textStatus) {
1157 if (!data || !data.success) {
1158 // TODO - show error
1161 $.each(data.notifications, function(index, value) {
1162 oldNotification = getNotification(value.id);
1163 notification = ajaxifyNotification(createNotification(value.id, value.lastUpdatedTime, value.text, value.dismissable)).hide();
1164 if (oldNotification.length != 0) {
1165 if ((oldNotification.find(".short-text").length > 0) && (notification.find(".short-text").length > 0)) {
1166 opened = oldNotification.is(":visible") && oldNotification.find(".short-text").hasClass("hidden");
1167 notification.find(".short-text").toggleClass("hidden", opened);
1168 notification.find(".text").toggleClass("hidden", !opened);
1170 checkForRemovedSones(oldNotification, notification);
1171 checkForRemovedPosts(oldNotification, notification);
1172 checkForRemovedReplies(oldNotification, notification);
1173 oldNotification.replaceWith(notification.show());
1175 $("#sone #notification-area").append(notification);
1176 if (value.id.substring(0, 5) != "local") {
1177 notification.slideDown();
1186 * Returns the ID of the currently logged in Sone.
1188 * @return The ID of the current Sone, or an empty string if no Sone is logged
1191 function getCurrentSoneId() {
1192 return $("#currentSoneId").text();
1196 * Returns the content of the page-id attribute.
1198 * @returns The page ID
1200 function getPageId() {
1201 return $("#sone .page-id").text();
1205 * Returns whether the current page is the index page.
1207 * @returns {Boolean} <code>true</code> if the current page is the index page,
1208 * <code>false</code> otherwise
1210 function isIndexPage() {
1211 return getPageId() == "index";
1215 * Returns the current page of the selected pagination. If no pagination can be
1216 * found with the given selector, {@code 1} is returned.
1218 * @param paginationSelector
1219 * The pagination selector
1220 * @returns The current page of the pagination
1222 function getPage(paginationSelector) {
1223 pagination = $(paginationSelector);
1224 if (pagination.length > 0) {
1225 return $(".current-page", paginationSelector).text();
1231 * Returns whether the current page is a “view Sone” page.
1233 * @returns {Boolean} <code>true</code> if the current page is a “view Sone”
1234 * page, <code>false</code> otherwise
1236 function isViewSonePage() {
1237 return getPageId() == "view-sone";
1241 * Returns the ID of the currently shown Sone. This will only return a sensible
1242 * value if isViewSonePage() returns <code>true</code>.
1244 * @returns The ID of the currently shown Sone
1246 function getShownSoneId() {
1247 return $("#sone .sone-id").text();
1251 * Returns whether the current page is a “view post” page.
1253 * @returns {Boolean} <code>true</code> if the current page is a “view post”
1254 * page, <code>false</code> otherwise
1256 function isViewPostPage() {
1257 return getPageId() == "view-post";
1261 * Returns the ID of the currently shown post. This will only return a sensible
1262 * value if isViewPostPage() returns <code>true</code>.
1264 * @returns The ID of the currently shown post
1266 function getShownPostId() {
1267 return $("#sone .post-id").text();
1271 * Returns whether the current page is the “known Sones” page.
1273 * @returns {Boolean} <code>true</code> if the current page is the “known
1274 * Sones” page, <code>false</code> otherwise
1276 function isKnownSonesPage() {
1277 return getPageId() == "known-sones";
1281 * Returns whether a post with the given ID exists on the current page.
1284 * The post ID to check for
1285 * @returns {Boolean} <code>true</code> if a post with the given ID already
1286 * exists on the page, <code>false</code> otherwise
1288 function hasPost(postId) {
1289 return $(".post#" + postId).length > 0;
1293 * Returns whether a reply with the given ID exists on the current page.
1296 * The reply ID to check for
1297 * @returns {Boolean} <code>true</code> if a reply with the given ID already
1298 * exists on the page, <code>false</code> otherwise
1300 function hasReply(replyId) {
1301 return $("#sone .reply#" + replyId).length > 0;
1304 function loadNewPost(postId, soneId, recipientId, time) {
1305 if (hasPost(postId)) {
1308 if (!isIndexPage() || (getPage(".pagination-index") > 1)) {
1309 if (!isViewPostPage() || (getShownPostId() != postId)) {
1310 if (!isViewSonePage() || ((getShownSoneId() != soneId) && (getShownSoneId() != recipientId)) || (getPage(".post-navigation") > 1)) {
1315 if (getPostTime($("#sone .post").last()) > time) {
1318 ajaxGet("getPost.ajax", { "post" : postId }, function(data, textStatus) {
1319 if ((data != null) && data.success) {
1320 if (hasPost(data.post.id)) {
1323 if ((!isIndexPage() || (getPage(".pagination-index") > 1)) && !(isViewSonePage() && ((getShownSoneId() == data.post.sone) || (getShownSoneId() == data.post.recipient) || (getPage(".post-navigation") > 1)))) {
1326 var firstOlderPost = null;
1327 $("#sone .post").each(function() {
1328 if (getPostTime(this) < data.post.time) {
1329 firstOlderPost = $(this);
1333 newPost = $(data.post.html).addClass("hidden");
1334 if ($(".post-author-local", newPost).text() == "true") {
1335 newPost.removeClass("new");
1337 if (firstOlderPost != null) {
1338 newPost.insertBefore(firstOlderPost);
1340 ajaxifyPost(newPost);
1341 updatePostTimes(data.post.id);
1342 newPost.slideDown();
1348 function loadNewReply(replyId, soneId, postId, postSoneId) {
1349 if (hasReply(replyId)) {
1352 if (!hasPost(postId)) {
1355 ajaxGet("getReply.ajax", { "reply": replyId }, function(data, textStatus) {
1357 if ((data != null) && data.success) {
1358 if (hasReply(data.reply.id)) {
1361 $("#sone .post#" + data.reply.postId).each(function() {
1362 var firstNewerReply = null;
1363 $(this).find(".replies .reply").each(function() {
1364 if (getReplyTime(this) > data.reply.time) {
1365 firstNewerReply = $(this);
1369 newReply = $(data.reply.html).addClass("hidden");
1370 if ($(".reply-author-local", newReply).text() == "true") {
1371 newReply.removeClass("new");
1372 (function(newReply) {
1373 setTimeout(function() {
1374 markReplyAsKnown(newReply, false);
1378 if (firstNewerReply != null) {
1379 newReply.insertBefore(firstNewerReply);
1381 if ($(this).find(".replies .create-reply")) {
1382 $(this).find(".replies .create-reply").before(newReply);
1384 $(this).find(".replies").append(newReply);
1387 ajaxifyReply(newReply);
1388 updateReplyTimes(data.reply.id);
1389 newReply.slideDown();
1398 * Marks the given Sone as known if it is still new.
1400 * @param soneElement
1401 * The Sone to mark as known
1402 * @param skipRequest
1403 * true to skip the JSON request, false or omit to perform the JSON
1406 function markSoneAsKnown(soneElement, skipRequest) {
1407 if ($(soneElement).is(".new")) {
1408 $(soneElement).removeClass("new");
1409 if ((typeof skipRequest == "undefined") || !skipRequest) {
1410 ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "sone", "id": getSoneId(soneElement)});
1415 function markPostAsKnown(postElements, skipRequest) {
1416 $(postElements).each(function() {
1418 if ($(postElement).hasClass("new") || ((typeof skipRequest != "undefined") && !skipRequest)) {
1419 (function(postElement) {
1420 $(postElement).removeClass("new");
1421 if ((typeof skipRequest == "undefined") || !skipRequest) {
1422 ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "post", "id": getPostId(postElement)});
1426 $(".click-to-show", postElement).removeClass("new");
1428 markReplyAsKnown($(postElements).find(".reply"));
1431 function markReplyAsKnown(replyElements, skipRequest) {
1432 $(replyElements).each(function() {
1433 replyElement = this;
1434 if ($(replyElement).hasClass("new") || ((typeof skipRequest != "undefined") && !skipRequest)) {
1435 (function(replyElement) {
1436 $(replyElement).removeClass("new");
1437 if ((typeof skipRequest == "undefined") || !skipRequest) {
1438 ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "reply", "id": getReplyId(replyElement)});
1446 * Updates the time of the post with the given ID.
1449 * The ID of the post to update
1451 * The text of the time to show
1452 * @param refreshTime
1453 * The refresh time after which to request a new time (in seconds)
1455 * The tooltip to show
1457 function updatePostTime(postId, timeText, refreshTime, tooltip) {
1458 if (!getPost(postId).is(":visible")) {
1461 getPost(postId).find(".post-status-line > .time a").html(timeText).attr("title", tooltip);
1462 (function(postId, refreshTime) {
1463 setTimeout(function() {
1464 updatePostTimes(postId);
1465 }, refreshTime * 1000);
1466 })(postId, refreshTime);
1470 * Requests new rendered times for the posts with the given IDs.
1473 * Comma-separated post IDs
1475 function updatePostTimes(postIds) {
1476 ajaxGet("getTimes.ajax", { "posts" : postIds }, function(data, textStatus) {
1477 if ((data != null) && data.success) {
1478 $.each(data.postTimes, function(index, value) {
1479 updatePostTime(index, value.timeText, value.refreshTime, value.tooltip);
1486 * Updates the time of the reply with the given ID.
1489 * The ID of the reply to update
1491 * The text of the time to show
1492 * @param refreshTime
1493 * The refresh time after which to request a new time (in seconds)
1495 * The tooltip to show
1497 function updateReplyTime(replyId, timeText, refreshTime, tooltip) {
1498 getReply(replyId).find(".reply-status-line > .time").html(timeText).attr("title", tooltip);
1499 (function(replyId, refreshTime) {
1500 setTimeout(function() {
1501 updateReplyTimes(replyId);
1502 }, refreshTime * 1000);
1503 })(replyId, refreshTime);
1507 * Requests new rendered times for the posts with the given IDs.
1510 * Comma-separated post IDs
1512 function updateReplyTimes(replyIds) {
1513 ajaxGet("getTimes.ajax", { "replies" : replyIds }, function(data, textStatus) {
1514 if ((data != null) && data.success) {
1515 $.each(data.replyTimes, function(index, value) {
1516 updateReplyTime(index, value.timeText, value.refreshTime, value.tooltip);
1522 function resetActivity() {
1523 title = document.title;
1524 if (title.indexOf('(') == 0) {
1525 setTitle(title.substr(title.indexOf(' ') + 1));
1527 iconBlinking = false;
1530 function setActivity() {
1532 title = document.title;
1533 if (title.indexOf('(') != 0) {
1534 setTitle("(!) " + title);
1536 if (!iconBlinking) {
1537 setTimeout(toggleIcon, 1500);
1538 iconBlinking = true;
1544 * Sets the window title after a small delay to prevent race-condition issues.
1549 function setTitle(title) {
1550 setTimeout(function() {
1551 document.title = title;
1555 /** Whether the icon is currently showing activity. */
1556 var iconActive = false;
1558 /** Whether the icon is currently supposed to blink. */
1559 var iconBlinking = false;
1562 * Toggles the icon. If the window has gained focus and the icon is still
1563 * showing the activity state, it is returned to normal.
1565 function toggleIcon() {
1566 if (focus || !iconBlinking) {
1568 changeIcon("images/icon.png");
1571 iconBlinking = false;
1573 iconActive = !iconActive;
1574 changeIcon(iconActive ? "images/icon-activity.png" : "images/icon.png");
1575 setTimeout(toggleIcon, 1500);
1580 * Changes the icon of the page.
1583 * The new URL of the icon
1585 function changeIcon(iconUrl) {
1586 $("link[rel=icon]").remove();
1587 $("head").append($("<link>").attr("rel", "icon").attr("type", "image/png").attr("href", iconUrl));
1588 $("iframe[id=icon-update]")[0].src += "";
1592 * Creates a new notification.
1595 * The ID of the notificaiton
1597 * The text of the notification
1598 * @param dismissable
1599 * <code>true</code> if the notification can be dismissed by the
1602 function createNotification(id, lastUpdatedTime, text, dismissable) {
1603 notification = $("<div></div>").addClass("notification").attr("id", id).attr("lastUpdatedTime", lastUpdatedTime);
1605 dismissForm = $("#sone #notification-area #notification-dismiss-template").clone().removeClass("hidden").removeAttr("id");
1606 dismissForm.find("input[name=notification]").val(id);
1607 notification.append(dismissForm);
1609 notification.append(text);
1610 return notification;
1614 * Shows the details of the notification with the given ID.
1616 * @param notificationId
1617 * The ID of the notification
1619 function showNotificationDetails(notificationId) {
1620 $("#sone .notification#" + notificationId + " .text").removeClass("hidden");
1621 $("#sone .notification#" + notificationId + " .short-text").addClass("hidden");
1625 * Deletes the field with the given ID from the profile.
1628 * The ID of the field to delete
1630 function deleteProfileField(fieldId) {
1631 ajaxGet("deleteProfileField.ajax", {"formPassword": getFormPassword(), "field": fieldId}, function(data, textStatus) {
1632 if (data && data.success) {
1633 $("#sone .profile-field#" + data.field.id).slideUp();
1639 * Renames a profile field.
1642 * The ID of the field to rename
1644 * The new name of the field
1645 * @param successFunction
1646 * Called when the renaming was successful
1648 function editProfileField(fieldId, newName, successFunction) {
1649 ajaxGet("editProfileField.ajax", {"formPassword": getFormPassword(), "field": fieldId, "name": newName}, function(data, textStatus) {
1650 if (data && data.success) {
1657 * Moves the profile field with the given ID one slot in the given direction.
1660 * The ID of the field to move
1662 * The direction to move in (“up” or “down”)
1663 * @param successFunction
1664 * Function to call on success
1666 function moveProfileField(fieldId, direction, successFunction) {
1667 ajaxGet("moveProfileField.ajax", {"formPassword": getFormPassword(), "field": fieldId, "direction": direction}, function(data, textStatus) {
1668 if (data && data.success) {
1675 * Moves the profile field with the given ID up one slot.
1678 * The ID of the field to move
1679 * @param successFunction
1680 * Function to call on success
1682 function moveProfileFieldUp(fieldId, successFunction) {
1683 moveProfileField(fieldId, "up", successFunction);
1687 * Moves the profile field with the given ID down one slot.
1690 * The ID of the field to move
1691 * @param successFunction
1692 * Function to call on success
1694 function moveProfileFieldDown(fieldId, successFunction) {
1695 moveProfileField(fieldId, "down", successFunction);
1698 var statusRequestQueued = true;
1701 * Sets the status of the web interface as offline.
1703 function ajaxError() {
1705 showOfflineMarker(true);
1706 if (!statusRequestQueued) {
1707 setTimeout(getStatus, 5000);
1708 statusRequestQueued = true;
1713 * Sets the status of the web interface as online.
1715 function ajaxSuccess() {
1717 showOfflineMarker(!online || (initiallyLoggedIn && notLoggedIn));
1721 * Shows or hides the offline marker.
1724 * {@code true} to display the offline marker, {@code false} to hide
1727 function showOfflineMarker(visible) {
1728 /* jQuery documentation says toggle() works the other way around?! */
1729 $("#sone #offline-marker").toggle(visible);
1731 $("#sone #main").addClass("offline");
1733 $("#sone #main").removeClass("offline");
1738 // EVERYTHING BELOW HERE IS EXECUTED AFTER LOADING THE PAGE
1743 var initiallyLoggedIn = $("#sone #loggedIn").text() == "true";
1744 var notLoggedIn = !initiallyLoggedIn;
1746 $(document).ready(function() {
1748 /* this initializes the status update input field. */
1749 getTranslation("WebInterface.DefaultText.StatusUpdate", function(defaultText) {
1750 registerInputTextareaSwap("#sone #update-status .status-input", defaultText, "text", false, false);
1751 $("#sone #update-status .select-sender").css("display", "inline");
1752 $("#sone #update-status .sender").hide();
1753 $("#sone #update-status .select-sender button").click(function() {
1754 $("#sone #update-status .sender").show();
1755 $("#sone #update-status .select-sender").hide();
1758 $("#sone #update-status").submit(function() {
1759 button = $("button:submit", this);
1760 button.attr("disabled", "disabled");
1761 if ($(this).find(":input.default:enabled").length > 0) {
1764 sender = $(this).find(":input[name=sender]").val();
1765 text = $(this).find(":input[name=text]:enabled").val();
1766 ajaxGet("createPost.ajax", { "formPassword": getFormPassword(), "sender": sender, "text": text }, function(data, textStatus) {
1767 button.removeAttr("disabled");
1769 $(this).find(":input[name=sender]").val(getCurrentSoneId());
1770 $(this).find(":input[name=text]:enabled").val("").blur();
1771 $(this).find(".sender").hide();
1772 $(this).find(".select-sender").show();
1777 /* ajaxify the search input field. */
1778 getTranslation("WebInterface.DefaultText.Search", function(defaultText) {
1779 registerInputTextareaSwap("#sone #search input[name=query]", defaultText, "query", false, true);
1782 /* ajaxify input field on “view Sone” page. */
1783 getTranslation("WebInterface.DefaultText.Message", function(defaultText) {
1784 registerInputTextareaSwap("#sone #post-message input[name=text]", defaultText, "text", false, false);
1785 $("#sone #post-message .select-sender").css("display", "inline");
1786 $("#sone #post-message .sender").hide();
1787 $("#sone #post-message .select-sender button").click(function() {
1788 $("#sone #post-message .sender").show();
1789 $("#sone #post-message .select-sender").hide();
1792 $("#sone #post-message").submit(function() {
1793 sender = $(this).find(":input[name=sender]").val();
1794 text = $(this).find(":input[name=text]:enabled").val();
1795 ajaxGet("createPost.ajax", { "formPassword": getFormPassword(), "recipient": getShownSoneId(), "sender": sender, "text": text });
1796 $(this).find(":input[name=sender]").val(getCurrentSoneId());
1797 $(this).find(":input[name=text]:enabled").val("").blur();
1798 $(this).find(".sender").hide();
1799 $(this).find(".select-sender").show();
1804 /* Ajaxifies all posts. */
1805 /* calling getTranslation here will cache the necessary values. */
1806 getTranslation("WebInterface.Confirmation.DeletePostButton", function(text) {
1807 getTranslation("WebInterface.Confirmation.DeleteReplyButton", function(text) {
1808 getTranslation("WebInterface.DefaultText.Reply", function(text) {
1809 $("#sone .post").each(function() {
1816 /* update post times. */
1818 $("#sone .post").each(function() {
1819 postIds.push(getPostId(this));
1821 updatePostTimes(postIds.join(","));
1823 /* hides all replies but the latest two. */
1824 if (!isViewPostPage()) {
1825 getTranslation("WebInterface.ClickToShow.Replies", function(text) {
1826 $("#sone .post .replies").each(function() {
1827 allReplies = $(this).find(".reply");
1828 if (allReplies.length > 2) {
1830 for (replyIndex = 0; !newHidden && (replyIndex < (allReplies.length - 2)); ++replyIndex) {
1831 $(allReplies[replyIndex]).addClass("hidden");
1832 newHidden |= $(allReplies[replyIndex]).hasClass("new");
1834 clickToShowElement = $("<div></div>").addClass("click-to-show");
1836 clickToShowElement.addClass("new");
1838 (function(clickToShowElement, allReplies, text) {
1839 clickToShowElement.text(text);
1840 clickToShowElement.click(function() {
1841 allReplies.removeClass("hidden");
1842 clickToShowElement.addClass("hidden");
1844 })(clickToShowElement, allReplies, text);
1845 $(allReplies[0]).before(clickToShowElement);
1851 $("#sone .sone").each(function() {
1852 ajaxifySone($(this));
1855 /* process all existing notifications, ajaxify dismiss buttons. */
1856 $("#sone #notification-area .notification").each(function() {
1857 ajaxifyNotification($(this));
1860 /* disable all permalinks. */
1861 $(".permalink").click(function() {
1865 /* activate status polling. */
1866 setTimeout(getStatus, 5000);
1868 /* reset activity counter when the page has focus. */
1869 $(window).focus(function() {
1872 }).blur(function() {