|
1 | | -/*! Ideal Postcodes jQuery Plugin - v3.0.4 - 2016-07-29 |
| 1 | +/*! Ideal Postcodes jQuery Plugin - v3.0.5 - 2017-11-16 |
2 | 2 | * https://github.com/ideal-postcodes/jquery.postcodes |
3 | | -2016 Ideal Postcodes; Licensed MIT */ |
| 3 | +2017 Ideal Postcodes; Licensed MIT */ |
4 | 4 | (function($) { |
5 | 5 | "use strict"; |
6 | 6 | // Cache for all new instances of the plugin |
|
52 | 52 | input: undefined, |
53 | 53 | $input: undefined, |
54 | 54 | input_label: "Please enter your postcode", |
| 55 | + placeholder_label: "", |
55 | 56 | input_muted_style: "color:#CBCBCB;", |
56 | 57 | input_class: "", |
57 | 58 | input_id: "idpc_input", |
|
130 | 131 | onAddressesRetrieved: undefined, // When a lookup succeeds with a list of addresses |
131 | 132 | onAddressSelected: undefined, // User has clicked an address in dropdown |
132 | 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) |
133 | 135 | onLookupTriggered: undefined, // When user clicks the button to trigger a lookup |
134 | 136 | shouldLookupTrigger: undefined, // |
135 | 137 | onSearchError: undefined, // When a request succeeds but the API returns an error code |
|
138 | 140 | tags: undefined |
139 | 141 | }; |
140 | 142 |
|
| 143 | + /* |
| 144 | + * Utility method to remove organisation from Address result |
| 145 | + * |
| 146 | + * All organisations will have their name as first line |
| 147 | + */ |
| 148 | + var removeOrganisation = function (address) { |
| 149 | + if (address.organisation_name.length !== 0 && |
| 150 | + (address.line_1 === address.organisation_name)) { |
| 151 | + // Shift addresses up |
| 152 | + address.line_1 = address.line_2; |
| 153 | + address.line_2 = address.line_3; |
| 154 | + address.line_3 = ""; |
| 155 | + } |
| 156 | + return address; |
| 157 | + }; |
| 158 | + |
141 | 159 | function AddressFinderController (options) { |
142 | 160 | // Load in defaults |
143 | 161 | this.config = {}; |
|
183 | 201 | this.$input = $('<input />', { |
184 | 202 | type: "text", |
185 | 203 | id: this.input_id, |
186 | | - value: this.input_label |
| 204 | + value: this.input_label, |
| 205 | + placeholder: this.placeholder_label |
187 | 206 | }) |
188 | 207 | .appendTo(this.$context) |
189 | 208 | .addClass(this.input_class) |
|
443 | 462 | if (this.$dropdown && this.$dropdown.length) { |
444 | 463 | this.$dropdown.remove(); |
445 | 464 | delete this.$dropdown; |
| 465 | + if (this.onDropdownDestroyed) { |
| 466 | + this.onDropdownDestroyed.call(this); |
| 467 | + } |
446 | 468 | } |
447 | 469 |
|
448 | 470 | if (!data) { |
|
548 | 570 | } |
549 | 571 | }; |
550 | 572 |
|
551 | | - /* |
552 | | - * Utility method to remove organisation from Address result |
553 | | - * |
554 | | - * All organisations will have their name as first line |
555 | | - */ |
556 | | - |
557 | | - var removeOrganisation = function (address) { |
558 | | - if (address.organisation_name.length !== 0 && |
559 | | - (address.line_1 === address.organisation_name)) { |
560 | | - // Shift addresses up |
561 | | - address.line_1 = address.line_2; |
562 | | - address.line_2 = address.line_3; |
563 | | - address.line_3 = ""; |
564 | | - } |
565 | | - return address; |
566 | | - }; |
567 | | - |
568 | 573 | var extractError = function (data) { |
569 | 574 | return data.code + " - " + data.message; |
570 | 575 | }; |
|
0 commit comments