Skip to content

Commit

Permalink
Merge pull request waynehoover#158 from rocketmobile/master
Browse files Browse the repository at this point in the history
allow cancelation of ajax events by bubbling up return values to subsequent event handlers
  • Loading branch information
waynehoover committed Apr 15, 2014
2 parents 4d7db7e + 273aa57 commit 113d95d
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 113d95d

Please sign in to comment.