//= require vish

Vish.Wall = (function(V, $, undefined){
  var regexp = /^(<(embed|object|iframe).*<\/\2>).*$/i

  var hidden_embed_form = "This embedded object will be added to your repository<br/>Title: <input type='text' name='embed[title]' value='Check out this embed!' /><br/>Description:<input type='textarea' name='embed[description]'>";

  var urlDetect = function() {
    this.currentValue = $("#input_activities").val();

    if(regexp.test($("#input_activities").val())) {
      $("#embed_fulltext").val( regexp.exec($("#input_activities").val())[1]);
      $("#new_post").attr("action", "/embeds");
      $("#embed_preview").html(hidden_embed_form);
      $("#embed_preview").show();
    } else {
      $("#new_post").attr("action", "/posts");
      $("#embed_preview").hide();
      $("#embed_preview").html("");
      $("#embed_fulltext").val("");
    }
  }

  var init = function(){
    $("#input_activities_document").watermark(I18n.t('document.input'), "#666");

    if($("#new_post").length) {
      $("#input_activities").change(urlDetect).keyup(urlDetect);
      $("#new_post").append($('<input>').attr('type', 'hidden').attr('name', 'embed[owner_id]').attr('id', 'embed_owner_id').val($("#post_owner_id").val()));
      $("#new_post").append($('<input>').attr('type', 'hidden').attr('name', 'embed[fulltext]').attr('id', 'embed_fulltext'));
      $("#new_post").append($('<div>').attr('id', 'embed_preview').css('display', 'none'));

    }

    $('#attachFileButton').click(function(){
      $('#attachFileButton').toggleClass("selected");
      $('#wrapper_activities_header form').toggle();
      var post_text = $('#input_activities').val();
      var document_text = $('#input_activities_document').val();
      $('#input_activities').val(document_text);
      $('#input_activities_document').val(post_text);
      if($('#document_file').is(":visible")) {
        $('#document_file').trigger('click');
      }
    });
  }

  return {
    init: init,
  };
}) (Vish, jQuery)

@@ -63,16 +63,21 @@
 r regexp
+Embed
  = /%5E(%3C(
@@ -110,16 +110,119 @@
 2%3E).*$/i
+%0A  var regexpLink = /%5E(http%7Cftp%7Chttps):%5C/%5C/%5B%5Cw-%5D+(%5C.%5B%5Cw-%5D+)+(%5B%5Cw.,@?%5E=%25&;:%5C/~+#-%5D*%5B%5Cw@?%5E=%25&;%5C/~+#-%5D)?$/
 %0A%0A  var 
@@ -547,16 +547,21 @@
 f(regexp
+Embed
 .test($(
@@ -769,16 +769,16 @@
 _form);%0A
-
       $(
@@ -799,24 +799,1223 @@
 w%22).show();%0A
+    %7D else if(regexpLink.test($(%22#input_activities%22).val())) %7B%0A      $(%22#link_url%22).val($(%22#input_activities%22).val());%0A      $(%22#link_loaded%22).val(false);%0A      $(%22#new_post%22).attr(%22action%22, %22/links%22);%0A%0A      if(this.currentValue != this.lastValue) %7B%0A        $(%22#link_preview%22).html($('%3Cimg%3E').attr('src', '%3C%25= asset_path('loading.gif') %25%3E').addClass('loading'));%0A%0A        this.lastValue = this.currentValue;%0A        var url = this.currentValue;%0A        var urlDetect = this;%0A%0A        $.ajax(%7B%0A          type : %22GET%22,%0A          url : %22/linkser_parse?url=%22 + url,%0A          dataType: 'html',%0A          success : function(html) %7B%0A            if($(%22#input_activities%22).val() == url) %7B//Only show if input value is still the same%0A              $(%22#link_preview%22).html(html);%0A              $(%22#link_loaded%22).val(true);%0A            %7D%0A          %7D,%0A          error : function(xhr, ajaxOptions, thrownError) %7B%0A            if($(%22#input_activities%22).val() == url) %7B//Only show if input value is still the same%0A              $(%22#link_preview%22).html($('%3Cdiv%3E').addClass('loading').html(I18n.t('link.errors.loading') + %22 %22 + url));%0A            %7D%0A          %7D%0A        %7D);%0A      %7D%0A%0A      $(%22#link_preview%22).show();%0A%0A
     %7D else %7B

Fix embeds, links regex matching in timeline