Skip to content
Extraits de code Groupes Projets
stream.js 4,34 ko
Newer Older
  • Learn to ignore specific revisions
  • Raphael's avatar
    Raphael a validé
    /*   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");
    
    Dan Hansen's avatar
    Dan Hansen a validé
        var $publisher = $("#publisher");
    
        Diaspora.widgets.timeago.updateTimeAgo();
    
        $stream.not(".show").delegate("a.show_post_comments", "click", Stream.toggleComments);
    
        // comment link form focus
        $stream.delegate(".focus_comment_textarea", "click", function(e){
          Stream.focusNewComment($(this), e);
        });
    
        $stream.delegate("textarea.comment_box", "focus", function(evt) {
          var commentBox = $(this);
    
    danielvincent's avatar
    danielvincent a validé
          commentBox
    
            .parent().parent()
              .addClass('open');
    
        });
    
        $stream.delegate("textarea.comment_box", "blur", function(evt) {
          var commentBox = $(this);
          if (!commentBox.val()) {
    
    danielvincent's avatar
    danielvincent a validé
            commentBox
    
              .parent().parent()
                .removeClass('open');
    
        // fade in controls
        $stream.delegate(".stream_element", "mouseenter", function(evt) {
    
          var controls = $(this).find('.controls'),
              badges = $(this).find('.aspect_badges');
    
          controls.fadeIn(100);
    
          badges.fadeTo(100,1);
    
        });
        $stream.delegate(".stream_element", "mouseleave", function(evt) {
    
          var controls = $(this).find('.controls'),
              badges = $(this).find('.aspect_badges');
    
    
                  .fadeOut(50);
          badges.fadeTo(50,0.5);
    
        // 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();
          }
        });
    
    
        $(".new_status_message").live('ajax:loading', function(data, json, xhr) {
    
          $("#photodropzone").find('li').remove();
          $("#publisher textarea").removeClass("with_attachments");
        });
    
    
        $(".new_status_message").live('ajax:success', function(data, json, xhr) {
    
    lfortin's avatar
    lfortin a validé
          WebSocketReceiver.addPostToStream(json.post_id, json.html);
    
          //collapse publisher
    
          Publisher.close();
          Publisher.clear();
    
        $(".new_status_message").bind('ajax:failure', function(data, html, xhr) {
    
          Diaspora.widgets.alert.alert('Failed to post message!');
    
        });
    
        $(".new_comment").live('ajax:success', function(data, json, xhr) {
          json = $.parseJSON(json);
    
    lfortin's avatar
    lfortin a validé
          WebSocketReceiver.processComment(json.post_id, json.comment_id, json.html, false);
    
        });
        $(".new_comment").live('ajax:failure', function(data, html, xhr) {
    
          Diaspora.widgets.alert.alert('Failed to post message!');
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
    
    
        $(".stream").find(".delete").live('ajax:success', function(data, html, xhr) {
    
          $(this).parents(".status_message").fadeOut(150);
    
    zhitomirskiyi's avatar
    zhitomirskiyi a validé
        });
    
        var $this = $(this),
    
    root's avatar
    root a validé
          text = $this.html(),
    
          showUl = $(this).closest('li'),
    
          commentBlock = $this.closest(".stream_element").find("ul.comments", ".content"),
          commentBlockMore = $this.closest(".stream_element").find(".older_comments", ".content"),
    
          show = (text.indexOf("show") != -1);
    
    
        if( commentBlockMore.hasClass("inactive") ) {
    
    lfortin's avatar
    lfortin a validé
          commentBlockMore.fadeIn(150, function() {
    
            commentBlockMore.removeClass("inactive");
            commentBlockMore.removeClass("hidden");
          });
        } else {
    
          if(commentBlock.hasClass("hidden")) {
    
            commentBlock.removeClass('hidden');
            showUl.css('margin-bottom','-1em');
    
            commentBlock.addClass('hidden');
            showUl.css('margin-bottom','1em');
    
    root's avatar
    root a validé
        $this.html(text.replace((show) ? "show" : "hide", (show) ? "hide" : "show"));
    
      },
    
      focusNewComment: function(toggle, evt) {
        evt.preventDefault();
    
        var commentBlock = toggle.closest(".stream_element").find("ul.comments", ".content");
    
    
        if(commentBlock.hasClass('hidden')) {
          commentBlock.removeClass('hidden');
          commentBlock.find('textarea').focus();
        } else {
          if(!(commentBlock.children().length > 1)){
            commentBlock.addClass('hidden');
          } else {
            commentBlock.find('textarea').focus();
          }
        }