infusionvlc/infusion

View on GitHub
app/views/proposals/_form.html.erb

Summary

Maintainability
Test Coverage
<%= form_for(@proposal) do |f| %>
  <div class="field">
    <%= f.label :title %><br />
    <%= f.text_field :title, autofocus: true, class: 'form-control' %>
  </div><br/>

  <div class="field">
    <%= f.label :description %><br />
    <div class="row">
      <div class="col-sm-12 col-md-6">
        <%= f.text_area :description, class: 'form-control', id:'description_edit' %>
      </div>
      <div class="col-sm-12 col-md-6">
        <p id="description_view" class="description"></p>
      </div>
    </div>
  </div><br/>

  <div class="actions">
    <%= f.submit class: 'btn btn-primary' %>
  </div>
<% end %>

<script>
  var converter = new showdown.Converter({simplifiedAutoLink: true, openLinksInNewWindow: true, emoji: true});

  function autosize(el){
    setTimeout(function(){
      el.style.cssText = 'height:auto; padding:0';
      el.style.cssText = 'height:' + (el.scrollHeight + 5) + 'px';
    },0);
  };

  $("#description_edit").keyup(function() {
    $('#description_view').html(converter.makeHtml(this.value));
    autosize(this);
  });

  $( "#requirements_edit" ).keyup(function() {
    $('#requirements_view').html(converter.makeHtml(this.value));
    autosize(this);
  });

  $(document).on('turbolinks:load', function(){
    $('#description_edit').keyup();
    $('#requirements_edit').keyup();
  });

</script>