Browse Source

Fixes #3653, refactors several lines to use expectsJSON

pull/3792/head
Jack Lukic 8 years ago
parent
commit
0fa338409c
2 changed files with 10 additions and 4 deletions
  1. 3
      RELEASE-NOTES.md
  2. 11
      src/definitions/behaviors/api.js

3
RELEASE-NOTES.md

@ -17,7 +17,8 @@
-**Divider** - Fixed issue where descenders like "g" would be cut off in `horizontal divider` #3585 -**Divider** - Fixed issue where descenders like "g" would be cut off in `horizontal divider` #3585
**Bugs** **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 - **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 - **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 - **Dropdown** - Fixed issue where `apiSettings` was not defaulting to use `cache: 'local'` as specified in the docs

11
src/definitions/behaviors/api.js

@ -275,6 +275,9 @@ $.api = $.fn.api = function(parameters) {
disabled: function() { disabled: function() {
return ($module.filter(selector.disabled).length > 0); return ($module.filter(selector.disabled).length > 0);
}, },
expectingJSON: function() {
return settings.dataType !== 'json' && settings.dataType !== 'jsonp';
},
form: function() { form: function() {
return $module.is('form') || $context.is('form'); return $module.is('form') || $context.is('form');
}, },
@ -298,7 +301,7 @@ $.api = $.fn.api = function(parameters) {
} }
}, },
validResponse: function(response) { 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); module.verbose('Response is not JSON, skipping validation', settings.successTest, response);
return true; return true;
} }
@ -468,7 +471,9 @@ $.api = $.fn.api = function(parameters) {
elapsedTime = (new Date().getTime() - requestStartTime), elapsedTime = (new Date().getTime() - requestStartTime),
timeLeft = (settings.loadingDuration - elapsedTime), timeLeft = (settings.loadingDuration - elapsedTime),
translatedResponse = ( $.isFunction(settings.onResponse) ) 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 : false
; ;
timeLeft = (timeLeft > 0) timeLeft = (timeLeft > 0)
@ -677,7 +682,7 @@ $.api = $.fn.api = function(parameters) {
get: { get: {
responseFromXHR: function(xhr) { responseFromXHR: function(xhr) {
return $.isPlainObject(xhr) return $.isPlainObject(xhr)
? (settings.dataType == 'json' || settings.dataType == 'jsonp')
? (module.is.expectingJSON())
? module.decode.json(xhr.responseText) ? module.decode.json(xhr.responseText)
: xhr.responseText : xhr.responseText
: false : false

Loading…
Cancel
Save