Skip to content

Commit

Permalink
Fixes #3653, refactors several lines to use expectsJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
jlukic committed Feb 28, 2016
1 parent 3328e08 commit 0fa3384
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
-**Divider** - Fixed issue where descenders like "g" would be cut off in `horizontal divider` #3585

**Bugs**
**Grid** - Fixed issue where `centered` content would cause `justified` content to appear aligned left. #3496
- **API** - Fixed bug where using `onResponse` with `dataType` other than JSON or JSONP would cause an error. (Not allowing plain text responses to be translated) #3653
- **Grid** - Fixed issue where `centered` content would cause `justified` content to appear aligned left. #3496
- **Button** - Fixes issue where `right icon` like `right arrow icon` would have additional margin inside an `icon button` #3525
- **Checkbox** - Fixed a chrome issue where radio buttons may receive `indeterminate` styles when user has not yet interacted with the page
- **Dropdown** - Fixed issue where `apiSettings` was not defaulting to use `cache: 'local'` as specified in the docs
Expand Down
11 changes: 8 additions & 3 deletions src/definitions/behaviors/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ $.api = $.fn.api = function(parameters) {
disabled: function() {
return ($module.filter(selector.disabled).length > 0);
},
expectingJSON: function() {
return settings.dataType !== 'json' && settings.dataType !== 'jsonp';
},
form: function() {
return $module.is('form') || $context.is('form');
},
Expand All @@ -298,7 +301,7 @@ $.api = $.fn.api = function(parameters) {
}
},
validResponse: function(response) {
if( (settings.dataType !== 'json' && settings.dataType !== 'jsonp') || !$.isFunction(settings.successTest) ) {
if( (!module.is.expectingJSON()) || !$.isFunction(settings.successTest) ) {
module.verbose('Response is not JSON, skipping validation', settings.successTest, response);
return true;
}
Expand Down Expand Up @@ -468,7 +471,9 @@ $.api = $.fn.api = function(parameters) {
elapsedTime = (new Date().getTime() - requestStartTime),
timeLeft = (settings.loadingDuration - elapsedTime),
translatedResponse = ( $.isFunction(settings.onResponse) )
? settings.onResponse.call(context, $.extend(true, {}, response))
? module.is.expectingJSON()
? settings.onResponse.call(context, $.extend(true, {}, response))
: settings.onResponse.call(conetxt, response)
: false
;
timeLeft = (timeLeft > 0)
Expand Down Expand Up @@ -677,7 +682,7 @@ $.api = $.fn.api = function(parameters) {
get: {
responseFromXHR: function(xhr) {
return $.isPlainObject(xhr)
? (settings.dataType == 'json' || settings.dataType == 'jsonp')
? (module.is.expectingJSON())
? module.decode.json(xhr.responseText)
: xhr.responseText
: false
Expand Down

0 comments on commit 0fa3384

Please sign in to comment.