<commit_before>var SocialStream = SocialStream || {};
SocialStream.Linkser = SocialStream.Linkser || {};
SocialStream.Linkser.initiate = function() {
  $.preloadImages("assets/loading.gif");
  var urlDetect = function() {
    this.currentValue = $("#input_activities").val();
    if(this.lastValue == null)
      this.lastValue = "";

    var regexp = /^(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&;:\/~+#-]*[\w@?^=%&;\/~+#-])?$/
    if(regexp.test($("#input_activities").val())) {
      $("#link_url").val($("#input_activities").val());
      $("#link_loaded").val(false);
      $("#new_post").attr("action", "/links");
      if(this.currentValue != this.lastValue) {
        $("#link_preview").html($('<img>').attr('src', 'assets/loading.gif').addClass('loading'));
        this.lastValue = this.currentValue;
        var url = this.currentValue;
        var urlDetect = this;
        $.ajax({
          type : "GET",
          url : "/linkser_parse?url=" + url,
          success : function(html) {
            if($("#input_activities").val() == url) {//Only show if input value is still the same
              $("#link_preview").html(html);
              $("#link_loaded").val(true);
            }
          },
          error : function(xhr, ajaxOptions, thrownError) {
            if($("#input_activities").val() == url) {//Only show if input value is still the same
              $("#link_preview").html($('<div>').addClass('loading').html("<%= I18n.t('link.errors.loading') %> " + url));
            }
          }
        });
      }
      $("#link_preview").show();
    } else {
      $("#new_post").attr("action", "/posts");
      $("#link_preview").hide();
      $("#link_preview").html("");
      $("#link_url").val("");
    }
  }
  if($("#new_post").length) {
    $("#input_activities").change(urlDetect).keyup(urlDetect);
    $("#new_post").append($('<input>').attr('type', 'hidden').attr('name', 'link[owner_id]').attr('id', 'link_owner_id').val($("#post_owner_id").val()));
    $("#new_post").append($('<input>').attr('type', 'hidden').attr('name', 'link[url]').attr('id', 'link_url'));
    $("#new_post").append($('<input>').attr('type', 'hidden').attr('name', 'link[loaded]').attr('id', 'link_loaded').val(false));
    $("#new_post").append($('<div>').attr('id', 'link_preview').css('display', 'none'));
  }
}

SocialStream.Linkser.openCallback = function(id,url,w,h){
      var height='353';
      if(w>0 && h>0) {
          height=470*h/w;
      }
      $("#" + id).html($('<iframe>').attr('src',url).attr('width','470').attr('height',height));
}

$(function(){
  SocialStream.Linkser.initiate();
});
<commit_msg>Fixes #185<commit_after>var SocialStream = SocialStream || {};
SocialStream.Linkser = SocialStream.Linkser || {};
SocialStream.Linkser.initiate = function() {
  $.preloadImages("/assets/loading.gif");
  var urlDetect = function() {
    this.currentValue = $("#input_activities").val();
    if(this.lastValue == null)
      this.lastValue = "";

    var regexp = /^(http|ftp|https):\/\/[\w-]+(\.[\w-]+)+([\w.,@?^=%&;:\/~+#-]*[\w@?^=%&;\/~+#-])?$/
    if(regexp.test($("#input_activities").val())) {
      $("#link_url").val($("#input_activities").val());
      $("#link_loaded").val(false);
      $("#new_post").attr("action", "/links");
      if(this.currentValue != this.lastValue) {
        $("#link_preview").html($('<img>').attr('src', 'assets/loading.gif').addClass('loading'));
        this.lastValue = this.currentValue;
        var url = this.currentValue;
        var urlDetect = this;
        $.ajax({
          type : "GET",
          url : "/linkser_parse?url=" + url,
          success : function(html) {
            if($("#input_activities").val() == url) {//Only show if input value is still the same
              $("#link_preview").html(html);
              $("#link_loaded").val(true);
            }
          },
          error : function(xhr, ajaxOptions, thrownError) {
            if($("#input_activities").val() == url) {//Only show if input value is still the same
              $("#link_preview").html($('<div>').addClass('loading').html("<%= I18n.t('link.errors.loading') %> " + url));
            }
          }
        });
      }
      $("#link_preview").show();
    } else {
      $("#new_post").attr("action", "/posts");
      $("#link_preview").hide();
      $("#link_preview").html("");
      $("#link_url").val("");
    }
  }
  if($("#new_post").length) {
    $("#input_activities").change(urlDetect).keyup(urlDetect);
    $("#new_post").append($('<input>').attr('type', 'hidden').attr('name', 'link[owner_id]').attr('id', 'link_owner_id').val($("#post_owner_id").val()));
    $("#new_post").append($('<input>').attr('type', 'hidden').attr('name', 'link[url]').attr('id', 'link_url'));
    $("#new_post").append($('<input>').attr('type', 'hidden').attr('name', 'link[loaded]').attr('id', 'link_loaded').val(false));
    $("#new_post").append($('<div>').attr('id', 'link_preview').css('display', 'none'));
  }
}

SocialStream.Linkser.openCallback = function(id,url,w,h){
      var height='353';
      if(w>0 && h>0) {
          height=470*h/w;
      }
      $("#" + id).html($('<iframe>').attr('src',url).attr('width','470').attr('height',height));
}

$(function(){
  SocialStream.Linkser.initiate();
});

{'fraction_non_alphanumeric': 0.26724791508718726, 'fraction_numerical': 0.005496588324488249, 'mean_word_length': 3.23855421686747, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 23, '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': '924915', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1721, 'n_words': 219}