Sha256: 5512a30e35bec255347d4b7341367fea403d7cc3a2418b86ab8c01f1b26dd9d2

Contents?: true

Size: 1.49 KB

Versions: 5

Compression:

Stored size: 1.49 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
    @options.singular = !@input.prop('multiple')

    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

5 entries across 5 versions & 1 rubygems

Version Path
rails-uploader-0.5.4 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.5.3 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.5.2 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.5.1 app/assets/javascripts/uploader/jquery.uploader.js.coffee
rails-uploader-0.5.0 app/assets/javascripts/uploader/jquery.uploader.js.coffee