Skip to content

Commit

Permalink
Add Zepto installer.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Jun 4, 2012
1 parent 3a7a08f commit 27878e9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Deferred.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,21 @@ root.Deferred.when = (args...) ->
.fail (failArgs...) ->
allReady.rejectWith(this, failArgs...)
allReady.promise()

# Install Deferred to Zepto automatically.
do ->
destination = window.Zepto
return if not destination or destination.Deferred
destination.Deferred = ->
new Deferred()
origAjax = destination.ajax
destination.ajax = (options) ->
deferred = new Deferred()
createWrapper = (wrapped, finisher) ->
(args...) ->
wrapped?(args...)
finisher(args...)
options.success = createWrapper options.success, deferred.resolve
options.error = createWrapper options.error, deferred.reject
origAjax(options)
deferred.promise()

0 comments on commit 27878e9

Please sign in to comment.