Plugin Directory

Changeset 2400284


Ignore:
Timestamp:
10/15/2020 04:04:06 PM (5 years ago)
Author:
spikkl
Message:

Remove disbled property from input fiels and remove referrer from admin

Location:
spikkl-address-lookup/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • spikkl-address-lookup/trunk/assets/js/spikkl-address-lookup.js

    r2365100 r2400284  
    3535            this.reorderFields( selectedCountryCode );
    3636            this.listen( selectedCountryCode );
    37             this.applyFieldsLock();
    3837        });
    3938
     
    5150
    5251            });
     52
     53            this.applyFieldsLock();
     54
    5355        } else {
    5456            $.each( interactionElements, ( index, el ) => {
     
    6769
    6870        this.$street.attr( 'disabled', true );
    69         this.$city.attr( 'disabled', true );
     71        this.$city.prop( 'disabled', true );
    7072        this.$state.attr( 'disabled', true );
    7173    };
     
    7880        this.$city.removeAttr( 'disabled'  );
    7981        this.$state.removeAttr( 'disabled' );
     82
     83        console.log(this.$city.prop( 'disabled', false ));
    8084    };
    8185
     
    311315    };
    312316
    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
    326334});
  • 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)});
     1jQuery(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  
    5151                </tr>
    5252
    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 
    7053            </tbody>
    7154        </table>
  • spikkl-address-lookup/trunk/includes/integrations/spikkl-woocommerce-integration.php

    r2365100 r2400284  
    9999            }
    100100
    101             $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
     101            $suffix = '';
     102
     103            //$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
    102104
    103105            wp_register_script( 'spikkl_address_lookup', plugins_url( '/assets/js/spikkl-address-lookup' . $suffix . '.js', SPIKKL_PLUGIN_FILE ), array( 'jquery', 'woocommerce' ) );
     
    131133            }
    132134
    133             $fields['address_2']['class'][] = 'form-row-first';
    134 
    135135            $fields['address_3'] = array(
    136136                'label'        => __( 'Street number suffix', 'woocommerce' ),
     
    158158                ),
    159159                'address_2' => array(
     160                    'class' => array( 'form-row-first' ),
    160161                    'priority' => 50,
    161162                    'placeholder' => '',
     
    163164                ),
    164165                'address_3' => array(
    165                     'priority' => 55,
     166                    'priority' => 55
    166167                ),
    167168                'address_1' => array(
    168169                    'priority' => 70,
    169                     'placeholder' => ''
     170                    'placeholder' => '',
     171                    'required' => true
    170172                ),
    171173                'city' => array(
    172                     'priority' => 80
     174                    'priority' => 80,
     175                    'required' => true
    173176                ),
    174177                'state' => array(
     
    182185
    183186        public function perform_lookup() {
    184             if ( $this->_settings->validate_referrer() ) {
    185                 $this->validate_referrer();
    186             }
     187            $this->validate_referrer();
    187188
    188189            if ( empty( $_GET[ 'postal_code' ] ) || empty( $_GET[ 'street_number' ] ) ) {
     
    233234            ));
    234235
    235             if ($response instanceof WP_Error || ! in_array( $response[ 'response' ][ 'code' ], [ 200, 400 ], true ) ) {
     236            if ($response instanceof WP_Error || ! in_array( $response[ 'response' ][ 'code' ], [ 200, 404 ], true ) ) {
    236237                $this->error_occurred( 'UNAVAILABLE' );
    237238            } else {
  • spikkl-address-lookup/trunk/includes/spikkl-settings.php

    r2313054 r2400284  
    2222        public $is_enabled = '0';
    2323
    24         public $validate_referrer = '0';
    25 
    2624        protected static $_instance;
    2725
     
    3129            if ( isset( $current_settings[ 'is_enabled' ] ) ) {
    3230                $this->is_enabled = $current_settings[ 'is_enabled' ];
    33             }
    34 
    35             if ( isset( $current_settings[ 'validate_referrer' ] ) ) {
    36                 $this->validate_referrer = $current_settings[ 'validate_referrer' ];
    3731            }
    3832
     
    6155            return (bool) $this->is_enabled;
    6256        }
    63 
    64         public function validate_referrer() {
    65             return (bool) $this->validate_referrer;
    66         }
    6757    }
    6858}
  • spikkl-address-lookup/trunk/readme.txt

    r2365506 r2400284  
    11=== Spikkl Address Lookup ===
    22Contributors: Spikkl
    3 Tags: postcode, address validation, checkout, billing, shipping, address, address verification, lookup, postcode api, online service
     3Tags: postcode, address validation, checkout, billing, shipping, address, address verification, lookup, postcode api, online service, postcode check, woocommerce
    44Requires at least: 4.4
    55Tested up to: 5.5
    6 Stable tag: 1.1.1
     6Stable tag: 1.3.2
    77Requires PHP: 5.6
    88License: GPLv3
     
    56561. Install the Spikkl Address Lookup using the Wordpress plugin repository.
    57572. Simple settings interface to add your Spikkl API key.
     583. Checkout page with default WooCommerce template.
    5859
    5960== Changelog ==
     
    6970= 1.1.1 =
    7071* 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  
    1111 *  Plugin URI: https://www.spikkl.nl/modules
    1212 *  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.1
     13 *  Version: 1.3.2
    1414 *  Author: Spikkl
    1515 *  Author URI: https://www.spikkl.nl/
Note: See TracChangeset for help on using the changeset viewer.