/* 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 = {
initialize: function() {
var $stream = $(".stream");
var $publisher = $("#publisher");
$stream.not(".show").delegate("a.show_post_comments", "click", Stream.toggleComments);
// publisher textarea reset
$publisher.find("textarea").bind("blur", function() {
$(this).css('height','42px');
});
// comment link form focus
$stream.delegate(".focus_comment_textarea", "click", function(e){
Stream.focusNewComment($(this), e);
});
// comment submit action
$stream.delegate("textarea.comment_box", "keydown", function(e){
if (e.keyCode === 13) {
if(!e.shiftKey) {
$(this).blur();
$(this).closest("form").submit();
}
}
});
$stream.delegate("textarea.comment_box", "focus", function(evt) {
var commentBox = $(this);
commentBox
.attr('rows',2)
.addClass('force_open')
.closest("li").find(".submit_instructions").removeClass('hidden');
});
$stream.delegate("textarea.comment_box", "blur", function(evt) {
var commentBox = $(this);
if (!commentBox.val()) {
commentBox
.attr('rows',1)
.removeClass('force_open')
.css('height','1.4em')
.closest("li").find(".submit_instructions").addClass('hidden');
}
});
// reshare button action
$stream.delegate(".reshare_button", "click", function(evt) {
evt.preventDefault();
button = $(this)
box = button.siblings(".reshare_box");
if (box.length > 0) {
button.toggleClass("active");
box.toggle();
}
});
$stream.delegate("a.video-link", "click", function(evt) {
evt.preventDefault();
var $this = $(this),
container = document.createElement("div"),
$container = $(container).attr("class", "video-container"),
$videoContainer = $this.parent().siblings("div.video-container");
if ($videoContainer.length > 0) {
$videoContainer.slideUp('fast', function() {
$videoContainer.detach();
});
return;
}
if ($("div.video-container").length > 0) {
$("div.video-container").slideUp("fast", function() {
$(this).detach();
});
}
if ($this.data("host") === "youtube.com") {
$container.html(
'Watch this video on Youtube
' +
''
);
} else if($this.data("host") === "vimeo.com"){
$container.html(
'