Skip to content

Commit

Permalink
allow cancelation of rails ujs events by bubbling up return values to…
Browse files Browse the repository at this point in the history
… subsequent event handlers
  • Loading branch information
eprothro committed Apr 10, 2014
1 parent 4d7db7e commit 273aa57
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions app/assets/javascripts/s3_direct_upload.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,22 @@ $.fn.S3Uploader = (options) ->
type: $uploadForm.data('callback-method')
url: callback_url
data: content
beforeSend: ( xhr, settings ) -> $uploadForm.trigger( 'ajax:beforeSend', [xhr, settings] )
complete: ( xhr, status ) -> $uploadForm.trigger( 'ajax:complete', [xhr, status] )
success: ( data, status, xhr ) -> $uploadForm.trigger( 'ajax:success', [data, status, xhr] )
error: ( xhr, status, error ) -> $uploadForm.trigger( 'ajax:error', [xhr, status, error] )
beforeSend: ( xhr, settings ) ->
event = $.Event('ajax:beforeSend')
$uploadForm.trigger(event, [xhr, settings])
return event.result
complete: ( xhr, status ) ->
event = $.Event('ajax:complete')
$uploadForm.trigger(event, [xhr, status])
return event.result
success: ( data, status, xhr ) ->
event = $.Event('ajax:success')
$uploadForm.trigger(event, [data, status, xhr])
return event.result
error: ( xhr, status, error ) ->
event = $.Event('ajax:error')
$uploadForm.trigger(event, [xhr, status, error])
return event.result

data.context.remove() if data.context && settings.remove_completed_progress_bar # remove progress bar
$uploadForm.trigger("s3_upload_complete", [content])
Expand Down

0 comments on commit 273aa57

Please sign in to comment.