Skip to content

Commit

Permalink
add js and css
Browse files Browse the repository at this point in the history
  • Loading branch information
Wayne committed Sep 30, 2012
1 parent b7375cd commit 9d2b11c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.DS_Store
spec/gallery-jquery/fileupload
spec/gallery-jquery-fileupload
*.gem
*.rbc
.bundle
Expand Down
30 changes: 30 additions & 0 deletions app/assets/javascripts/s3_direct_upload.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#= require jquery-fileupload/basic
#= require jquery-fileupload/vendor/tmpl

jQuery ->
$('#fileupload').fileupload
add: (e, data) ->
file = data.files[0]
data.context = $(tmpl("template-upload", file))
$('#fileupload').append(data.context)
data.submit()

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')
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)
17 changes: 17 additions & 0 deletions app/assets/stylesheets/s3_direct_upload_progress_bars.css.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.upload {
border-top: solid 1px #CCC;
width: 400px;
padding-top: 10px;
margin-top: 10px;

.progress {
margin-top: 8px;
border: solid 1px #555;
border-radius: 3px;
-moz-border-radius: 3px;
.bar {
height: 10px;
background: #3EC144;
}
}
}

0 comments on commit 9d2b11c

Please sign in to comment.