diff --git a/src/definitions/modules/dropdown.js b/src/definitions/modules/dropdown.js index 71cfc6e825..228c323cb3 100644 --- a/src/definitions/modules/dropdown.js +++ b/src/definitions/modules/dropdown.js @@ -814,20 +814,28 @@ $.fn.dropdown = function(parameters) { throttle : settings.throttle, urlData : { query: query - }, - onError: function() { + } + }, + apiCallbacks = { + onError: function(errorMessage, $module, xhr) { module.add.message(message.serverError); iconClicked = false; focused = false; callback.apply(null, callbackParameters); + if(typeof settings.apiSettings.onError === 'function') { + settings.apiSettings.onError.call(this, errorMessage, $module, xhr); + } }, - onFailure: function() { + onFailure: function(response, $module, xhr) { module.add.message(message.serverError); iconClicked = false; focused = false; callback.apply(null, callbackParameters); + if(typeof settings.apiSettings.onFailure === 'function') { + settings.apiSettings.onFailure.call(this, response, $module, xhr); + } }, - onSuccess : function(response) { + onSuccess : function(response, $module, xhr) { var values = response[fields.remoteValues] ; @@ -852,13 +860,16 @@ $.fn.dropdown = function(parameters) { iconClicked = false; focused = false; callback.apply(null, callbackParameters); + if(typeof settings.apiSettings.onSuccess === 'function') { + settings.apiSettings.onSuccess.call(this, response, $module, xhr); + } } } ; if( !$module.api('get request') ) { module.setup.api(); } - apiSettings = $.extend(true, {}, apiSettings, settings.apiSettings); + apiSettings = $.extend(true, {}, apiSettings, settings.apiSettings, apiCallbacks); $module .api('setting', apiSettings) .api('query') diff --git a/src/definitions/modules/search.js b/src/definitions/modules/search.js index 8687acc000..b0321b5306 100644 --- a/src/definitions/modules/search.js +++ b/src/definitions/modules/search.js @@ -367,20 +367,36 @@ $.fn.search = function(parameters) { urlData : { query : searchTerm }, - onSuccess : function(response) { + }, + apiCallbacks = { + onSuccess : function(response, $module, xhr) { module.parse.response.call(element, response, searchTerm); callback(); + if(settings.apiSettings && typeof settings.apiSettings.onSuccess === 'function') { + settings.apiSettings.onSuccess.call(this, response, $module, xhr); + } }, - onFailure : function() { + onFailure : function(response, $module, xhr) { module.displayMessage(error.serverError); callback(); + if(settings.apiSettings && typeof settings.apiSettings.onFailure === 'function') { + settings.apiSettings.onFailure.call(this, response, $module, xhr); + } }, - onAbort : function(response) { + onAbort : function(status, $module, xhr) { + if(settings.apiSettings && typeof settings.apiSettings.onAbort === 'function') { + settings.apiSettings.onAbort.call(this, status, $module, xhr); + } }, - onError : module.error + onError : function(errorMessage, $module, xhr){ + module.error(); + if(settings.apiSettings && typeof settings.apiSettings.onError === 'function') { + settings.apiSettings.onError.call(this, errorMessage, $module, xhr); + } + } } ; - $.extend(true, apiSettings, settings.apiSettings); + $.extend(true, apiSettings, settings.apiSettings, apiCallbacks); module.verbose('Setting up API request', apiSettings); $module.api(apiSettings); }