Skip to content

Commit

Permalink
Related #2713 add XHR to all callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jlukic committed Jul 23, 2015
1 parent 5639244 commit 44bf836
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

### Version 2.0.7 - July 22, 2015

**Enhancements**

- **API** - All API callbacks now recieve `xhr` from API request as the third calback parameter

**[Reported Bugs](https://github.com/Semantic-Org/Semantic-UI/issues?q=is%3Aissue+milestone%3A2.0.7+is%3Aclosed)**
- **Build Tools** - Fixed issue where `npm install semantic-ui` would hang after setup in some version of NPM
- **Build Tools** - Fixed `npm install` with CI or tests. Install will not stop to ask questions if project has an existing `semantic.json` file
Expand Down
15 changes: 8 additions & 7 deletions src/definitions/behaviors/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,17 +506,18 @@ $.api = $.fn.api = function(parameters) {
}
},
request: {
done: function(response) {
done: function(response, xhr) {
module.debug('Successful API Response', response);
if(settings.cache === 'local' && url) {
module.write.cachedResponse(url, response);
module.debug('Saving server response locally', module.cache);
}
settings.onSuccess.call(context, response, $module);
settings.onSuccess.call(context, response, $module, xhr);
},
complete: function(xhr) {
complete: function(maybeResponse, xhr) {
var
response = module.get.responseFromXHR(xhr)
// ajax deferred returns either response or xhr depending on success/fail
response = module.get.responseFromXHR(maybeResponse)
;
module.remove.loading();
settings.onComplete.call(context, response, $module, xhr);
Expand All @@ -529,7 +530,7 @@ $.api = $.fn.api = function(parameters) {
;
if(status == 'aborted') {
module.debug('XHR Aborted (Most likely caused by page navigation or CORS Policy)', status, httpMessage);
settings.onAbort.call(context, status, $module);
settings.onAbort.call(context, status, $module, xhr);
}
else if(status == 'invalid') {
module.debug('JSON did not pass success test. A server-side error has most likely occurred', response);
Expand All @@ -541,7 +542,7 @@ $.api = $.fn.api = function(parameters) {
if( xhr.status != 200 && httpMessage !== undefined && httpMessage !== '') {
module.error(error.statusMessage + httpMessage, ajaxSettings.url);
}
settings.onError.call(context, errorMessage, $module);
settings.onError.call(context, errorMessage, $module, xhr);
}
}

Expand All @@ -551,7 +552,7 @@ $.api = $.fn.api = function(parameters) {
setTimeout(module.remove.error, settings.errorDuration);
}
module.debug('API Request failed', errorMessage, xhr);
settings.onFailure.call(context, response, $module);
settings.onFailure.call(context, response, $module, xhr);
}
}
},
Expand Down

0 comments on commit 44bf836

Please sign in to comment.