Skip to content

Commit ee3078b

Browse files
authored
Merge pull request #17 from ideal-postcodes/3.0.7
3.0.7
2 parents 0d2f2bd + 3d3b7b6 commit ee3078b

File tree

10 files changed

+235
-130
lines changed

10 files changed

+235
-130
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [3.0.7] 2018-03-14
4+
- Fix: Custom API endpoint can be passed to setup configuration object
5+
- Fix: Class Methods `lookupPostcode`, `lookupAddress` and `checkKey` accept custom endpoint
6+
- Reduce library size. Commented out optional configuration attributes which currently serve as documentation. Will be removed altogether in final minified payload
7+
38
## [3.0.6] 2017-11-02
49
- Fix: Sublicensee key now passed into key checking API calls if `check_key: true`
510

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery.postcodes",
3-
"version": "3.0.6",
3+
"version": "3.0.7",
44
"authors": [
55
"support@ideal-postcodes.co.uk"
66
],

dist/postcodes.js

Lines changed: 51 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/*! Ideal Postcodes jQuery Plugin - v3.0.6 - 2017-11-17
1+
/*! Ideal Postcodes jQuery Plugin - v3.0.7 - 2018-03-14
22
* https://github.com/ideal-postcodes/jquery.postcodes
3-
2017 Ideal Postcodes; Licensed MIT */
3+
2018 Ideal Postcodes; Licensed MIT */
44
(function($) {
55
"use strict";
66
// Cache for all new instances of the plugin
@@ -23,23 +23,23 @@
2323
line_2: "#line_2",
2424
line_3: "#line_3",
2525
post_town: "#post_town",
26-
postcode: "#postcode",
27-
postcode_inward: undefined,
28-
postcode_outward: undefined,
29-
udprn: undefined,
30-
dependant_locality: undefined,
31-
double_dependant_locality: undefined,
32-
thoroughfare: undefined,
33-
dependant_thoroughfare: undefined,
34-
building_number: undefined,
35-
building_name: undefined,
36-
sub_building_name: undefined,
37-
po_box: undefined,
38-
department_name: undefined,
39-
organisation_name: undefined,
40-
postcode_type: undefined,
41-
su_organisation_indicator: undefined,
42-
delivery_point_suffix: undefined
26+
postcode: "#postcode"
27+
// postcode_inward: undefined,
28+
// postcode_outward: undefined,
29+
// udprn: undefined,
30+
// dependant_locality: undefined,
31+
// double_dependant_locality: undefined,
32+
// thoroughfare: undefined,
33+
// dependant_thoroughfare: undefined,
34+
// building_number: undefined,
35+
// building_name: undefined,
36+
// sub_building_name: undefined,
37+
// po_box: undefined,
38+
// department_name: undefined,
39+
// organisation_name: undefined,
40+
// postcode_type: undefined,
41+
// su_organisation_indicator: undefined,
42+
// delivery_point_suffix: undefined
4343
},
4444

4545
/*
@@ -49,38 +49,38 @@
4949
endpoint: "https://api.ideal-postcodes.co.uk/v1",
5050

5151
// Input Field Configuration
52-
input: undefined,
53-
$input: undefined,
52+
// input: undefined,
53+
// $input: undefined,
5454
input_label: "Please enter your postcode",
5555
placeholder_label: "",
5656
input_muted_style: "color:#CBCBCB;",
5757
input_class: "",
5858
input_id: "idpc_input",
5959

6060
// Button configuration
61-
button: undefined,
62-
$button: undefined,
61+
// button: undefined,
62+
// $button: undefined,
6363
button_id: "idpc_button",
6464
button_label: "Find my Address",
6565
button_class: "",
6666
button_disabled_message: "Looking up postcode...",
6767

6868
// Dropdown configuration
69-
$dropdown: undefined,
69+
// $dropdown: undefined,
7070
dropdown_id: "idpc_dropdown",
7171
dropdown_select_message: "Please select your address",
7272
dropdown_class: "",
73-
dropdown_container: undefined,
73+
// dropdown_container: undefined,
7474

7575
// Error Message Configuration
76-
$error_message: undefined,
76+
// $error_message: undefined,
7777
error_message_id: "idpc_error_message",
7878
error_message_invalid_postcode: "Please check your postcode, it seems to be incorrect",
7979
error_message_not_found: "Your postcode could not be found. Please type in your address",
8080
error_message_address_not_found: "We could not find a match for your address. Please type in your address",
8181
error_message_default: "Sorry, we weren't able to get the address you were looking for. Please type your address manually",
8282
error_message_class: "",
83-
error_message_container: undefined,
83+
// error_message_container: undefined,
8484

8585
// Address search fallback - if enabled, postcode searches which fail validation will be forward to the Address search API
8686
address_search: false,
@@ -125,19 +125,19 @@
125125
},
126126

127127
// Register callbacks at specific stages
128-
onLoaded: undefined, // When plugin is initialised
129-
onFailedCheck: undefined, // When key check fails (requires check_key: true)
130-
onSearchCompleted: undefined, // When a lookup succeeds, E.g. Server responds that Postcode is found or doesn't exist
131-
onAddressesRetrieved: undefined, // When a lookup succeeds with a list of addresses
132-
onAddressSelected: undefined, // User has clicked an address in dropdown
133-
onDropdownCreated: undefined, // When the address selection dropdown is inserted to DOM
134-
onDropdownDestroyed: undefined, // When the address selection dropdown is removed (following new search)
135-
onLookupTriggered: undefined, // When user clicks the button to trigger a lookup
136-
shouldLookupTrigger: undefined, //
137-
onSearchError: undefined, // When a request succeeds but the API returns an error code
128+
// onLoaded: undefined, // When plugin is initialised
129+
// onFailedCheck: undefined, // When key check fails (requires check_key: true)
130+
// onSearchCompleted: undefined, // When a lookup succeeds, E.g. Server responds that Postcode is found or doesn't exist
131+
// onAddressesRetrieved: undefined, // When a lookup succeeds with a list of addresses
132+
// onAddressSelected: undefined, // User has clicked an address in dropdown
133+
// onDropdownCreated: undefined, // When the address selection dropdown is inserted to DOM
134+
// onDropdownDestroyed: undefined, // When the address selection dropdown is removed (following new search)
135+
// onLookupTriggered: undefined, // When user clicks the button to trigger a lookup
136+
// shouldLookupTrigger: undefined, //
137+
// onSearchError: undefined, // When a request succeeds but the API returns an error code
138138

139139
// Tags to be included with search requests
140-
tags: undefined
140+
// tags: undefined
141141
};
142142

143143
/*
@@ -188,9 +188,7 @@
188188
*
189189
* If a selector (this.input) is specified, that input is used
190190
* If no selector specified, a new input field is generated and added to context
191-
*
192191
*/
193-
194192
AddressFinderController.prototype.setupInputField = function () {
195193
var self = this;
196194
if ($(this.input).length) {
@@ -231,9 +229,7 @@
231229

232230
/*
233231
* Connects clickable element to the plugin to trigger
234-
*
235232
*/
236-
237233
AddressFinderController.prototype.setupLookupButton = function () {
238234
var self = this;
239235
if ($(self.button).length) {
@@ -280,7 +276,6 @@
280276
/*
281277
* Prevents lookup button from being triggered
282278
*/
283-
284279
AddressFinderController.prototype.disableLookup = function (message) {
285280
// Cancel if custom button
286281
if (this.button) {
@@ -293,7 +288,6 @@
293288
/*
294289
* Allows lookup button to be triggered
295290
*/
296-
297291
AddressFinderController.prototype.enableLookup = function () {
298292
// Cancel if custom button
299293
if (this.button) {
@@ -311,19 +305,15 @@
311305

312306
/*
313307
* Clears the following fields
314-
*
315308
*/
316-
317309
AddressFinderController.prototype.clearAll = function () {
318310
this.setDropDown();
319311
this.setErrorMessage();
320312
};
321313

322314
/*
323315
* Removes all elements from DOM
324-
*
325316
*/
326-
327317
AddressFinderController.prototype.removeAll = function () {
328318
this.$context = null;
329319

@@ -340,7 +330,6 @@
340330
* - On successful search but no addresses, show error message
341331
* - On failed search, show error message
342332
*/
343-
344333
AddressFinderController.prototype.executeSearch = function (term) {
345334
var self = this;
346335
var message;
@@ -386,12 +375,12 @@
386375
/*
387376
* Invoke postcode lookup
388377
*/
389-
390378
AddressFinderController.prototype.executePostcodeSearch = function (postcode, callback) {
391379
var self = this;
392380
var options = {
393381
query: postcode,
394-
api_key: self.api_key
382+
api_key: self.api_key,
383+
endpoint: self.endpoint
395384
};
396385

397386
if (self.tags) {
@@ -408,12 +397,12 @@
408397
/*
409398
* Invoke an address search
410399
*/
411-
412400
AddressFinderController.prototype.executeAddressSearch = function (query, callback) {
413401
var self = this;
414402
var options = {
415403
query: query,
416-
api_key: self.api_key
404+
api_key: self.api_key,
405+
endpoint: self.endpoint
417406
};
418407

419408
if (typeof self.address_search === "object") {
@@ -434,7 +423,6 @@
434423
/*
435424
* Caches search result with raw data object
436425
*/
437-
438426
AddressFinderController.prototype.cacheSearchResults = function (data) {
439427
if (data === null) {
440428
return null;
@@ -450,7 +438,6 @@
450438
*
451439
* Removes dropdown from DOM if data is undefined
452440
*/
453-
454441
AddressFinderController.prototype.setDropDown = function (data) {
455442
var self = this;
456443

@@ -528,7 +515,6 @@
528515
*
529516
* Removes error message from DOM if undefined
530517
*/
531-
532518
AddressFinderController.prototype.setErrorMessage = function (message) {
533519
if (this.$error_message && this.$error_message.length) {
534520
this.$error_message.remove();
@@ -561,7 +547,6 @@
561547
*
562548
* Empties output fields if undefined
563549
*/
564-
565550
AddressFinderController.prototype.setAddressFields = function (data) {
566551
data = data || {};
567552

@@ -590,14 +575,14 @@
590575
* - options.query: (string) Postcode to lookup, case and space insensitive
591576
* - options.api_key: (string) API Key required
592577
* - options.licensee: (string) Licensee key
578+
* - options.endpoint: (string) API endpoint
593579
* - success: (function) Callback invoked upon successful request
594580
* - error: (function) Optional callback invoked upon failed HTTP request
595581
*/
596-
597582
lookupPostcode: function (o, callback) {
598583
var postcode = o.query || o.postcode || "";
599584
var api_key = o.api_key || "";
600-
var endpoint = defaults.endpoint;
585+
var endpoint = o.endpoint || defaults.endpoint;
601586
var resource = "postcodes";
602587
var url = [endpoint, resource, encodeURI(postcode)].join('/');
603588
var queryString = {
@@ -647,14 +632,14 @@
647632
* - options.api_key: (string) API Key required
648633
* - options.licensee: (string) Licensee key
649634
* - options.limit: (number) Maximum number of addresses to return (default 10)
635+
* - options.endpoint: (string) API endpoint
650636
* - success: (function) Callback invoked upon successful request
651637
* - error: (function) Optional callback invoked upon failed HTTP request
652638
*/
653-
654639
lookupAddress: function (o, callback) {
655640
var query = o.query || "";
656641
var api_key = o.api_key || "";
657-
var endpoint = defaults.endpoint;
642+
var endpoint = o.endpoint || defaults.endpoint;
658643
var resource = "addresses";
659644
var url = [endpoint, resource].join('/');
660645
var queryString = {
@@ -703,10 +688,10 @@
703688
* - options: (object) Configuration object for key checking
704689
* - options.api_key: (string) API Key to test
705690
* - options.licensee: (string) Licensee key
691+
* - options.endpoint: (string) API endpoint
706692
* - success: (function) Callback invoked when key is available
707693
* - error: (function) Optional callback invoked when key is not available or HTTP request failed
708694
*/
709-
710695
checkKey: function (o, success, error) {
711696
var api_key = o.api_key || "";
712697

@@ -734,7 +719,7 @@
734719
};
735720
}
736721

737-
var endpoint = defaults.endpoint;
722+
var endpoint = o.endpoint || defaults.endpoint;
738723
var resource = "keys";
739724
var url = [endpoint, resource, api_key].join('/');
740725
var options = {
@@ -817,6 +802,9 @@
817802
// Check if key is usable if necessary
818803
if (options.check_key) {
819804
var keyOptions = { api_key: options.api_key };
805+
if (options.endpoint) {
806+
keyOptions.endpoint = options.endpoint;
807+
}
820808
if (options.licensee) {
821809
keyOptions.licensee = options.licensee;
822810
}

0 commit comments

Comments
 (0)