Sha256: cb80be27623fcdaa5ea9ed1b79d39022dfafff123a34230dbf5b253dcaff9287

Contents?: true

Size: 1.89 KB

Versions: 2

Compression:

Stored size: 1.89 KB

Contents

<% my_file_name = File.basename(@avatar.logo.queued_for_write[:original].path) %>

<div class = "block">
  <div id="precropPrev" >
    <div class="form_row">
      <%= t('avatar.preview') %>
    </div>
    <div id="precropPrevImg" class="logo">
      <%= image_tag "tmp/#{my_file_name}",:id=>"preview" %>
    </div>  
  </div>
  
  <div class="form_row">
    <%= t('avatar.original') %>
  </div>
  
  <div id="precropDiv" class = "block title content">
  	<%= image_tag "tmp/#{my_file_name}",:id=>"cropImage" %>
  </div>
</div>
<% content_for :javascript do %>
jQuery('#cropImage').Jcrop({
            bgColor:     'clear',
            bgOpacity:   .6,
            setSelect:   [ 0, 0, 200, 200 ],
            aspectRatio: 1 ,
            onChange: update_crop,
            onSelect: update_crop
        });

function update_crop(coords) {
  var rx = 100/coords.w;
  var ry = 100/coords.h;
  
  if((coords.w == 0) || (coords.h == 0)){
  	rx = 100/$("#cropImage").width();
  	ry = 100/$("#cropImage").height();
  	coords.x = 0;
  	coords.y = 0;
  }  
  
  $('#preview').css({
    width: Math.round(rx * $("#cropImage").width()) + 'px',
    height: Math.round(ry * $("#cropImage").height()) + 'px',
    marginLeft: '-' + Math.round(rx * coords.x) + 'px',
    marginTop: '-' + Math.round(ry * coords.y) + 'px'
  });
  var ratio = 1;
  $("#crop_x").val(Math.round(coords.x * ratio));
  $("#crop_y").val(Math.round(coords.y * ratio));
  $("#crop_w").val(Math.round(coords.w * ratio));
  $("#crop_h").val(Math.round(coords.h * ratio));
}
<% end %>

<%= form_for @avatar, :html => { :multipart => true } do |f| %>
<div class= "block">
  <% for attribute in [:crop_x, :crop_y, :crop_w, :crop_h] %>
    <%= f.hidden_field attribute, :id => attribute %>
  <% end %>
	<%= f.hidden_field :name, :value => my_file_name %>
	  <div class="form_row center">
  <%= f.submit t('avatar.crop_submit'), :class => "button" %>
  </div>
  </div>
<% end %>

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
social_stream-0.4.4 app/views/avatars/_precrop.html.erb
social_stream-0.4.3 app/views/avatars/_precrop.html.erb