Sha256: 6a405ed3128640a0ca9dc2b4d062cf1a78daaf4e0b68b314c6ff52120465e9cd

Contents?: true

Size: 1.31 KB

Versions: 11

Compression:

Stored size: 1.31 KB

Contents

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
jQuery ->
  $('#fileupload').fileupload
    add: (e, data) ->
      types = /(\.|\/)(gif|jpe?g|png|pdf)$/i
      file = data.files[0]
      if types.test(file.type) || types.test(file.name)
        data.context = $(tmpl("template-upload", file))
        $('#fileupload').append(data.context)
        data.submit()
      else
        alert("#{file.name} is not a gif, jpeg, png or pdf file")

    progress: (e, data) ->
      if data.context
        progress = parseInt(data.loaded / data.total * 100, 10)
        data.context.find('.bar').css('width', progress + '%')

    done: (e, data) ->
      file = data.files[0]
      domain = $('#fileupload').attr('action')
      path = $('#fileupload input[name=key]').val().replace('${filename}', file.name)
      to = $('#fileupload').data('post') + ".js"
      content = {}
      content[$('#fileupload').data('as')] = domain + path
      $.post(to, content)

      data.context.remove() if data.context # remove progress bar

    fail: (e, data) ->
      alert("#{data.files[0].name} failed to upload.")
      console.log("Upload failed:")
      console.log(data)

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
smithycms-0.5.1 app/assets/javascripts/smithy/assets.js.coffee
smithycms-0.5.0 app/assets/javascripts/smithy/assets.js.coffee
smithycms-0.4.5 app/assets/javascripts/smithy/assets.js.coffee
smithycms-0.4.4 app/assets/javascripts/smithy/assets.js.coffee
smithycms-0.4.3 app/assets/javascripts/smithy/assets.js.coffee
smithycms-0.4.2 app/assets/javascripts/smithy/assets.js.coffee
smithycms-0.4.1 app/assets/javascripts/smithy/assets.js.coffee
smithycms-0.4.0 app/assets/javascripts/smithy/assets.js.coffee
smithycms-0.0.3 app/assets/javascripts/smithy/assets.js.coffee
smithycms-0.0.2 app/assets/javascripts/smithy/assets.js.coffee
smithycms-0.0.1 app/assets/javascripts/smithy/assets.js.coffee