/* Copyright (c) 2010, Diaspora Inc. This file is * licensed under the Affero General Public License version 3 or later. See * the COPYRIGHT file. */ var Stream = { selector: "#main_stream", initialize: function() { console.log(this); Diaspora.widgets.timeago.updateTimeAgo(); Diaspora.widgets.directionDetector.updateBinds(); $(".status_message_delete").tipsy({ trigger: "hover", gravity: "n" }); $("a.show_post_comments:not(.show)", this.selector).click(Stream.toggleComments); //audio links Stream.setUpAudioLinks(); //Stream.setUpImageLinks(); console.log(this, $(".focus_comment_textarea").length, $(".focus_comment_textarea", this.selector), this.selector); // comment link form focus $(".focus_comment_textarea", this.selector).click(function(evt) { Stream.focusNewComment($(this), evt); }); $("textarea.comment_box", this.selector).bind("focus blur", function(evt) { var commentBox = $(this); commentBox .attr("rows", (evt.type === "focus") ? 2 : 1) .parent().parent() .toggleClass("open"); }); $("a.expand_likes", this.selector).click(function(evt) { evt.preventDefault(); $(this).siblings(".likes_list").fadeToggle("fast"); }); $("a.expand_dislikes", this.selector).click(function(evt) { evt.preventDefault(); $(this).siblings(".dislikes_list").fadeToggle("fast"); }); // reshare button action $(".reshare_button", this.selector).click(function(evt) { evt.preventDefault(); var button = $(this), box = button.siblings(".reshare_box"); if (box.length > 0) { button.toggleClass("active"); box.toggle(); } }); $(".new_comment", this.selector).bind("ajax:failure", function() { Diaspora.widgets.alert.alert(Diaspora.widgets.i18n.t("failed_to_post_message")); }); $(".comment .comment_delete", this.selector).bind("ajax:success", function() { var element = $(this), target = element.parents(".comment"), post = element.closest(".stream_element"), toggler = post.find(".show_post_comments"); target.hide("blind", { direction: "vertical" }, 300, function() { $(this).remove(); toggler.html( toggler.html().replace(/\d+/, $(".comments li", post).length - 1) ); }); }); // collapse long comments $(".content p", this.selector).expander({ slicePoint: 400, widow: 12, expandText: Diaspora.widgets.i18n.t("show_more"), userCollapse: false }); }, setUpLikes: function() { var likes = $(".like_it, .dislike_it", this.selector); likes.bind("ajax:loading", function() { $(this).parent().fadeOut("fast"); }); likes.bind("ajax:failure", function() { Diaspora.widgets.alert.alert(Diaspora.widgets.i18n.t("failed_to_like")); $(this).parent().fadeIn("fast"); }); }, setUpAudioLinks: function() { $(".stream a[target='_blank']").each(function() { var link = $(this); if(this.href.match(/\.mp3$|\.ogg$/)) { $("