<commit_before>/*
 *  Copyright (c) 2010-2011, Diaspora Inc.  This file is
 *   licensed under the Affero General Public License version 3 or later.  See
 *   the COPYRIGHT file.
 */

$(document).ready(function() {

  $(".stream").on("tap click", "a.back_to_stream_element_top", function() {
    var bottomBar = $(this).closest(".bottom_bar").first();
    var streamElement = bottomBar.parent();
    $("html, body").animate({
      scrollTop: streamElement.offset().top - 54
    }, 1000);
  });

  $(".stream").on("tap click", "a.show_comments", function(evt){
    evt.preventDefault();
    toggleComments($(this));
  });

  function toggleComments(toggleReactionsLink) {
    if (toggleReactionsLink.hasClass("active")) {
      hideComments(toggleReactionsLink);
    } else {
      showComments(toggleReactionsLink);
    }
  }

  function hideComments(toggleReactionsLink) {
    var bottomBar = toggleReactionsLink.closest(".bottom_bar").first(),
        commentsContainer = commentsContainerLazy(bottomBar),
        existingCommentsContainer = commentsContainer();
    existingCommentsContainer.hide();
    toggleReactionsLink.removeClass("active");
  }

  function showComments(toggleReactionsLink) {
    var bottomBar = toggleReactionsLink.closest(".bottom_bar").first(),
        commentsContainer = commentsContainerLazy(bottomBar),
        existingCommentsContainer = commentsContainer(),
        commentActionLink = bottomBar.find("a.comment-action");
    if (existingCommentsContainer.length > 0) {
      showLoadedComments(toggleReactionsLink, existingCommentsContainer, commentActionLink);
    } else {
      showUnloadedComments(toggleReactionsLink, bottomBar, commentActionLink);
    }
  }

  function showLoadedComments(toggleReactionsLink, existingCommentsContainer, commentActionLink) {
    existingCommentsContainer.show();
    showCommentBox(commentActionLink);
    toggleReactionsLink.addClass("active");
    existingCommentsContainer.find("time.timeago").timeago();
  }

  function showUnloadedComments(toggleReactionsLink, bottomBar, commentActionLink) {
    var commentsContainer = commentsContainerLazy(bottomBar);
    $.ajax({
      url: toggleReactionsLink.attr("href"),
      success: function (data) {
        $(data).insertAfter(bottomBar.children(".show_comments").first());
        showCommentBox(commentActionLink);
        toggleReactionsLink.addClass("active");
        commentsContainer().find("time.timeago").timeago();
      }
    });
  }

  function commentsContainerLazy(bottomBar) {
    return function() {
      return bottomBar.find(".comment_container").first();
    };
  }

  $(".stream").on("tap click", "a.comment-action", function(evt) {<commit_msg>Display mobile reaction box only once<commit_after>/*
 *  Copyright (c) 2010-2011, Diaspora Inc.  This file is
 *   licensed under the Affero General Public License version 3 or later.  See
 *   the COPYRIGHT file.
 */

$(document).ready(function() {

  $(".stream").on("tap click", "a.back_to_stream_element_top", function() {
    var bottomBar = $(this).closest(".bottom_bar").first();
    var streamElement = bottomBar.parent();
    $("html, body").animate({
      scrollTop: streamElement.offset().top - 54
    }, 1000);
  });

  $(".stream").on("tap click", "a.show_comments", function(evt){
    evt.preventDefault();
    toggleComments($(this));
  });

  function toggleComments(toggleReactionsLink) {
    if(toggleReactionsLink.hasClass("loading")) { return; }
    if (toggleReactionsLink.hasClass("active")) {
      hideComments(toggleReactionsLink);
    } else {
      showComments(toggleReactionsLink);
    }
  }

  function hideComments(toggleReactionsLink) {
    var bottomBar = toggleReactionsLink.closest(".bottom_bar").first(),
        commentsContainer = commentsContainerLazy(bottomBar),
        existingCommentsContainer = commentsContainer();
    existingCommentsContainer.hide();
    toggleReactionsLink.removeClass("active");
  }

  function showComments(toggleReactionsLink) {
    var bottomBar = toggleReactionsLink.closest(".bottom_bar").first(),
        commentsContainer = commentsContainerLazy(bottomBar),
        existingCommentsContainer = commentsContainer(),
        commentActionLink = bottomBar.find("a.comment-action");
    if (existingCommentsContainer.length > 0) {
      showLoadedComments(toggleReactionsLink, existingCommentsContainer, commentActionLink);
    } else {
      showUnloadedComments(toggleReactionsLink, bottomBar, commentActionLink);
    }
  }

  function showLoadedComments(toggleReactionsLink, existingCommentsContainer, commentActionLink) {
    toggleReactionsLink.addClass("active");
    existingCommentsContainer.show();
    showCommentBox(commentActionLink);
    existingCommentsContainer.find("time.timeago").timeago();
  }

  function showUnloadedComments(toggleReactionsLink, bottomBar, commentActionLink) {
    toggleReactionsLink.addClass("loading");
    var commentsContainer = commentsContainerLazy(bottomBar);
    $.ajax({
      url: toggleReactionsLink.attr("href"),
      success: function (data) {
        toggleReactionsLink.addClass("active").removeClass("loading");
        $(data).insertAfter(bottomBar.children(".show_comments").first());
        showCommentBox(commentActionLink);
        commentsContainer().find("time.timeago").timeago();
      },
      error: function() {
        toggleReactionsLink.removeClass("loading");
      }
    });
  }

  function commentsContainerLazy(bottomBar) {
    return function() {
      return bottomBar.find(".comment_container").first();
    };
  }

  $(".stream").on("tap click", "a.comment-action", function(evt) {
{'fraction_non_alphanumeric': 0.13102222222222223, 'fraction_numerical': 0.005688888888888889, 'mean_word_length': 4.317580340264651, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2487345', 'n_tokens_mistral': 1584, 'n_tokens_neox': 1503, 'n_words': 253}