Browse Source

Adds response/responseAsync, fixes settings returned #3466 #3491

pull/3321/head
Jack Lukic 9 years ago
parent
commit
b2dd449f21
2 changed files with 31 additions and 18 deletions
  1. 9
      RELEASE-NOTES.md
  2. 40
      src/definitions/behaviors/api.js

9
RELEASE-NOTES.md

@ -2,13 +2,18 @@
### Version 2.1.7 Dec 19, 2015
**Enhancements**
-***API** - All responses fulfilled with settings (like `mockResponse`) will now receive a settings object with all values resolved. For example `url` will be `/user/2/` and not `user/{id}` in the callback. - #3466
-**API** - API now allows the use of settings `response` and `responseAsync` to replace `mockResponse` and `mockResponseAsync`. The use of "mock" may not represent the most common use case which is providing a response from a third party source. (These changes are purely cosmetic and no underlying behavior has changed) - #3491
-**Popup** - Adds `onUnplaceable` callback when element cannot be place in visible screen #3388
**Bug Fixes**
-**Flag** - A flag with no country set will no longer display an incorrect country flag. Thanks @space-alien #3333
-**Build Tools** -
-**Build Tools** - CSS build will now correctly call callback after both packaged files are created (compressed and uncompressed) Thanks @youngjay #3405
-**Search** - Search now correctly hides menu when an error message inside results is clicked. #3039
-**Popup** - Adds `onUnplaceable` callback when element cannot be place in visible screen #3388
-**Sidebar** - Sidebar no longer includes `transform` rules on child elements, this was causing layout issues in some cases (for example dropdowns in sidebars) #3306
-**Sidebar** - Fixed css rule issue causing `very thin` sidebar to not work #3300
-**Sticky** - Renames variables used to account for scroll offset internally for greater code clarity
-**Popup** - Fixed issue with `onEnable` callback being defined with name `onEnabled` and `onDisable` with `onDisabled` in default settings, causing an error. To preserve backwards compatibility, the mispelled callback name has been left, but the bug has been fixed. #3148
-**Form** - Fixed issue where text would turn transparent inside a `loading form` #3122

40
src/definitions/behaviors/api.js

@ -212,13 +212,15 @@ $.api = $.fn.api = function(parameters) {
}
// replace variables
console.log(url);
url = module.add.urlData( url );
console.log(url);
// missing url parameters
if( !url && !module.is.mocked()) {
return;
}
requestSettings.url = settings.base + url;
// look for jQuery ajax parameters in settings
ajaxSettings = $.extend(true, {}, settings, {
@ -280,7 +282,7 @@ $.api = $.fn.api = function(parameters) {
return $module.is('form') || $context.is('form');
},
mocked: function() {
return (settings.mockResponse || settings.mockResponseAsync);
return (settings.mockResponse || settings.mockResponseAsync || settings.response || settings.responseAsync);
},
input: function() {
return $module.is('input');
@ -592,9 +594,11 @@ $.api = $.fn.api = function(parameters) {
mockedXHR: function () {
var
// xhr does not simulate these properties of xhr but must return them
textStatus = false,
status = false,
httpMessage = false,
textStatus = false,
status = false,
httpMessage = false,
responder = settings.mockResponse || settings.response,
asyncResponder = settings.mockResponseAsync || settings.responseAsync,
asyncCallback,
response,
mockedXHR
@ -606,19 +610,19 @@ $.api = $.fn.api = function(parameters) {
.fail(module.event.xhr.fail)
;
if(settings.mockResponse) {
if( $.isFunction(settings.mockResponse) ) {
module.debug('Using mocked callback returning response', settings.mockResponse);
response = settings.mockResponse.call(context, settings);
if(responder) {
if( $.isFunction(responder) ) {
module.debug('Using specified synchronous callback', responder);
response = responder.call(context, requestSettings);
}
else {
module.debug('Using specified response', settings.mockResponse);
response = settings.mockResponse;
module.debug('Using settings specified response', responder);
response = responder;
}
// simulating response
mockedXHR.resolveWith(context, [ response, textStatus, { responseText: response }]);
}
else if( $.isFunction(settings.mockResponseAsync) ) {
else if( $.isFunction(asyncResponder) ) {
asyncCallback = function(response) {
module.debug('Async callback returned response', response);
@ -629,8 +633,8 @@ $.api = $.fn.api = function(parameters) {
mockedXHR.rejectWith(context, [{ responseText: response }, status, httpMessage]);
}
};
module.debug('Using async mocked response', settings.mockResponseAsync);
settings.mockResponseAsync.call(context, settings, asyncCallback);
module.debug('Using specified async response callback', asyncResponder);
asyncResponder.call(context, requestSettings, asyncCallback);
}
return mockedXHR;
},
@ -722,8 +726,8 @@ $.api = $.fn.api = function(parameters) {
module.error(error.noReturnedValue);
}
return (runSettings !== undefined)
? runSettings
: settings
? $.extend(true, {}, runSettings)
: $.extend(true, {}, settings)
;
},
urlEncodedValue: function(value) {
@ -1066,6 +1070,10 @@ $.api.settings = {
mockResponse : false,
mockResponseAsync : false,
// aliases for mock
response : false,
responseAsync : false,
// callbacks before request
beforeSend : function(settings) { return settings; },
beforeXHR : function(xhr) {},

Loading…
Cancel
Save