Sha256: 9fbffec803611581dd8ecbc747b02b72a4a8b45d20aa2e7d0a3eb6481fb2cae0

Contents?: true

Size: 1.44 KB

Versions: 10

Compression:

Stored size: 1.44 KB

Contents

$ = jQuery

$.fn.uploaderWidget = (options = {}) ->
  @each ->
    $this = $(this)
    data = $this.data('uploaderWidget')
    if (!data)
      $this.data('uploaderWidget', new UploaderWidget(this, options))
    if (typeof options is 'string')
      data[options]()

class UploaderWidget
  constructor: (@dom_id, options = {}) ->
    defaults =
      dataType: 'json'
      autoUpload: true
      paramName: 'asset[data]'
      formData: (form) -> return []
      namespace: 'uploader'
      uploadTemplateId: 'template-upload-'
      downloadTemplateId: 'template-download-'

    @options = $.extend defaults, options

    this._setup()

  _setup: ->
    @element = $(@dom_id)
    @container = @element.find('.uploader-files')
    @template = @element.data('tpml')
    @input = @element.find('input[type="file"]:eq(0)')

    @options['dropZone'] = @element
    @options['filesContainer'] = @container
    @options['uploadTemplateId'] += @template
    @options['downloadTemplateId'] += @template

    this._initFileupload()

  _initFileupload: ->
    @input.fileupload(@options)

    @uploader = (@input.data('blueimp-fileupload') || @input.data('fileupload'))

    this._load() if @element.data('exists')

  _load: ->
    $.ajax(
      url: @input.data('url')
      dataType: 'json'
      method: 'GET'
      success: (data) =>
        if data['files']?
          this.render(data['files'])
    )

  render: (files) ->
    @uploader._renderDownload(files).appendTo(@container)

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rails-uploader-0.4.5 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.4.4 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.4.3 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.4.2 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.4.1 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.4.0 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.3.4 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.3.3 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.3.2 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.3.1 app/assets/javascripts/uploader/jquery.uploader.js.coffee