Changeset 2400284
- Timestamp:
- 10/15/2020 04:04:06 PM (5 years ago)
- Location:
- spikkl-address-lookup/trunk
- Files:
-
- 7 edited
-
assets/js/spikkl-address-lookup.js (modified) (5 diffs)
-
assets/js/spikkl-address-lookup.min.js (modified) (1 diff)
-
includes/admin/spikkl-admin-template.php (modified) (1 diff)
-
includes/integrations/spikkl-woocommerce-integration.php (modified) (6 diffs)
-
includes/spikkl-settings.php (modified) (3 diffs)
-
readme.txt (modified) (3 diffs)
-
spikkl-address-lookup.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
spikkl-address-lookup/trunk/assets/js/spikkl-address-lookup.js
r2365100 r2400284 35 35 this.reorderFields( selectedCountryCode ); 36 36 this.listen( selectedCountryCode ); 37 this.applyFieldsLock();38 37 }); 39 38 … … 51 50 52 51 }); 52 53 this.applyFieldsLock(); 54 53 55 } else { 54 56 $.each( interactionElements, ( index, el ) => { … … 67 69 68 70 this.$street.attr( 'disabled', true ); 69 this.$city. attr( 'disabled', true );71 this.$city.prop( 'disabled', true ); 70 72 this.$state.attr( 'disabled', true ); 71 73 }; … … 78 80 this.$city.removeAttr( 'disabled' ); 79 81 this.$state.removeAttr( 'disabled' ); 82 83 console.log(this.$city.prop( 'disabled', false )); 80 84 }; 81 85 … … 311 315 }; 312 316 313 /** 314 * Init LookupHandler when billing fields are set. 315 */ 316 if ( typeof spikkl_billing_fields !== 'undefined' ) { 317 new LookupHandler( spikkl_billing_fields ); 318 } 319 320 /** 321 * Init LookupHandler when billing fields are set. 322 */ 323 if ( typeof spikkl_shipping_fields !== 'undefined' ) { 324 new LookupHandler( spikkl_shipping_fields ); 325 } 317 318 $( document.body ).bind('wc_address_i18n_ready', function () { 319 /** 320 * Init LookupHandler when billing fields are set. 321 */ 322 if ( typeof spikkl_billing_fields !== 'undefined' ) { 323 new LookupHandler( spikkl_billing_fields ); 324 } 325 326 /** 327 * Init LookupHandler when billing fields are set. 328 */ 329 if ( typeof spikkl_shipping_fields !== 'undefined' ) { 330 new LookupHandler( spikkl_shipping_fields ); 331 } 332 }); 333 326 334 }); -
spikkl-address-lookup/trunk/assets/js/spikkl-address-lookup.min.js
r2365100 r2400284 1 jQuery(function(e){if("undefined"==typeof spikkl_params)return!1;const t=new RegExp(""),s=new RegExp(""),i=new RegExp(""),r=function(t){this.cache={},this.lookupTimeout=null,this.prefix=t.prefix,this.$country=e(t.country),this.$state=e(t.state),this.$city=e(t.city),this.$street=e(t.street),this.$postcode=e(t.postcode),this.$streetNumber=e(t.street_number),this.$streetNumberSuffix=e(t.street_number_suffix),this.setHelperElements(),this.$country.on("change",()=>{let e=this.getSelectedCountryCode();this.reorderFields(e),this.listen(e) ,this.applyFieldsLock()}),this.$country.trigger("change")};r.prototype.listen=function(t){const s=[this.$postcode,this.$streetNumber,this.$streetNumberSuffix];this.isCountryEligibleForLookup(t)?e.each(s,(t,s)=>{e(s).on("keyup",this.delayedLookup.bind(this)),e(s).on("blur",this.performLookup.bind(this))}):(e.each(s,(e,t)=>{t.off("keyup"),t.off("blur")}),this.hardResetFields(),this.releaseFieldsLock())},r.prototype.applyFieldsLock=function(){this.$postcode.attr("autocomplete","off"),this.$postcode.attr("maxlength",7),this.$street.attr("disabled",!0),this.$city.attr("disabled",!0),this.$state.attr("disabled",!0)},r.prototype.releaseFieldsLock=function(){this.$postcode.removeAttr("autocomplete"),this.$postcode.removeAttr("maxlength"),this.$street.removeAttr("disabled"),this.$city.removeAttr("disabled"),this.$state.removeAttr("disabled")},r.prototype.softResetFields=function(){this.$street.val(""),this.$city.val(""),this.$state.val("").trigger("change"),void 0!==this.$spinner&&this.$spinner.hide()},r.prototype.hardResetFields=function(){this.$postcode.val(""),this.$streetNumber.val(""),this.$streetNumberSuffix.val(""),void 0!==this.$message&&this.$message.hide(),this.softResetFields()},r.prototype.delayedLookup=function(){clearTimeout(this.lookupTimeout),this.lookupTimeout=setTimeout(()=>{this.performLookup()},350)},r.prototype.performLookup=function(){const e=this.$postcode.val(),t=this.$streetNumber.val(),s=this.$streetNumberSuffix.val();if(this.isValidPostcode()&&this.isValidStreetNumber()&&this.isValidStreetNumberSuffix()){this.$spinner.show(),this.$message.hide();const i={action:spikkl_params.action,postal_code:encodeURIComponent(e),street_number:encodeURIComponent(t),street_number_suffix:encodeURIComponent(s)};this.cachedGet(i)}else this.softResetFields()},r.prototype.cachedGet=function(t){const s=spikkl_params.url+JSON.stringify(Object.values(t));this.cache.hasOwnProperty(s)?this.fillFields(this.cache[s]):e.ajax({crossDomain:!0,type:"GET",dataType:"json",timeout:5e3,url:spikkl_params.url,data:t,success:(e,t)=>{if(!e||"success"!==t)return this.fillFields({status:"failed",status_code:"UNAVAILABLE"}),void this.releaseFieldsLock();this.cache[s]=e,this.fillFields(e)}})},r.prototype.fillFields=function(e){if(this.$spinner.hide(),"ok"===e.status&&e.results.length>=1)this.$street.val(e.results[0].street_name),this.$city.val(e.results[0].city),this.$state.val(e.results[0].administrative_areas[0].abbreviation).trigger("change");else{let t;"ZERO_RESULTS"===e.status_code&&(t=spikkl_params.errors.invalid_address),"INVALID_REQUEST"===e.status_code&&(t=spikkl_params.errors.invalid_postal_code_or_street_number),"UNAVAILABLE"!==e.status_code&&"ACCESS_RESTRICTED"!==e.status_code||(t=spikkl_params.errors.unknown_error,this.releaseFieldsLock()),this.softResetFields(),this.$message.empty().append("<li>"+t+"</li>"),this.$message.show()}},r.prototype.isValidPostcode=function(){const e=this.$postcode.val();return null!==e&&""!==e&&(!!t.test(e)||(this.$message.empty().append("<li>"+spikkl_params.errors.invalid_postal_code+"</li>"),this.$message.show(),!1))},r.prototype.isValidStreetNumber=function(){const e=this.$streetNumber.val();return null!==e&&""!==e&&(!!s.test(e)||(this.$message.empty().append("<li>"+spikkl_params.errors.invalid_street_number+"</li>"),this.$message.show(),!1))},r.prototype.isValidStreetNumberSuffix=function(){const e=this.$streetNumberSuffix.val();return!!i.test(e)||(this.$message.empty().append("<li>"+spikkl_params.errors.invalid_street_number_suffix+"</li>"),this.$message.show(),!1)},r.prototype.setHelperElements=function(){this.$spinner=e("<div>",{id:"spikkl-"+this.prefix+"-spinner",class:"spikkl-loader",style:"display:none;"}),this.$message=e("<ul>",{id:"spikkl-"+this.prefix+"-message",class:"woocommerce-error",style:"display:none;"}),this.$postcode.after(this.$spinner),this.$postcode.before(this.$message)},r.prototype.reorderFields=function(e){const t=this.$streetNumber.closest("p.form-row"),s=this.$streetNumberSuffix.closest("p.form-row");this.isCountryEligibleForLookup(e)?(this.createStreetNumberLabel(),t.removeClass("form-row-wide").addClass("form-row-first"),s.show()):(t.removeClass("form-row-first").addClass("form-row-wide"),s.hide(),t.find("label").remove())},r.prototype.createStreetNumberLabel=function(){const t=this.$streetNumber.attr("id"),s='<abbr title="'+("undefined"!==woocommerce_params.i18n_required_text?woocommerce_params.i18n_required_text:"required")+'" class="required"> * </abbr>',i=e('label[for="'+t+'"]');i.length?e('label[for="'+t+'"] > abbr').length||i.append(s):this.$streetNumber.before('<label for="'+t+'">'+spikkl_params.street_number_label+s+"</label>")},r.prototype.getSelectedCountryCode=function(){return e(this.$country.selector+" :selected").val().trim()},r.prototype.isCountryEligibleForLookup=function(e){return e=e||this.getSelectedCountryCode(),spikkl_params.supported_countries.indexOf(e)>=0},"undefined"!=typeof spikkl_billing_fields&&new r(spikkl_billing_fields),"undefined"!=typeof spikkl_shipping_fields&&new r(spikkl_shipping_fields)});1 jQuery(function(e){if("undefined"==typeof spikkl_params)return!1;const t=new RegExp(""),s=new RegExp(""),i=new RegExp(""),r=function(t){this.cache={},this.lookupTimeout=null,this.prefix=t.prefix,this.$country=e(t.country),this.$state=e(t.state),this.$city=e(t.city),this.$street=e(t.street),this.$postcode=e(t.postcode),this.$streetNumber=e(t.street_number),this.$streetNumberSuffix=e(t.street_number_suffix),this.setHelperElements(),this.$country.on("change",()=>{let e=this.getSelectedCountryCode();this.reorderFields(e),this.listen(e)}),this.$country.trigger("change")};r.prototype.listen=function(t){const s=[this.$postcode,this.$streetNumber,this.$streetNumberSuffix];this.isCountryEligibleForLookup(t)?(e.each(s,(t,s)=>{e(s).on("keyup",this.delayedLookup.bind(this)),e(s).on("blur",this.performLookup.bind(this))}),this.applyFieldsLock()):(e.each(s,(e,t)=>{t.off("keyup"),t.off("blur")}),this.hardResetFields(),this.releaseFieldsLock())},r.prototype.applyFieldsLock=function(){this.$postcode.attr("autocomplete","off"),this.$postcode.attr("maxlength",7),this.$street.attr("disabled",!0),this.$city.prop("disabled",!0),this.$state.attr("disabled",!0)},r.prototype.releaseFieldsLock=function(){this.$postcode.removeAttr("autocomplete"),this.$postcode.removeAttr("maxlength"),this.$street.removeAttr("disabled"),this.$city.removeAttr("disabled"),this.$state.removeAttr("disabled"),console.log(this.$city.prop("disabled",!1))},r.prototype.softResetFields=function(){this.$street.val(""),this.$city.val(""),this.$state.val("").trigger("change"),void 0!==this.$spinner&&this.$spinner.hide()},r.prototype.hardResetFields=function(){this.$postcode.val(""),this.$streetNumber.val(""),this.$streetNumberSuffix.val(""),void 0!==this.$message&&this.$message.hide(),this.softResetFields()},r.prototype.delayedLookup=function(){clearTimeout(this.lookupTimeout),this.lookupTimeout=setTimeout(()=>{this.performLookup()},350)},r.prototype.performLookup=function(){const e=this.$postcode.val(),t=this.$streetNumber.val(),s=this.$streetNumberSuffix.val();if(this.isValidPostcode()&&this.isValidStreetNumber()&&this.isValidStreetNumberSuffix()){this.$spinner.show(),this.$message.hide();const i={action:spikkl_params.action,postal_code:encodeURIComponent(e),street_number:encodeURIComponent(t),street_number_suffix:encodeURIComponent(s)};this.cachedGet(i)}else this.softResetFields()},r.prototype.cachedGet=function(t){const s=spikkl_params.url+JSON.stringify(Object.values(t));this.cache.hasOwnProperty(s)?this.fillFields(this.cache[s]):e.ajax({crossDomain:!0,type:"GET",dataType:"json",timeout:5e3,url:spikkl_params.url,data:t,success:(e,t)=>{if(!e||"success"!==t)return this.fillFields({status:"failed",status_code:"UNAVAILABLE"}),void this.releaseFieldsLock();this.cache[s]=e,this.fillFields(e)}})},r.prototype.fillFields=function(e){if(this.$spinner.hide(),"ok"===e.status&&e.results.length>=1)this.$street.val(e.results[0].street_name),this.$city.val(e.results[0].city),this.$state.val(e.results[0].administrative_areas[0].abbreviation).trigger("change");else{let t;"ZERO_RESULTS"===e.status_code&&(t=spikkl_params.errors.invalid_address),"INVALID_REQUEST"===e.status_code&&(t=spikkl_params.errors.invalid_postal_code_or_street_number),"UNAVAILABLE"!==e.status_code&&"ACCESS_RESTRICTED"!==e.status_code||(t=spikkl_params.errors.unknown_error,this.releaseFieldsLock()),this.softResetFields(),this.$message.empty().append("<li>"+t+"</li>"),this.$message.show()}},r.prototype.isValidPostcode=function(){const e=this.$postcode.val();return null!==e&&""!==e&&(!!t.test(e)||(this.$message.empty().append("<li>"+spikkl_params.errors.invalid_postal_code+"</li>"),this.$message.show(),!1))},r.prototype.isValidStreetNumber=function(){const e=this.$streetNumber.val();return null!==e&&""!==e&&(!!s.test(e)||(this.$message.empty().append("<li>"+spikkl_params.errors.invalid_street_number+"</li>"),this.$message.show(),!1))},r.prototype.isValidStreetNumberSuffix=function(){const e=this.$streetNumberSuffix.val();return!!i.test(e)||(this.$message.empty().append("<li>"+spikkl_params.errors.invalid_street_number_suffix+"</li>"),this.$message.show(),!1)},r.prototype.setHelperElements=function(){this.$spinner=e("<div>",{id:"spikkl-"+this.prefix+"-spinner",class:"spikkl-loader",style:"display:none;"}),this.$message=e("<ul>",{id:"spikkl-"+this.prefix+"-message",class:"woocommerce-error",style:"display:none;"}),this.$postcode.after(this.$spinner),this.$postcode.before(this.$message)},r.prototype.reorderFields=function(e){const t=this.$streetNumber.closest("p.form-row"),s=this.$streetNumberSuffix.closest("p.form-row");this.isCountryEligibleForLookup(e)?(this.createStreetNumberLabel(),t.removeClass("form-row-wide").addClass("form-row-first"),s.show()):(t.removeClass("form-row-first").addClass("form-row-wide"),s.hide(),t.find("label").remove())},r.prototype.createStreetNumberLabel=function(){const t=this.$streetNumber.attr("id"),s='<abbr title="'+("undefined"!==woocommerce_params.i18n_required_text?woocommerce_params.i18n_required_text:"required")+'" class="required"> * </abbr>',i=e('label[for="'+t+'"]');i.length?e('label[for="'+t+'"] > abbr').length||i.append(s):this.$streetNumber.before('<label for="'+t+'">'+spikkl_params.street_number_label+s+"</label>")},r.prototype.getSelectedCountryCode=function(){return e(this.$country.selector+" :selected").val().trim()},r.prototype.isCountryEligibleForLookup=function(e){return e=e||this.getSelectedCountryCode(),spikkl_params.supported_countries.indexOf(e)>=0},e(document.body).bind("wc_address_i18n_ready",function(){"undefined"!=typeof spikkl_billing_fields&&new r(spikkl_billing_fields),"undefined"!=typeof spikkl_shipping_fields&&new r(spikkl_shipping_fields)})}); -
spikkl-address-lookup/trunk/includes/admin/spikkl-admin-template.php
r2313054 r2400284 51 51 </tr> 52 52 53 <tr class="option-lookup-enabled">54 <th scope="row"><?php _e( 'Security settings', 'spikkl' ); ?></th>55 <td>56 <fieldset>57 <legend class="screen-reader-text">58 <span><?php _e( 'Security settings', 'spikkl' ); ?></span>59 </legend>60 <label for="spikkl_settings_validate_referrer">61 <input name="spikkl_settings[validate_referrer]" type="checkbox" id="spikkl_settings_validate_referrer" value="1" <?php checked( true, $this->_settings->validate_referrer() ); ?> >62 <span><?php _e( 'Validate referrer', 'spikkl' ); ?></span>63 </label>64 <br>65 <p class="description"><?php vprintf( __( 'Enable site domain validation of each request. Additional restrictions of the referrer need to be configured on the <a href="%s" target="_blank">Spikkl credentials page</a>.', 'spikkl' ), array( 'https://www.spikkl.nl/account/credentials' )); ?></p>66 </fieldset>67 </td>68 </tr>69 70 53 </tbody> 71 54 </table> -
spikkl-address-lookup/trunk/includes/integrations/spikkl-woocommerce-integration.php
r2365100 r2400284 99 99 } 100 100 101 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; 101 $suffix = ''; 102 103 //$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; 102 104 103 105 wp_register_script( 'spikkl_address_lookup', plugins_url( '/assets/js/spikkl-address-lookup' . $suffix . '.js', SPIKKL_PLUGIN_FILE ), array( 'jquery', 'woocommerce' ) ); … … 131 133 } 132 134 133 $fields['address_2']['class'][] = 'form-row-first';134 135 135 $fields['address_3'] = array( 136 136 'label' => __( 'Street number suffix', 'woocommerce' ), … … 158 158 ), 159 159 'address_2' => array( 160 'class' => array( 'form-row-first' ), 160 161 'priority' => 50, 161 162 'placeholder' => '', … … 163 164 ), 164 165 'address_3' => array( 165 'priority' => 55 ,166 'priority' => 55 166 167 ), 167 168 'address_1' => array( 168 169 'priority' => 70, 169 'placeholder' => '' 170 'placeholder' => '', 171 'required' => true 170 172 ), 171 173 'city' => array( 172 'priority' => 80 174 'priority' => 80, 175 'required' => true 173 176 ), 174 177 'state' => array( … … 182 185 183 186 public function perform_lookup() { 184 if ( $this->_settings->validate_referrer() ) { 185 $this->validate_referrer(); 186 } 187 $this->validate_referrer(); 187 188 188 189 if ( empty( $_GET[ 'postal_code' ] ) || empty( $_GET[ 'street_number' ] ) ) { … … 233 234 )); 234 235 235 if ($response instanceof WP_Error || ! in_array( $response[ 'response' ][ 'code' ], [ 200, 40 0], true ) ) {236 if ($response instanceof WP_Error || ! in_array( $response[ 'response' ][ 'code' ], [ 200, 404 ], true ) ) { 236 237 $this->error_occurred( 'UNAVAILABLE' ); 237 238 } else { -
spikkl-address-lookup/trunk/includes/spikkl-settings.php
r2313054 r2400284 22 22 public $is_enabled = '0'; 23 23 24 public $validate_referrer = '0';25 26 24 protected static $_instance; 27 25 … … 31 29 if ( isset( $current_settings[ 'is_enabled' ] ) ) { 32 30 $this->is_enabled = $current_settings[ 'is_enabled' ]; 33 }34 35 if ( isset( $current_settings[ 'validate_referrer' ] ) ) {36 $this->validate_referrer = $current_settings[ 'validate_referrer' ];37 31 } 38 32 … … 61 55 return (bool) $this->is_enabled; 62 56 } 63 64 public function validate_referrer() {65 return (bool) $this->validate_referrer;66 }67 57 } 68 58 } -
spikkl-address-lookup/trunk/readme.txt
r2365506 r2400284 1 1 === Spikkl Address Lookup === 2 2 Contributors: Spikkl 3 Tags: postcode, address validation, checkout, billing, shipping, address, address verification, lookup, postcode api, online service 3 Tags: postcode, address validation, checkout, billing, shipping, address, address verification, lookup, postcode api, online service, postcode check, woocommerce 4 4 Requires at least: 4.4 5 5 Tested up to: 5.5 6 Stable tag: 1. 1.16 Stable tag: 1.3.2 7 7 Requires PHP: 5.6 8 8 License: GPLv3 … … 56 56 1. Install the Spikkl Address Lookup using the Wordpress plugin repository. 57 57 2. Simple settings interface to add your Spikkl API key. 58 3. Checkout page with default WooCommerce template. 58 59 59 60 == Changelog == … … 69 70 = 1.1.1 = 70 71 * Unify release information 72 73 = 1.3.0 = 74 * Remove disabled property from input fields when changing country during checkout 75 * Validate referrer by default and remove administrator setting 76 77 = 1.3.2 = 78 * Minor changes in Readme.txt -
spikkl-address-lookup/trunk/spikkl-address-lookup.php
r2365504 r2400284 11 11 * Plugin URI: https://www.spikkl.nl/modules 12 12 * Description: Spikkl Address Lookup validates the Dutch postcode and street number combination during checkout and fills additional address values automatically. Increase the ease-of-use for each of your customers and be assured of up-to-date and valid address data. 13 * Version: 1. 1.113 * Version: 1.3.2 14 14 * Author: Spikkl 15 15 * Author URI: https://www.spikkl.nl/
Note: See TracChangeset
for help on using the changeset viewer.