From 96f5f10811bc7132577d3a1f266ff532fd2e8ffe Mon Sep 17 00:00:00 2001 From: Jay Trees Date: Mon, 17 Jan 2022 12:40:53 +0100 Subject: [PATCH] Refactor --- includes/assets/js/default.js | 44 +++++++++++++++++++++++++++ includes/assets/js/wishlist-view.js | 47 ----------------------------- 2 files changed, 44 insertions(+), 47 deletions(-) delete mode 100644 includes/assets/js/wishlist-view.js diff --git a/includes/assets/js/default.js b/includes/assets/js/default.js index eae289a4..76b8a22d 100644 --- a/includes/assets/js/default.js +++ b/includes/assets/js/default.js @@ -1,3 +1,47 @@ $(function() { + $.fn.api.settings.api = { + 'get wishlists' : '/includes/api/wishlists.php' + }; + $('.ui.dropdown.wishlists').dropdown({ + filterRemoteData: true + }); + + $('.ui.dropdown.wishlists').api({ + action: 'get wishlists', + method: 'GET', + on: 'now', + onResponse: function(response) { + console.log('onResponse'); + // make some adjustments to response + return response; + }, + successTest: function(response) { + console.log('successTest'); + // test whether a JSON response is valid + return response.success || false; + }, + onComplete: function(response, element, xhr) { + $('.ui.dropdown.wishlists').removeClass('loading'); + }, + onSuccess: function(response, element, xhr) { + $('.ui.dropdown.wishlists') + .dropdown({ + values: response.results + }) + .dropdown('set selected', response.results[0].value); + }, + onFailure: function(response, element, xhr) { + console.log('onFailure'); + // request failed, or valid response but response.success = false + }, + onError: function(errorMessage, element, xhr) { + console.log('onError'); + // invalid response + }, + onAbort: function(errorMessage, element, xhr) { + console.log('onAbort'); + // navigated to a new page, CORS issue, or user canceled request + } + }); }); diff --git a/includes/assets/js/wishlist-view.js b/includes/assets/js/wishlist-view.js deleted file mode 100644 index 76b8a22d..00000000 --- a/includes/assets/js/wishlist-view.js +++ /dev/null @@ -1,47 +0,0 @@ -$(function() { - $.fn.api.settings.api = { - 'get wishlists' : '/includes/api/wishlists.php' - }; - - $('.ui.dropdown.wishlists').dropdown({ - filterRemoteData: true - }); - - $('.ui.dropdown.wishlists').api({ - action: 'get wishlists', - method: 'GET', - on: 'now', - onResponse: function(response) { - console.log('onResponse'); - // make some adjustments to response - return response; - }, - successTest: function(response) { - console.log('successTest'); - // test whether a JSON response is valid - return response.success || false; - }, - onComplete: function(response, element, xhr) { - $('.ui.dropdown.wishlists').removeClass('loading'); - }, - onSuccess: function(response, element, xhr) { - $('.ui.dropdown.wishlists') - .dropdown({ - values: response.results - }) - .dropdown('set selected', response.results[0].value); - }, - onFailure: function(response, element, xhr) { - console.log('onFailure'); - // request failed, or valid response but response.success = false - }, - onError: function(errorMessage, element, xhr) { - console.log('onError'); - // invalid response - }, - onAbort: function(errorMessage, element, xhr) { - console.log('onAbort'); - // navigated to a new page, CORS issue, or user canceled request - } - }); -});