Sha256: 0c151f3d38794eed1b629fb016da89ce0e0e1647c401dfeab19ffd29986994cb

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

var jcrop_api;

window.init_papercrop = function() {
  $("div[id$=_cropbox]").each(function() {

    var attachment = $(this).attr("id").replace("_cropbox", "");
    var preview    = !!$("#" + attachment + "_crop_preview").length;
    var aspect     = $("input#" + attachment + "_aspect").val();
    var width      = $(this).width();
    
    console.log($(this));

    update_crop = function(coords) {
      var preview_width, rx, ry;

      if (preview) {
        preview_width = $("#" + attachment + "_crop_preview_wrapper").width();
        
        rx = preview_width / coords.w;
        ry = preview_width / coords.h;

        $("img#" + attachment + "_crop_preview").css({
          width      : Math.round(rx * $("input[id$='_" + attachment + "_original_w']").val()) + "px",
          height     : Math.round((ry * $("input[id$='_" + attachment + "_original_h']").val()) / aspect) + "px",
          marginLeft : "-" + Math.round(rx * coords.x) + "px",
          marginTop  : "-" + Math.round((ry * coords.y) / aspect) + "px"
        });
      }

      $("#" + attachment + "_crop_x").val(Math.round(coords.x));
      $("#" + attachment + "_crop_y").val(Math.round(coords.y));
      $("#" + attachment + "_crop_w").val(Math.round(coords.w));
      $("#" + attachment + "_crop_h").val(Math.round(coords.h));
    };

    $(this).find("img").Jcrop({
      onChange    : update_crop,
      onSelect    : update_crop,
      setSelect   : [0, 0, 250, 250],
      aspectRatio : aspect,
      boxWidth    : $("input[id$='_" + attachment + "_box_w']").val()
    }, function() {
      jcrop_api = this;
    });
  });
};


$(document).ready(function() {
  init_papercrop();
});

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
papercrop-0.1.1 lib/assets/javascripts/papercrop.js
papercrop-0.1.0 lib/assets/javascripts/papercrop.js