Sha256: c676d0b3967dac926c5cff9c9a5c05b02044edb52fec957be5ac93fd171a3f01

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

buildUploader = (element, data)->
  elementId = $(element).attr('id')
  $input = $('<input/>')
  $input
    .attr({type: "file", name: "file", class: 'ts-editable-image-input', 'data-form-data': JSON.stringify(data), 'data-element-id': elementId})
    .cloudinary_fileupload()
    .bind 'cloudinaryprogress', (e, data) ->
      $('.ts-progress-bar').css('width', Math.round((data.loaded * 100.0) / data.total) + '%')
    .bind 'cloudinarystart', (e, data) ->
      $(this).prop('disabled', true)
      $('body').append($('<div>').addClass('ts-progress-bar'))
    .bind 'cloudinarydone', (e, data) ->
      $element = $("##{$(this).data('elementId')}")
      for imageTag in $('.ts-editable-image-tag', $element)
        $(imageTag).attr('src', $.cloudinary.url(data.result.public_id, $(imageTag).data()))
      $element.data('drop').close()
      $(this).prop('disabled', false)
      $('.ts-progress-bar').remove()

      model = window.TS.getModel $element.data('ts-edit-url')
      model.set($element.data('ts-field'), { field: $element.data('ts-field'), value: {identifier: data.result.public_id}, type: 'image' })

  $input

setUpDrops = (elements)->
  drops = []

  for element in elements
    tsData = $(element).data('tsData')
    drop = new Drop
      target: $('.ts-editable-button', element)[0]
      content: buildUploader(element, tsData)[0]
      position: 'bottom center'
      openOn: 'click'
      classes: 'drop-theme-arrows-bounce-dark'
    $(element).data('drop', drop)
    drops.push drop

  drops

class window.TS.EditableImage
  constructor: (@elements) ->
    @drops = []
    for element in elements
      $(element).append($('<div>').addClass('ts-editable-button').addClass('ts-button').html("<i class='ion-ios-compose-outline'></i>"))

  enable: ->
    @disable()
    @drops = setUpDrops(@elements)

  disable: ->
    for drop in @drops
      drop.close()
      drop.remove()
      drop.destroy()
    @drops = []

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
type_station-0.0.3 app/assets/javascripts/type_station/editables/image.js.coffee
type_station-0.0.2 app/assets/javascripts/type_station/editables/image.js.coffee
type_station-0.0.1 app/assets/javascripts/type_station/editables/image.js.coffee