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 * Generates a list of Sones by concatening the names of the given sones with a
287 * new line character (“\n”).
290 * The sones to format
291 * @returns {String} The created string
293 function generateSoneList(sones) {
295 $.each(sones, function() {
296 if (soneList != "") {
299 soneList += this.name;
305 * Returns the ID of the Sone that this element belongs to.
308 * The element to locate the matching Sone ID for
309 * @returns The ID of the Sone, or undefined
311 function getSoneId(element) {
312 return getSoneElement(element).find(".id").text();
316 * Returns the element of the post with the given ID.
320 * @returns The element of the post
322 function getPost(postId) {
323 return $("#sone .post#" + postId);
326 function getPostElement(element) {
327 return $(element).closest(".post");
330 function getPostId(element) {
331 return getPostElement(element).attr("id");
334 function getPostTime(element) {
335 return getPostElement(element).find(".post-time").text();
339 * Returns the author of the post the given element belongs to.
342 * The element whose post to get the author for
343 * @returns The ID of the authoring Sone
345 function getPostAuthor(element) {
346 return getPostElement(element).find(".post-author").text();
350 * Returns the element of the reply with the given ID.
353 * The ID of the reply
354 * @returns The element of the reply
356 function getReply(replyId) {
357 return $("#sone .reply#" + replyId);
360 function getReplyElement(element) {
361 return $(element).closest(".reply");
364 function getReplyId(element) {
365 return getReplyElement(element).attr("id");
368 function getReplyTime(element) {
369 return getReplyElement(element).find(".reply-time").text();
373 * Returns the author of the reply the given element belongs to.
376 * The element whose reply to get the author for
377 * @returns The ID of the authoring Sone
379 function getReplyAuthor(element) {
380 return getReplyElement(element).find(".reply-author").text();
384 * Returns the notification with the given ID.
386 * @param notificationId
387 * The ID of the notification
388 * @returns The notification element
390 function getNotification(notificationId) {
391 return $("#sone #notification-area .notification#" + notificationId);
395 * Returns the notification element closest to the given element.
398 * The element to get the closest notification of
399 * @return The closest notification element
401 function getNotificationElement(element) {
402 return $(element).closest(".notification");
406 * Returns the ID of the notification element.
408 * @param notificationElement
409 * The notification element
410 * @returns The ID of the notification
412 function getNotificationId(notificationElement) {
413 return $(notificationElement).attr("id");
417 * Returns the time the notification was last updated.
419 * @param notificationElement
420 * The notification element
421 * @returns The last update time of the notification
423 function getNotificationLastUpdatedTime(notificationElement) {
424 return $(notificationElement).attr("lastUpdatedTime");
427 function likePost(postId) {
428 ajaxGet("like.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
429 if ((data == null) || !data.success) {
432 $("#sone .post#" + postId + " > .inner-part > .status-line .like").addClass("hidden");
433 $("#sone .post#" + postId + " > .inner-part > .status-line .unlike").removeClass("hidden");
434 updatePostLikes(postId);
435 }, function(xmlHttpRequest, textStatus, error) {
440 function unlikePost(postId) {
441 ajaxGet("unlike.ajax", { "type": "post", "post" : postId, "formPassword": getFormPassword() }, function(data, textStatus) {
442 if ((data == null) || !data.success) {
445 $("#sone .post#" + postId + " > .inner-part > .status-line .unlike").addClass("hidden");
446 $("#sone .post#" + postId + " > .inner-part > .status-line .like").removeClass("hidden");
447 updatePostLikes(postId);
448 }, function(xmlHttpRequest, textStatus, error) {
453 function updatePostLikes(postId) {
454 ajaxGet("getLikes.ajax", { "type": "post", "post": postId }, function(data, textStatus) {
455 if ((data != null) && data.success) {
456 $("#sone .post#" + postId + " > .inner-part > .status-line .likes").toggleClass("hidden", data.likes == 0);
457 $("#sone .post#" + postId + " > .inner-part > .status-line .likes span.like-count").text(data.likes);
458 $("#sone .post#" + postId + " > .inner-part > .status-line .likes > span").attr("title", generateSoneList(data.sones));
460 }, function(xmlHttpRequest, textStatus, error) {
465 function likeReply(replyId) {
466 ajaxGet("like.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
467 if ((data == null) || !data.success) {
470 $("#sone .reply#" + replyId + " .status-line .like").addClass("hidden");
471 $("#sone .reply#" + replyId + " .status-line .unlike").removeClass("hidden");
472 updateReplyLikes(replyId);
473 }, function(xmlHttpRequest, textStatus, error) {
478 function unlikeReply(replyId) {
479 ajaxGet("unlike.ajax", { "type": "reply", "reply" : replyId, "formPassword": getFormPassword() }, function(data, textStatus) {
480 if ((data == null) || !data.success) {
483 $("#sone .reply#" + replyId + " .status-line .unlike").addClass("hidden");
484 $("#sone .reply#" + replyId + " .status-line .like").removeClass("hidden");
485 updateReplyLikes(replyId);
486 }, function(xmlHttpRequest, textStatus, error) {
492 * Trusts the Sone with the given ID.
495 * The ID of the Sone to trust
497 function trustSone(soneId) {
498 ajaxGet("trustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data, textStatus) {
499 if ((data != null) && data.success) {
500 updateTrustControls(soneId, data.trustValue);
506 * Distrusts the Sone with the given ID, i.e. assigns a negative trust value.
509 * The ID of the Sone to distrust
511 function distrustSone(soneId) {
512 ajaxGet("distrustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data, textStatus) {
513 if ((data != null) && data.success) {
514 updateTrustControls(soneId, data.trustValue);
520 * Untrusts the Sone with the given ID, i.e. removes any trust assignment.
523 * The ID of the Sone to untrust
525 function untrustSone(soneId) {
526 ajaxGet("untrustSone.ajax", { "formPassword" : getFormPassword(), "sone" : soneId }, function(data, textStatus) {
527 if ((data != null) && data.success) {
528 updateTrustControls(soneId, data.trustValue);
534 * Updates the trust controls for all posts and replies of the given Sone,
535 * according to the given trust value.
538 * The ID of the Sone to update all trust controls for
540 * The trust value for the Sone
542 function updateTrustControls(soneId, trustValue) {
543 $("#sone .post").each(function() {
544 if (getPostAuthor(this) == soneId) {
545 getPostElement(this).find(".post-trust").toggleClass("hidden", trustValue != null);
546 getPostElement(this).find(".post-distrust").toggleClass("hidden", trustValue != null);
547 getPostElement(this).find(".post-untrust").toggleClass("hidden", trustValue == null);
550 $("#sone .reply").each(function() {
551 if (getReplyAuthor(this) == soneId) {
552 getReplyElement(this).find(".reply-trust").toggleClass("hidden", trustValue != null);
553 getReplyElement(this).find(".reply-distrust").toggleClass("hidden", trustValue != null);
554 getReplyElement(this).find(".reply-untrust").toggleClass("hidden", trustValue == null);
560 * Bookmarks the post with the given ID.
563 * The ID of the post to bookmark
565 function bookmarkPost(postId) {
567 ajaxGet("bookmark.ajax", {"formPassword": getFormPassword(), "type": "post", "post": postId}, function(data, textStatus) {
568 if ((data != null) && data.success) {
569 getPost(postId).find(".bookmark").toggleClass("hidden", true);
570 getPost(postId).find(".unbookmark").toggleClass("hidden", false);
577 * Unbookmarks the post with the given ID.
580 * The ID of the post to unbookmark
582 function unbookmarkPost(postId) {
583 ajaxGet("unbookmark.ajax", {"formPassword": getFormPassword(), "type": "post", "post": postId}, function(data, textStatus) {
584 if ((data != null) && data.success) {
585 getPost(postId).find(".bookmark").toggleClass("hidden", false);
586 getPost(postId).find(".unbookmark").toggleClass("hidden", true);
591 function updateReplyLikes(replyId) {
592 ajaxGet("getLikes.ajax", { "type": "reply", "reply": replyId }, function(data, textStatus) {
593 if ((data != null) && data.success) {
594 $("#sone .reply#" + replyId + " .status-line .likes").toggleClass("hidden", data.likes == 0);
595 $("#sone .reply#" + replyId + " .status-line .likes span.like-count").text(data.likes);
596 $("#sone .reply#" + replyId + " .status-line .likes > span").attr("title", generateSoneList(data.sones));
598 }, function(xmlHttpRequest, textStatus, error) {
604 * Posts a reply and calls the given callback when the request finishes.
607 * The ID of the sender
609 * The ID of the post the reply refers to
612 * @param callbackFunction
613 * The callback function to call when the request finishes (takes 3
614 * parameters: success, error, replyId)
616 function postReply(sender, postId, text, callbackFunction) {
617 ajaxGet("createReply.ajax", { "formPassword" : getFormPassword(), "sender": sender, "post" : postId, "text": text }, function(data, textStatus) {
619 /* TODO - show error */
623 callbackFunction(true, null, data.reply, data.sone);
625 callbackFunction(false, data.error);
627 }, function(xmlHttpRequest, textStatus, error) {
633 * Ajaxifies the given Sone by enhancing all eligible elements with AJAX.
636 * The Sone to ajaxify
638 function ajaxifySone(soneElement) {
640 * convert all “follow”, “unfollow”, “lock”, and “unlock” links to something
643 $(".follow", soneElement).submit(function() {
644 var followElement = this;
645 ajaxGet("followSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
646 $(followElement).addClass("hidden");
647 $(followElement).parent().find(".unfollow").removeClass("hidden");
651 $(".unfollow", soneElement).submit(function() {
652 var unfollowElement = this;
653 ajaxGet("unfollowSone.ajax", { "sone": getSoneId(this), "formPassword": getFormPassword() }, function() {
654 $(unfollowElement).addClass("hidden");
655 $(unfollowElement).parent().find(".follow").removeClass("hidden");
659 $(".lock", soneElement).submit(function() {
660 var lockElement = this;
661 ajaxGet("lockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
662 $(lockElement).addClass("hidden");
663 $(lockElement).parent().find(".unlock").removeClass("hidden");
667 $(".unlock", soneElement).submit(function() {
668 var unlockElement = this;
669 ajaxGet("unlockSone.ajax", { "sone" : getSoneId(this), "formPassword" : getFormPassword() }, function() {
670 $(unlockElement).addClass("hidden");
671 $(unlockElement).parent().find(".lock").removeClass("hidden");
676 /* mark Sone as known when clicking it. */
677 $(soneElement).click(function() {
678 markSoneAsKnown(this);
683 * Ajaxifies the given post by enhancing all eligible elements with AJAX.
686 * The post element to ajaxify
688 function ajaxifyPost(postElement) {
689 $(postElement).find("form").submit(function() {
692 $(postElement).find(".create-reply button:submit").click(function() {
694 button.attr("disabled", "disabled");
695 sender = $(this.form).find(":input[name=sender]").val();
696 inputField = $(this.form).find(":input[name=text]:enabled").get(0);
697 postId = getPostId(this);
698 text = $(inputField).val();
699 (function(sender, postId, text, inputField) {
700 postReply(sender, postId, text, function(success, error, replyId, soneId) {
702 $(inputField).val("");
703 loadNewReply(replyId, soneId, postId);
704 $("#sone .post#" + postId + " .create-reply").addClass("hidden");
705 $("#sone .post#" + postId + " .create-reply .sender").hide();
706 $("#sone .post#" + postId + " .create-reply .select-sender").show();
707 $("#sone .post#" + postId + " .create-reply :input[name=sender]").val(getCurrentSoneId());
711 button.removeAttr("disabled");
713 })(sender, postId, text, inputField);
717 /* replace all “delete” buttons with javascript. */
718 (function(postElement) {
719 getTranslation("WebInterface.Confirmation.DeletePostButton", function(deletePostText) {
720 postId = getPostId(postElement);
721 enhanceDeletePostButton($(postElement).find(".delete-post button"), postId, deletePostText);
725 /* convert all “like” buttons to javascript functions. */
726 $(postElement).find(".like-post").submit(function() {
727 likePost(getPostId(this));
730 $(postElement).find(".unlike-post").submit(function() {
731 unlikePost(getPostId(this));
735 /* convert trust control buttons to javascript functions. */
736 $(postElement).find(".post-trust").submit(function() {
737 trustSone(getPostAuthor(this));
740 $(postElement).find(".post-distrust").submit(function() {
741 distrustSone(getPostAuthor(this));
744 $(postElement).find(".post-untrust").submit(function() {
745 untrustSone(getPostAuthor(this));
749 /* convert bookmark/unbookmark buttons to javascript functions. */
750 $(postElement).find(".bookmark").submit(function() {
751 bookmarkPost(getPostId(this));
754 $(postElement).find(".unbookmark").submit(function() {
755 unbookmarkPost(getPostId(this));
759 /* convert “show source” link into javascript function. */
760 $(postElement).find(".show-source").each(function() {
761 $("a", this).click(function() {
762 post = getPostElement(this);
763 rawPostText = $(".post-text.raw-text", post);
764 rawPostText.toggleClass("hidden");
765 if (rawPostText.hasClass("hidden")) {
766 $(".post-text.short-text", post).removeClass("hidden");
767 $(".post-text.text", post).addClass("hidden");
768 $(".expand-post-text", post).removeClass("hidden");
769 $(".shrink-post-text", post).addClass("hidden");
771 $(".post-text.short-text", post).addClass("hidden");
772 $(".post-text.text", post).addClass("hidden");
773 $(".expand-post-text", post).addClass("hidden");
774 $(".shrink-post-text", post).addClass("hidden");
780 /* convert “show more” link into javascript function. */
781 $(postElement).find(".expand-post-text").each(function() {
782 $(this).click(function() {
783 $(".post-text.text", getPostElement(this)).toggleClass("hidden");
784 $(".post-text.short-text", getPostElement(this)).toggleClass("hidden");
785 $(".expand-post-text", getPostElement(this)).toggleClass("hidden");
786 $(".shrink-post-text", getPostElement(this)).toggleClass("hidden");
790 $(postElement).find(".shrink-post-text").each(function() {
791 $(this).click(function() {
792 $(".post-text.text", getPostElement(this)).toggleClass("hidden");
793 $(".post-text.short-text", getPostElement(this)).toggleClass("hidden");
794 $(".expand-post-text", getPostElement(this)).toggleClass("hidden");
795 $(".shrink-post-text", getPostElement(this)).toggleClass("hidden");
800 /* add “comment” link. */
801 addCommentLink(getPostId(postElement), getPostAuthor(postElement), postElement, $(postElement).find(".post-status-line .permalink-author"));
803 /* process all replies. */
805 $(postElement).find(".reply").each(function() {
806 replyIds.push(getReplyId(this));
809 updateReplyTimes(replyIds.join(","));
811 /* process reply input fields. */
812 getTranslation("WebInterface.DefaultText.Reply", function(text) {
813 $(postElement).find("input.reply-input").each(function() {
814 registerInputTextareaSwap(this, text, "text", false, false);
818 /* process sender selection. */
819 $(".select-sender", postElement).css("display", "inline");
820 $(".sender", postElement).hide();
821 $(".select-sender button", postElement).click(function() {
822 $(".sender", postElement).show();
823 $(".select-sender", postElement).hide();
827 /* mark everything as known on click. */
828 $(postElement).click(function(event) {
829 if ($(event.target).hasClass("click-to-show")) {
832 markPostAsKnown(this);
835 /* hide reply input field. */
836 $(postElement).find(".create-reply").addClass("hidden");
840 * Ajaxifies the given reply element.
842 * @param replyElement
843 * The reply element to ajaxify
845 function ajaxifyReply(replyElement) {
846 $(replyElement).find(".like-reply").submit(function() {
847 likeReply(getReplyId(this));
850 $(replyElement).find(".unlike-reply").submit(function() {
851 unlikeReply(getReplyId(this));
854 (function(replyElement) {
855 getTranslation("WebInterface.Confirmation.DeleteReplyButton", function(deleteReplyText) {
856 $(replyElement).find(".delete-reply button").each(function() {
857 enhanceDeleteReplyButton(this, getReplyId(replyElement), deleteReplyText);
861 addCommentLink(getPostId(replyElement), getReplyAuthor(replyElement), replyElement, $(replyElement).find(".reply-status-line .permalink-author"));
863 /* convert “show source” link into javascript function. */
864 $(replyElement).find(".show-reply-source").each(function() {
865 $("a", this).click(function() {
866 reply = getReplyElement(this);
867 rawReplyText = $(".reply-text.raw-text", reply);
868 rawReplyText.toggleClass("hidden");
869 if (rawReplyText.hasClass("hidden")) {
870 $(".reply-text.short-text", reply).removeClass("hidden");
871 $(".reply-text.text", reply).addClass("hidden");
872 $(".expand-reply-text", reply).removeClass("hidden");
873 $(".shrink-reply-text", reply).addClass("hidden");
875 $(".reply-text.short-text", reply).addClass("hidden");
876 $(".reply-text.text", reply).addClass("hidden");
877 $(".expand-reply-text", reply).addClass("hidden");
878 $(".shrink-reply-text", reply).addClass("hidden");
884 /* convert “show more” link into javascript function. */
885 $(replyElement).find(".expand-reply-text").each(function() {
886 $(this).click(function() {
887 $(".reply-text.text", getReplyElement(this)).toggleClass("hidden");
888 $(".reply-text.short-text", getReplyElement(this)).toggleClass("hidden");
889 $(".expand-reply-text", getReplyElement(this)).toggleClass("hidden");
890 $(".shrink-reply-text", getReplyElement(this)).toggleClass("hidden");
894 $(replyElement).find(".shrink-reply-text").each(function() {
895 $(this).click(function() {
896 $(".reply-text.text", getReplyElement(this)).toggleClass("hidden");
897 $(".reply-text.short-text", getReplyElement(this)).toggleClass("hidden");
898 $(".expand-reply-text", getReplyElement(this)).toggleClass("hidden");
899 $(".shrink-reply-text", getReplyElement(this)).toggleClass("hidden");
904 /* convert trust control buttons to javascript functions. */
905 $(replyElement).find(".reply-trust").submit(function() {
906 trustSone(getReplyAuthor(this));
909 $(replyElement).find(".reply-distrust").submit(function() {
910 distrustSone(getReplyAuthor(this));
913 $(replyElement).find(".reply-untrust").submit(function() {
914 untrustSone(getReplyAuthor(this));
920 * Ajaxifies the given notification by replacing the form with AJAX.
922 * @param notification
923 * jQuery object representing the notification.
925 function ajaxifyNotification(notification) {
926 notification.find("form").submit(function() {
929 notification.find("input[name=returnPage]").val($.url.attr("relative"));
930 if (notification.find(".short-text").length > 0) {
931 notification.find(".short-text").removeClass("hidden");
932 notification.find(".text").addClass("hidden");
934 notification.find("form.mark-as-read button").click(function() {
935 allIds = $(":input[name=id]", this.form).val().split(" ");
936 for (index = 0; index < allIds.length; index += 16) {
937 ids = allIds.slice(index, index + 16).join(" ");
938 ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": $(":input[name=type]", this.form).val(), "id": ids});
941 notification.find("a[class^='link-']").each(function() {
942 linkElement = $(this);
943 if (linkElement.is("[href^='viewPost']")) {
944 id = linkElement.attr("class").substr(5);
946 linkElement.attr("href", "#post-" + id).addClass("in-page-link");
950 notification.find("form.dismiss button").click(function() {
951 ajaxGet("dismissNotification.ajax", { "formPassword" : getFormPassword(), "notification" : notification.attr("id") }, function(data, textStatus) {
952 /* dismiss in case of error, too. */
953 notification.slideUp();
954 }, function(xmlHttpRequest, textStatus, error) {
962 * Retrieves element IDs from notification elements.
964 * @param notification
965 * The notification element
967 * The selector of the element containing the ID as text
968 * @returns All extracted IDs
970 function getElementIds(notification, selector) {
972 $(selector, notification).each(function() {
973 elementIds.push($(this).text());
979 * Compares the given notification elements and calls {@link #markSoneAsKnown()}
980 * for every ID that is contained in the old notification but not in the new.
982 * @param oldNotification
983 * The old notification element
984 * @param newNotification
985 * The new notification element
987 function checkForRemovedSones(oldNotification, newNotification) {
988 if (getNotificationId(oldNotification) != "new-sone-notification") {
991 oldIds = getElementIds(oldNotification, ".new-sone-id");
992 newIds = getElementIds(newNotification, ".new-sone-id");
993 $.each(oldIds, function(index, value) {
994 if ($.inArray(value, newIds) == -1) {
995 markSoneAsKnown(getSone(value), true);
1001 * Compares the given notification elements and calls {@link #markPostAsKnown()}
1002 * for every ID that is contained in the old notification but not in the new.
1004 * @param oldNotification
1005 * The old notification element
1006 * @param newNotification
1007 * The new notification element
1009 function checkForRemovedPosts(oldNotification, newNotification) {
1010 if (getNotificationId(oldNotification) != "new-post-notification") {
1013 oldIds = getElementIds(oldNotification, ".post-id");
1014 newIds = getElementIds(newNotification, ".post-id");
1015 $.each(oldIds, function(index, value) {
1016 if ($.inArray(value, newIds) == -1) {
1017 markPostAsKnown(getPost(value), true);
1023 * Compares the given notification elements and calls
1024 * {@link #markReplyAsKnown()} for every ID that is contained in the old
1025 * notification but not in the new.
1027 * @param oldNotification
1028 * The old notification element
1029 * @param newNotification
1030 * The new notification element
1032 function checkForRemovedReplies(oldNotification, newNotification) {
1033 if (getNotificationId(oldNotification) != "new-replies-notification") {
1036 oldIds = getElementIds(oldNotification, ".reply-id");
1037 newIds = getElementIds(newNotification, ".reply-id");
1038 $.each(oldIds, function(index, value) {
1039 if ($.inArray(value, newIds) == -1) {
1040 markReplyAsKnown(getReply(value), true);
1045 function getStatus() {
1046 ajaxGet("getStatus.ajax", isViewSonePage() ? {"soneIds": getShownSoneId() } : {"loadAllSones": isKnownSonesPage()}, function(data, textStatus) {
1047 if ((data != null) && data.success) {
1048 /* process Sone information. */
1049 $.each(data.sones, function(index, value) {
1050 updateSoneStatus(value.id, value.name, value.status, value.modified, value.locked, value.lastUpdatedUnknown ? null : value.lastUpdated, value.lastUpdatedText);
1052 notLoggedIn = !data.loggedIn;
1054 showOfflineMarker(!online);
1056 /* search for removed notifications. */
1057 $("#sone #notification-area .notification").each(function() {
1058 notificationId = $(this).attr("id");
1059 foundNotification = false;
1060 $.each(data.notifications, function(index, value) {
1061 if (value.id == notificationId) {
1062 foundNotification = true;
1066 if (!foundNotification) {
1067 if (notificationId == "new-sone-notification") {
1068 $(".new-sone-id", this).each(function(index, element) {
1069 soneId = $(this).text();
1070 markSoneAsKnown(getSone(soneId), true);
1072 } else if (notificationId == "new-post-notification") {
1073 $(".post-id", this).each(function(index, element) {
1074 postId = $(this).text();
1075 markPostAsKnown(getPost(postId), true);
1077 } else if (notificationId == "new-replies-notification") {
1078 $(".reply-id", this).each(function(index, element) {
1079 replyId = $(this).text();
1080 markReplyAsKnown(getReply(replyId), true);
1083 $(this).slideUp("normal", function() {
1085 /* remove activity when no notifications are visible. */
1086 if ($("#sone #notification-area .notification").length == 0) {
1092 /* process notifications. */
1093 notificationIds = [];
1094 $.each(data.notifications, function(index, value) {
1095 oldNotification = getNotification(value.id);
1096 if ((oldNotification.length == 0) || (value.lastUpdatedTime > getNotificationLastUpdatedTime(oldNotification))) {
1097 notificationIds.push(value.id);
1100 if (notificationIds.length > 0) {
1101 loadNotifications(notificationIds);
1103 /* process new posts. */
1104 $.each(data.newPosts, function(index, value) {
1105 loadNewPost(value.id, value.sone, value.recipient, value.time);
1107 /* process new replies. */
1108 $.each(data.newReplies, function(index, value) {
1109 loadNewReply(value.id, value.sone, value.post, value.postSone);
1111 /* do it again in 5 seconds. */
1112 setTimeout(getStatus, 5000);
1114 /* data.success was false, wait 30 seconds. */
1115 setTimeout(getStatus, 30000);
1118 statusRequestQueued = false;
1124 * Requests multiple notifications from Sone and displays them.
1126 * @param notificationIds
1127 * Array of IDs of the notifications to load
1129 function loadNotifications(notificationIds) {
1130 ajaxGet("getNotification.ajax", {"notifications": notificationIds.join(",")}, function(data, textStatus) {
1131 if (!data || !data.success) {
1132 // TODO - show error
1135 $.each(data.notifications, function(index, value) {
1136 oldNotification = getNotification(value.id);
1137 notification = ajaxifyNotification(createNotification(value.id, value.lastUpdatedTime, value.text, value.dismissable)).hide();
1138 if (oldNotification.length != 0) {
1139 if ((oldNotification.find(".short-text").length > 0) && (notification.find(".short-text").length > 0)) {
1140 opened = oldNotification.is(":visible") && oldNotification.find(".short-text").hasClass("hidden");
1141 notification.find(".short-text").toggleClass("hidden", opened);
1142 notification.find(".text").toggleClass("hidden", !opened);
1144 checkForRemovedSones(oldNotification, notification);
1145 checkForRemovedPosts(oldNotification, notification);
1146 checkForRemovedReplies(oldNotification, notification);
1147 oldNotification.replaceWith(notification.show());
1149 $("#sone #notification-area").append(notification);
1150 if (value.id.substring(0, 5) != "local") {
1151 notification.slideDown();
1160 * Returns the ID of the currently logged in Sone.
1162 * @return The ID of the current Sone, or an empty string if no Sone is logged
1165 function getCurrentSoneId() {
1166 return $("#currentSoneId").text();
1170 * Returns the content of the page-id attribute.
1172 * @returns The page ID
1174 function getPageId() {
1175 return $("#sone .page-id").text();
1179 * Returns whether the current page is the index page.
1181 * @returns {Boolean} <code>true</code> if the current page is the index page,
1182 * <code>false</code> otherwise
1184 function isIndexPage() {
1185 return getPageId() == "index";
1189 * Returns the current page of the selected pagination. If no pagination can be
1190 * found with the given selector, {@code 1} is returned.
1192 * @param paginationSelector
1193 * The pagination selector
1194 * @returns The current page of the pagination
1196 function getPage(paginationSelector) {
1197 pagination = $(paginationSelector);
1198 if (pagination.length > 0) {
1199 return $(".current-page", paginationSelector).text();
1205 * Returns whether the current page is a “view Sone” page.
1207 * @returns {Boolean} <code>true</code> if the current page is a “view Sone”
1208 * page, <code>false</code> otherwise
1210 function isViewSonePage() {
1211 return getPageId() == "view-sone";
1215 * Returns the ID of the currently shown Sone. This will only return a sensible
1216 * value if isViewSonePage() returns <code>true</code>.
1218 * @returns The ID of the currently shown Sone
1220 function getShownSoneId() {
1221 return $("#sone .sone-id").text();
1225 * Returns whether the current page is a “view post” page.
1227 * @returns {Boolean} <code>true</code> if the current page is a “view post”
1228 * page, <code>false</code> otherwise
1230 function isViewPostPage() {
1231 return getPageId() == "view-post";
1235 * Returns the ID of the currently shown post. This will only return a sensible
1236 * value if isViewPostPage() returns <code>true</code>.
1238 * @returns The ID of the currently shown post
1240 function getShownPostId() {
1241 return $("#sone .post-id").text();
1245 * Returns whether the current page is the “known Sones” page.
1247 * @returns {Boolean} <code>true</code> if the current page is the “known
1248 * Sones” page, <code>false</code> otherwise
1250 function isKnownSonesPage() {
1251 return getPageId() == "known-sones";
1255 * Returns whether a post with the given ID exists on the current page.
1258 * The post ID to check for
1259 * @returns {Boolean} <code>true</code> if a post with the given ID already
1260 * exists on the page, <code>false</code> otherwise
1262 function hasPost(postId) {
1263 return $(".post#" + postId).length > 0;
1267 * Returns whether a reply with the given ID exists on the current page.
1270 * The reply ID to check for
1271 * @returns {Boolean} <code>true</code> if a reply with the given ID already
1272 * exists on the page, <code>false</code> otherwise
1274 function hasReply(replyId) {
1275 return $("#sone .reply#" + replyId).length > 0;
1278 function loadNewPost(postId, soneId, recipientId, time) {
1279 if (hasPost(postId)) {
1282 if (!isIndexPage() || (getPage(".pagination-index") > 1)) {
1283 if (!isViewPostPage() || (getShownPostId() != postId)) {
1284 if (!isViewSonePage() || ((getShownSoneId() != soneId) && (getShownSoneId() != recipientId)) || (getPage(".post-navigation") > 1)) {
1289 if (getPostTime($("#sone .post").last()) > time) {
1292 ajaxGet("getPost.ajax", { "post" : postId }, function(data, textStatus) {
1293 if ((data != null) && data.success) {
1294 if (hasPost(data.post.id)) {
1297 if ((!isIndexPage() || (getPage(".pagination-index") > 1)) && !(isViewSonePage() && ((getShownSoneId() == data.post.sone) || (getShownSoneId() == data.post.recipient) || (getPage(".post-navigation") > 1)))) {
1300 var firstOlderPost = null;
1301 $("#sone .post").each(function() {
1302 if (getPostTime(this) < data.post.time) {
1303 firstOlderPost = $(this);
1307 newPost = $(data.post.html).addClass("hidden");
1308 if ($(".post-author-local", newPost).text() == "true") {
1309 newPost.removeClass("new");
1311 if (firstOlderPost != null) {
1312 newPost.insertBefore(firstOlderPost);
1314 ajaxifyPost(newPost);
1315 updatePostTimes(data.post.id);
1316 newPost.slideDown();
1322 function loadNewReply(replyId, soneId, postId, postSoneId) {
1323 if (hasReply(replyId)) {
1326 if (!hasPost(postId)) {
1329 ajaxGet("getReply.ajax", { "reply": replyId }, function(data, textStatus) {
1331 if ((data != null) && data.success) {
1332 if (hasReply(data.reply.id)) {
1335 $("#sone .post#" + data.reply.postId).each(function() {
1336 var firstNewerReply = null;
1337 $(this).find(".replies .reply").each(function() {
1338 if (getReplyTime(this) > data.reply.time) {
1339 firstNewerReply = $(this);
1343 newReply = $(data.reply.html).addClass("hidden");
1344 if ($(".reply-author-local", newReply).text() == "true") {
1345 newReply.removeClass("new");
1346 (function(newReply) {
1347 setTimeout(function() {
1348 markReplyAsKnown(newReply, false);
1352 if (firstNewerReply != null) {
1353 newReply.insertBefore(firstNewerReply);
1355 if ($(this).find(".replies .create-reply")) {
1356 $(this).find(".replies .create-reply").before(newReply);
1358 $(this).find(".replies").append(newReply);
1361 ajaxifyReply(newReply);
1362 updateReplyTimes(data.reply.id);
1363 newReply.slideDown();
1372 * Marks the given Sone as known if it is still new.
1374 * @param soneElement
1375 * The Sone to mark as known
1376 * @param skipRequest
1377 * true to skip the JSON request, false or omit to perform the JSON
1380 function markSoneAsKnown(soneElement, skipRequest) {
1381 if ($(soneElement).is(".new")) {
1382 $(soneElement).removeClass("new");
1383 if ((typeof skipRequest == "undefined") || !skipRequest) {
1384 ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "sone", "id": getSoneId(soneElement)});
1389 function markPostAsKnown(postElements, skipRequest) {
1390 $(postElements).each(function() {
1392 if ($(postElement).hasClass("new") || ((typeof skipRequest != "undefined") && !skipRequest)) {
1393 (function(postElement) {
1394 $(postElement).removeClass("new");
1395 if ((typeof skipRequest == "undefined") || !skipRequest) {
1396 ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "post", "id": getPostId(postElement)});
1400 $(".click-to-show", postElement).removeClass("new");
1402 markReplyAsKnown($(postElements).find(".reply"));
1405 function markReplyAsKnown(replyElements, skipRequest) {
1406 $(replyElements).each(function() {
1407 replyElement = this;
1408 if ($(replyElement).hasClass("new") || ((typeof skipRequest != "undefined") && !skipRequest)) {
1409 (function(replyElement) {
1410 $(replyElement).removeClass("new");
1411 if ((typeof skipRequest == "undefined") || !skipRequest) {
1412 ajaxGet("markAsKnown.ajax", {"formPassword": getFormPassword(), "type": "reply", "id": getReplyId(replyElement)});
1420 * Updates the time of the post with the given ID.
1423 * The ID of the post to update
1425 * The text of the time to show
1426 * @param refreshTime
1427 * The refresh time after which to request a new time (in seconds)
1429 * The tooltip to show
1431 function updatePostTime(postId, timeText, refreshTime, tooltip) {
1432 if (!getPost(postId).is(":visible")) {
1435 getPost(postId).find(".post-status-line > .time a").html(timeText).attr("title", tooltip);
1436 (function(postId, refreshTime) {
1437 setTimeout(function() {
1438 updatePostTimes(postId);
1439 }, refreshTime * 1000);
1440 })(postId, refreshTime);
1444 * Requests new rendered times for the posts with the given IDs.
1447 * Comma-separated post IDs
1449 function updatePostTimes(postIds) {
1450 ajaxGet("getTimes.ajax", { "posts" : postIds }, function(data, textStatus) {
1451 if ((data != null) && data.success) {
1452 $.each(data.postTimes, function(index, value) {
1453 updatePostTime(index, value.timeText, value.refreshTime, value.tooltip);
1460 * Updates the time of the reply with the given ID.
1463 * The ID of the reply to update
1465 * The text of the time to show
1466 * @param refreshTime
1467 * The refresh time after which to request a new time (in seconds)
1469 * The tooltip to show
1471 function updateReplyTime(replyId, timeText, refreshTime, tooltip) {
1472 getReply(replyId).find(".reply-status-line > .time").html(timeText).attr("title", tooltip);
1473 (function(replyId, refreshTime) {
1474 setTimeout(function() {
1475 updateReplyTimes(replyId);
1476 }, refreshTime * 1000);
1477 })(replyId, refreshTime);
1481 * Requests new rendered times for the posts with the given IDs.
1484 * Comma-separated post IDs
1486 function updateReplyTimes(replyIds) {
1487 ajaxGet("getTimes.ajax", { "replies" : replyIds }, function(data, textStatus) {
1488 if ((data != null) && data.success) {
1489 $.each(data.replyTimes, function(index, value) {
1490 updateReplyTime(index, value.timeText, value.refreshTime, value.tooltip);
1496 function resetActivity() {
1497 title = document.title;
1498 if (title.indexOf('(') == 0) {
1499 setTitle(title.substr(title.indexOf(' ') + 1));
1501 iconBlinking = false;
1504 function setActivity() {
1506 title = document.title;
1507 if (title.indexOf('(') != 0) {
1508 setTitle("(!) " + title);
1510 if (!iconBlinking) {
1511 setTimeout(toggleIcon, 1500);
1512 iconBlinking = true;
1518 * Sets the window title after a small delay to prevent race-condition issues.
1523 function setTitle(title) {
1524 setTimeout(function() {
1525 document.title = title;
1529 /** Whether the icon is currently showing activity. */
1530 var iconActive = false;
1532 /** Whether the icon is currently supposed to blink. */
1533 var iconBlinking = false;
1536 * Toggles the icon. If the window has gained focus and the icon is still
1537 * showing the activity state, it is returned to normal.
1539 function toggleIcon() {
1540 if (focus || !iconBlinking) {
1542 changeIcon("images/icon.png");
1545 iconBlinking = false;
1547 iconActive = !iconActive;
1548 changeIcon(iconActive ? "images/icon-activity.png" : "images/icon.png");
1549 setTimeout(toggleIcon, 1500);
1554 * Changes the icon of the page.
1557 * The new URL of the icon
1559 function changeIcon(iconUrl) {
1560 $("link[rel=icon]").remove();
1561 $("head").append($("<link>").attr("rel", "icon").attr("type", "image/png").attr("href", iconUrl));
1562 $("iframe[id=icon-update]")[0].src += "";
1566 * Creates a new notification.
1569 * The ID of the notificaiton
1571 * The text of the notification
1572 * @param dismissable
1573 * <code>true</code> if the notification can be dismissed by the
1576 function createNotification(id, lastUpdatedTime, text, dismissable) {
1577 notification = $("<div></div>").addClass("notification").attr("id", id).attr("lastUpdatedTime", lastUpdatedTime);
1579 dismissForm = $("#sone #notification-area #notification-dismiss-template").clone().removeClass("hidden").removeAttr("id");
1580 dismissForm.find("input[name=notification]").val(id);
1581 notification.append(dismissForm);
1583 notification.append(text);
1584 return notification;
1588 * Shows the details of the notification with the given ID.
1590 * @param notificationId
1591 * The ID of the notification
1593 function showNotificationDetails(notificationId) {
1594 $("#sone .notification#" + notificationId + " .text").removeClass("hidden");
1595 $("#sone .notification#" + notificationId + " .short-text").addClass("hidden");
1599 * Deletes the field with the given ID from the profile.
1602 * The ID of the field to delete
1604 function deleteProfileField(fieldId) {
1605 ajaxGet("deleteProfileField.ajax", {"formPassword": getFormPassword(), "field": fieldId}, function(data, textStatus) {
1606 if (data && data.success) {
1607 $("#sone .profile-field#" + data.field.id).slideUp();
1613 * Renames a profile field.
1616 * The ID of the field to rename
1618 * The new name of the field
1619 * @param successFunction
1620 * Called when the renaming was successful
1622 function editProfileField(fieldId, newName, successFunction) {
1623 ajaxGet("editProfileField.ajax", {"formPassword": getFormPassword(), "field": fieldId, "name": newName}, function(data, textStatus) {
1624 if (data && data.success) {
1631 * Moves the profile field with the given ID one slot in the given direction.
1634 * The ID of the field to move
1636 * The direction to move in (“up” or “down”)
1637 * @param successFunction
1638 * Function to call on success
1640 function moveProfileField(fieldId, direction, successFunction) {
1641 ajaxGet("moveProfileField.ajax", {"formPassword": getFormPassword(), "field": fieldId, "direction": direction}, function(data, textStatus) {
1642 if (data && data.success) {
1649 * Moves the profile field with the given ID up one slot.
1652 * The ID of the field to move
1653 * @param successFunction
1654 * Function to call on success
1656 function moveProfileFieldUp(fieldId, successFunction) {
1657 moveProfileField(fieldId, "up", successFunction);
1661 * Moves the profile field with the given ID down one slot.
1664 * The ID of the field to move
1665 * @param successFunction
1666 * Function to call on success
1668 function moveProfileFieldDown(fieldId, successFunction) {
1669 moveProfileField(fieldId, "down", successFunction);
1672 var statusRequestQueued = true;
1675 * Sets the status of the web interface as offline.
1677 function ajaxError() {
1679 showOfflineMarker(true);
1680 if (!statusRequestQueued) {
1681 setTimeout(getStatus, 5000);
1682 statusRequestQueued = true;
1687 * Sets the status of the web interface as online.
1689 function ajaxSuccess() {
1691 showOfflineMarker(!online || (initiallyLoggedIn && notLoggedIn));
1695 * Shows or hides the offline marker.
1698 * {@code true} to display the offline marker, {@code false} to hide
1701 function showOfflineMarker(visible) {
1702 /* jQuery documentation says toggle() works the other way around?! */
1703 $("#sone #offline-marker").toggle(visible);
1705 $("#sone #main").addClass("offline");
1707 $("#sone #main").removeClass("offline");
1712 // EVERYTHING BELOW HERE IS EXECUTED AFTER LOADING THE PAGE
1717 var initiallyLoggedIn = $("#sone #loggedIn").text() == "true";
1718 var notLoggedIn = !initiallyLoggedIn;
1720 $(document).ready(function() {
1722 /* this initializes the status update input field. */
1723 getTranslation("WebInterface.DefaultText.StatusUpdate", function(defaultText) {
1724 registerInputTextareaSwap("#sone #update-status .status-input", defaultText, "text", false, false);
1725 $("#sone #update-status .select-sender").css("display", "inline");
1726 $("#sone #update-status .sender").hide();
1727 $("#sone #update-status .select-sender button").click(function() {
1728 $("#sone #update-status .sender").show();
1729 $("#sone #update-status .select-sender").hide();
1732 $("#sone #update-status").submit(function() {
1733 button = $("button:submit", this);
1734 button.attr("disabled", "disabled");
1735 if ($(this).find(":input.default:enabled").length > 0) {
1738 sender = $(this).find(":input[name=sender]").val();
1739 text = $(this).find(":input[name=text]:enabled").val();
1740 ajaxGet("createPost.ajax", { "formPassword": getFormPassword(), "sender": sender, "text": text }, function(data, textStatus) {
1741 button.removeAttr("disabled");
1743 $(this).find(":input[name=sender]").val(getCurrentSoneId());
1744 $(this).find(":input[name=text]:enabled").val("").blur();
1745 $(this).find(".sender").hide();
1746 $(this).find(".select-sender").show();
1751 /* ajaxify the search input field. */
1752 getTranslation("WebInterface.DefaultText.Search", function(defaultText) {
1753 registerInputTextareaSwap("#sone #search input[name=query]", defaultText, "query", false, true);
1756 /* ajaxify input field on “view Sone” page. */
1757 getTranslation("WebInterface.DefaultText.Message", function(defaultText) {
1758 registerInputTextareaSwap("#sone #post-message input[name=text]", defaultText, "text", false, false);
1759 $("#sone #post-message .select-sender").css("display", "inline");
1760 $("#sone #post-message .sender").hide();
1761 $("#sone #post-message .select-sender button").click(function() {
1762 $("#sone #post-message .sender").show();
1763 $("#sone #post-message .select-sender").hide();
1766 $("#sone #post-message").submit(function() {
1767 sender = $(this).find(":input[name=sender]").val();
1768 text = $(this).find(":input[name=text]:enabled").val();
1769 ajaxGet("createPost.ajax", { "formPassword": getFormPassword(), "recipient": getShownSoneId(), "sender": sender, "text": text });
1770 $(this).find(":input[name=sender]").val(getCurrentSoneId());
1771 $(this).find(":input[name=text]:enabled").val("").blur();
1772 $(this).find(".sender").hide();
1773 $(this).find(".select-sender").show();
1778 /* Ajaxifies all posts. */
1779 /* calling getTranslation here will cache the necessary values. */
1780 getTranslation("WebInterface.Confirmation.DeletePostButton", function(text) {
1781 getTranslation("WebInterface.Confirmation.DeleteReplyButton", function(text) {
1782 getTranslation("WebInterface.DefaultText.Reply", function(text) {
1783 $("#sone .post").each(function() {
1790 /* update post times. */
1792 $("#sone .post").each(function() {
1793 postIds.push(getPostId(this));
1795 updatePostTimes(postIds.join(","));
1797 /* hides all replies but the latest two. */
1798 if (!isViewPostPage()) {
1799 getTranslation("WebInterface.ClickToShow.Replies", function(text) {
1800 $("#sone .post .replies").each(function() {
1801 allReplies = $(this).find(".reply");
1802 if (allReplies.length > 2) {
1804 for (replyIndex = 0; !newHidden && (replyIndex < (allReplies.length - 2)); ++replyIndex) {
1805 $(allReplies[replyIndex]).addClass("hidden");
1806 newHidden |= $(allReplies[replyIndex]).hasClass("new");
1808 clickToShowElement = $("<div></div>").addClass("click-to-show");
1810 clickToShowElement.addClass("new");
1812 (function(clickToShowElement, allReplies, text) {
1813 clickToShowElement.text(text);
1814 clickToShowElement.click(function() {
1815 allReplies.removeClass("hidden");
1816 clickToShowElement.addClass("hidden");
1818 })(clickToShowElement, allReplies, text);
1819 $(allReplies[0]).before(clickToShowElement);
1825 $("#sone .sone").each(function() {
1826 ajaxifySone($(this));
1829 /* process all existing notifications, ajaxify dismiss buttons. */
1830 $("#sone #notification-area .notification").each(function() {
1831 ajaxifyNotification($(this));
1834 /* disable all permalinks. */
1835 $(".permalink").click(function() {
1839 /* activate status polling. */
1840 setTimeout(getStatus, 5000);
1842 /* reset activity counter when the page has focus. */
1843 $(window).focus(function() {
1846 }).blur(function() {