Merge pull request #1028 from domenukk/master

Fixed headless client for deferred jQuery
This commit is contained in:
Michael Schmatz 2014-05-18 14:32:12 -07:00
commit 2cc344c4f0
2 changed files with 10 additions and 4 deletions

View file

@ -1,6 +1,5 @@
### ###
This file will simulate games on node.js by emulating the browser environment. This file will simulate games on node.js by emulating the browser environment.
At some point, most of the code can be merged with Simulator.coffee
### ###
bowerComponentsPath = "./bower_components/" bowerComponentsPath = "./bower_components/"
@ -27,7 +26,6 @@ disable = [
'../locale/locale' '../locale/locale'
] ]
# Start of the actual code. Setting up the enivronment to match the environment of the browser # Start of the actual code. Setting up the enivronment to match the environment of the browser
# the path used for the loader. __dirname is module dependent. # the path used for the loader. __dirname is module dependent.
@ -108,6 +106,9 @@ $.ajax = (options) ->
console.log "Requesting: " + JSON.stringify options if options.debug console.log "Requesting: " + JSON.stringify options if options.debug
console.log "URL: " + url if options.debug console.log "URL: " + url if options.debug
deferred = Deferred()
request request
url: url url: url
jar: cookies jar: cookies
@ -124,15 +125,20 @@ $.ajax = (options) ->
if (error) if (error)
console.warn "\t↳Returned: error: #{error}" console.warn "\t↳Returned: error: #{error}"
options.error(error) if options.error? options.error(error) if options.error?
deferred.reject()
else else
console.log "\t↳Returned: statusCode #{response.statusCode}: #{if options.parse then JSON.stringify body else body}" if options.debug console.log "\t↳Returned: statusCode #{response.statusCode}: #{if options.parse then JSON.stringify body else body}" if options.debug
options.success(body, response, status: response.statusCode) if options.success? options.success(body, response, status: response.statusCode) if options.success?
deferred.resolve()
statusCode = response.statusCode if response? statusCode = response.statusCode if response?
options.complete(status: statusCode) if options.complete? options.complete(status: statusCode) if options.complete?
responded = true responded = true
deferred.promise()
$.extend = (deep, into, from) -> $.extend = (deep, into, from) ->
copy = _.clone(from, deep); copy = _.clone(from, deep);
if into if into

View file

@ -67,7 +67,7 @@
"node-gyp": "~0.13.0", "node-gyp": "~0.13.0",
"aether": "~0.2.3", "aether": "~0.2.3",
"JASON": "~0.1.3", "JASON": "~0.1.3",
"JQDeferred": "^2.1.0" "JQDeferred": "~2.1.0"
}, },
"devDependencies": { "devDependencies": {
"jade": "0.33.x", "jade": "0.33.x",