Sha256: 9117798d8c266d2d3612c70b0445a9ecae2a243124a76c2cc3b2ee8c9155a84b

Contents?: true

Size: 1.19 KB

Versions: 6

Compression:

Stored size: 1.19 KB

Contents

class window.CroppableImage
  @crop_defaults = {}
#    aspectRatio: 760 / 350
#    setSelect: [0, 0, 760, 350]

  constructor: (@el, @options = {}) ->
    @options = {} unless _.isObject(@options)

  fancyboxHandler: =>
    _.defaults(@options, CroppableImage.crop_defaults)
    @options.onSelect = @setCropData
    @options.onChange = @setCropData
    $img = $('.fancybox-image:first')
    @options.trueSize = [$img[0].naturalWidth, $img[0].naturalHeight]
    $img.Jcrop @options
    $('.fancybox-nav').hide()

    $cont = $('.fancybox-outer:first')
    $btn = $("<a href='#' class='btn btn-primary' id='crop_button'>Обрезать</a>")
    $cont.append($btn)
    $btn.click @cropHandler

  setCropData: (coords) =>
    @cropData = coords

  cropHandler: (e) =>
    e.preventDefault()
    asset_id = to_i($('.fancybox-image:first').attr('src').match(/\/[\d\/]{1,}\//)[0].replace(/\//g, ''))
    $asset = $(@options.asset_selector || "#asset_#{asset_id}")
    geometry = [@cropData['w'], @cropData['h'], @cropData['x'], @cropData['y']].join(',')
    $.post "/admin/assets/#{asset_id}/crop", {geometry: geometry}, (data) =>
      $asset.replaceWith @el.data('assets').template(data.asset)
      $.fancybox.close()

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ab_admin-0.8.3 app/assets/javascripts/ab_admin/components/croppable_image.js.coffee
ab_admin-0.8.2 app/assets/javascripts/ab_admin/components/croppable_image.js.coffee
ab_admin-0.8.1 app/assets/javascripts/ab_admin/components/croppable_image.js.coffee
ab_admin-0.8.0 app/assets/javascripts/ab_admin/components/croppable_image.js.coffee
ab_admin-0.7.0 app/assets/javascripts/ab_admin/components/croppable_image.js.coffee
ab_admin-0.6.1 app/assets/javascripts/ab_admin/components/croppable_image.js.coffee