Sha256: 96075b47880fb3e59e98edb295a6d95a293ae12c843980e530ff6a269b60d45d

Contents?: true

Size: 1.49 KB

Versions: 35

Compression:

Stored size: 1.49 KB

Contents

class Tenon.features.AssetCropping
  constructor: ->
    $(document).on('click', '.asset-crop', @_loadCrop)
    $(document).on('click', '.asset-cropping .close', @_cancelCrop)
    $(document).on('ajax:success', '.asset-cropping form[data-remote]', @_saveCrop)
    $(document).keyup (ev) =>
      @_cancelCrop(ev) if ev.keyCode is 27
    $(document).on('click', '.save', @_showSpinner)

  _showSpinner: (e) ->
    $('.spinner').fadeIn()

  _loadCrop: (e) =>
    e.preventDefault()
    @$link = $(e.currentTarget)
    url = Routes.tenon_crop_asset_path(@$link.data('asset-id'))
    $.get(url, {format: 'html'}, @_startCrop, 'html')

  _cancelCrop: (e) ->
    e.preventDefault()
    $('.asset-cropping').remove()

  _startCrop: (data) =>
    $(data).appendTo('body')
    $cropbox = $('#cropbox')

    $("#cropbox").Jcrop
      onChange: @_updateCrop
      onSelect: @_updateCrop
      boxWidth: $(window).width() * 0.8
      boxHeight: $(window).height() * 0.75

  _saveCrop: (e, data) =>
    if @$link.data('post-crop-handler')
      @_sendToHandler(data)
    else
      $('.asset-cropping').remove()

  _sendToHandler: (data) =>
    parts = @$link.data('post-crop-handler').split('.')
    method = window
    $(parts).each (i, part) -> method = method[part]
    new method(@$link, data)

  _updateCrop: (coords) ->
    ratio = $('#cropbox').data('width') / $('#cropbox').width()
    $('#asset_crop_x').val(coords.x)
    $('#asset_crop_y').val(coords.y)
    $('#asset_crop_w').val(coords.w)
    $('#asset_crop_h').val(coords.h)

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
tenon-1.1.1 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.76 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.75 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.74 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.73 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.72 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.71 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.70 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.69 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.68 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.67 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.66 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.65 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.64 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.63 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.62 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.61 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.60 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.59 app/assets/javascripts/tenon/features/asset_cropping.js.coffee
tenon-1.0.57 app/assets/javascripts/tenon/features/asset_cropping.js.coffee