Sha256: 99d1538391532414b1d806475c58955632fd1a5d57fddd5821b24b1e279a01e0

Contents?: true

Size: 1.92 KB

Versions: 9

Compression:

Stored size: 1.92 KB

Contents

buildUploader = (editor) ->
  $input = $('<input/>')
  $label = $('<label/>')

  $labelIcon = $('<i/>').addClass "ts-file-style-icon #{if editor.data.type == 'image' then 'ion-image' else 'ion-android-attach'}"
  # $labelText = $('<span/>').addClass('ts-file-style-text').text('Upload image')

  $label
    .addClass 'ts-file-editor'
    .addClass('ts-editable-button')
    .addClass('ts-button')

  $input
    .attr({type: "file", name: "file", class: 'ts-editable-file-input', style: 'display: none', 'data-form-data': JSON.stringify(editor.data.options.cloudinary), 'data-element-id': editor.$el.attr('id')})
    .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, $.extend({}, {format: data.result.format}, $(imageTag).data())))
      for linkTag in $('.ts-editable-link-tag', $element)
        $(linkTag).attr('href', $.cloudinary.url(data.result.public_id, {resource_type: 'raw', format: data.result.format}))
      $(this).prop('disabled', false)
      $('.ts-progress-bar').remove()

      model = editor.ts.getModel editor.data.url
      model.set(editor.data.field, { field: editor.data.field, value: {identifier: data.result.public_id, format: data.result.format}, type: editor.data.type })

  $label
    # .append $labelText
    .append $labelIcon
    .append $input


class @TypeStation.FileEditor
  constructor: (@ts, @$el, @data) ->
    @$el.addClass('ts-block')
  enable: ->
    @$el.append(buildUploader(@))

  disable: ->
    @$el.find('.ts-file-editor').remove()

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
type_station-0.3.4 app/assets/javascripts/type_station/editables/file_editor.js.coffee
type_station-0.3.3 app/assets/javascripts/type_station/editables/file_editor.js.coffee
type_station-0.3.2 app/assets/javascripts/type_station/editables/file_editor.js.coffee
type_station-0.3.1 app/assets/javascripts/type_station/editables/file_editor.js.coffee
type_station-0.3.0 app/assets/javascripts/type_station/editables/file_editor.js.coffee
type_station-0.2.3 app/assets/javascripts/type_station/editables/file_editor.js.coffee
type_station-0.2.2 app/assets/javascripts/type_station/editables/file_editor.js.coffee
type_station-0.2.1 app/assets/javascripts/type_station/editables/file_editor.js.coffee
type_station-0.2.0 app/assets/javascripts/type_station/editables/file_editor.js.coffee