PageSourceSearch

https://ambitec.cr/wp-content/plugins/ambitec-customizations/assets/js/main.js?ver=214920

js ambitec.cr collected 2026-10-05 04:53:17 UTC 11,687 bytes, 359 lines download raw bytes

1/**
2 * Masks for identification numbers and other fields
3 * 
4 * @version 2.1.0
5 */
6let masks = {
7    ced_fisica_mask: (obj) => obj.mask(
8        'Z-0000-0000', {
9            placeholder: '1-1111-1111',
10            translation: {
11                'Z': {
12                    pattern: /[1-9]/
13                }
14            }
15        }
16    ),
17    ced_juridica_mask: (obj) => obj.mask(
18        'Z-000-000000', {
19            placeholder: '1-111-111111',
20            translation: {
21                'Z': {
22                    pattern: /[1-9]/
23                }
24            }
25        }
26    ),
27    ced_dimex_mask: (obj) => obj.mask(
28        'Z00-000-000000', {
29            placeholder: '111-111-111111',
30            translation: {
31                'Z': {
32                    pattern: /[1-9]/
33                }
34            }
35        }
36    ),
37    // NITE min 10 & max 12 digits
38    ced_reset: (obj) => obj.mask(
39        'AAAAAAAAAAAA', {
40            placeholder: '111111111111'
41        }
42    ),
43    numbers_mask: (obj) => obj.mask(
44        'Z#', {
45            translation: {
46                'Z': {
47                    pattern: /[1-9]/
48                }
49            }
50        }
51    ),
52    unmask: (obj) => obj.unmask()
53}
54
55jQuery( ($) => {
56    const { __, _x, _n, _nx } = wp.i18n
57
58    setTimeout( () => {
59        if ( $('.product-image img').length ) {
60            $('.product-image img').removeAttr('style')
61        }
62    }, 2000 )
63
64    $(document).on( 'click', '.toggle-item', ( e ) => {
65        e.preventDefault()
66        
67        let _this = $( e.target ),
68        _key = _this.data( 'key' )
69        if ( !_this.hasClass( 'active' ) ) {
70            $( '.toggle-item' ).not( _this ).removeClass( 'active' )
71            _this.addClass('active')
72            $('.title-block').hide()
73            $('.title-block.' + _key + '-title').fadeIn('slow')
74
75            $('.ambct-products-body > div').hide()
76            $('.ambct-products-body #' + _key).fadeIn('slow')
77
78            // Fix lazyload
79            $('.ambct-products-body .archive-products .product-image img').height('auto')
80        }
81    } )
82
83    $(document).on( 'click', '#mobile-search-icon', (e) => {
84        e.preventDefault()
85        
86        let body = $(document.body)
87        body.addClass('mobile-search-open')
88    } )
89
90    $(document).on( 'click', '.close-search-wrapper', () => {
91        let body = $(document.body)
92        body.removeClass('mobile-search-open')
93
94        $('.aws-search-clear').trigger( 'click' )
95    } )
96
97    $(document).on( 'click', '#mobile-cart-icon', (e) => {
98        e.preventDefault()
99        
100        $('.xoo-wsc-sc-bki').trigger( 'click' )
101    } )
102
103    $(document).on( 'updated_checkout', () => {
104        if ( $('#ambct-shipping-restricted-areas').length ) {
105            
106            let modal_id = parseInt( $('#modal-checkout-id').val() )
107            if ( isNaN( modal_id ) === false ) {
108                elementorProFrontend.modules.popup.showPopup( {
109                    id: modal_id
110                } )
111            }
112            $('#restricted-areas-detail').html( '<span>' + $('#ambct-shipping-restricted-areas').val() + '</span>' )
113        }
114    } )
115
116    /**
117     * Fix bug from theme after add to cart
118     */
119    $( document.body ).on( 'added_to_cart', () => {
120        setTimeout( () => {
121            $( 'body' ).removeClass( 'has-side-open' )
122        }, 400 )
123    } )
124
125    /**
126     * Toggle in My Account Login/Register page
127     */
128    $( document ).on( 'click', '.btn-toggle-customer_login', () => {
129        $( '.account-column' ).slideToggle()
130    } )
131
132    /**
133     * Factura electronica
134     * 
135     * @version 2.1.0
136     * @since 1.0.2
137     */
138    let validate_identification_number = ( _this ) => {
139        let type = $('#identification_type').val()
140        let form_row = _this.closest('.form-row'),
141        value = _this.val()
142
143        if (
144            ( type === 'I' && value.length < 11 )
145            || ( type === 'C' && value.length < 12 )
146            || ( type === 'D' && value.length < 12 )
147            || ( type === 'N' && value.length < 10 )
148            || ( type === 'X' && value.length < 10 )
149            ) {
150            // FISICA & JURIDICA & DIMEX & NITE
151            form_row.addClass('woocommerce-invalid').removeClass('woocommerce-validated')
152        } else {
153            form_row.removeClass('woocommerce-invalid')
154        }
155    }
156    
157    /**
158     * @version 2.1.1
159     * @since 1.x
160     */
161    if ( $( '.woocommerce-checkout #identification_number' ).length
162        || $( '.woocommerce-account #identification_number' ).length ) {
163        let hide_lastname = () => {
164            if ( $('#billing_first_name_field.form-row-first').length ) {
165                let field = $('#billing_last_name_field')
166                field.find( '.optional, .required' ).remove()
167                field.removeClass( 'validate-required' )
168                field.hide()
169    
170                $('#billing_first_name_field').removeClass('form-row-first').addClass('form-row-wide')
171            }
172        }
173        // hide_lastname()
174
175        let show_lastname = () => {
176            let field = $('#billing_last_name_field.form-row-last')
177
178            if ( field.length && !field.is(':visible') ) {
179                field.find( '.optional, .required' ).remove()
180                field.addClass( 'validate-required' )
181                field.find( 'label' ).append( '<abbr class="required" title="obligatorio">*</abbr>' )
182                field.show()
183                
184                $('#billing_first_name_field').removeClass('form-row-wide').addClass('form-row-first')
185            }
186        }
187
188        /* Validacion caracteres cedula FE */
189        $(document).on( 'blur change validate', '#identification_number', (e) => {
190            let _this = $(e.target)
191            validate_identification_number( _this )
192        } )
193
194        if ( $('#identification_type').val() != '' ) {
195            setTimeout( () => {
196                $('#identification_type').trigger( 'change' )
197            }, 2000 )
198        }
199        
200        $(document).on( 'change', '#identification_type', (e) => {
201            let _this = $(e.target),
202            parent = _this.closest( 'div' ),
203            elm = parent.find( '.identification-number .input-text' ),
204            label = __( 'Nombre', 'ambct' )
205
206            show_lastname()
207            if ( _this.val() === 'I' ) {
208                // FISICA
209                masks.ced_fisica_mask( elm )
210            } else if ( _this.val() === 'C' ) {
211                // JURIDICA
212                label = __( 'Razón social', 'ambct' )
213                masks.ced_juridica_mask( elm )
214                hide_lastname()
215            } else if ( _this.val() === 'D' ) {
216                // DIMEX
217                masks.ced_dimex_mask( elm )
218            } else if ( _this.val() === 'X' ) {
219                // Pasaporte
220                // elm.unmask()
221                masks.unmask( elm )
222            } else {
223                // NITE
224                masks.ced_reset( elm )
225            }
226
227            $('#billing_first_name_field').find( 'label' ).text( label ).append( ' <abbr class="required" title="obligatorio">*</abbr>' )
228            $('#billing_first_name_field .input-text').attr('placeholder', label)
229        } )
230    }
231    
232    if ( $( '.ambct-factura-electronica' ).length ) {
233        $(document).on( 'change', '.ambct-factura-electronica', (e) => {
234            let _this = $(e.target),
235            parent = _this.closest( '.ambct-factura-electronica-wrapper' ),
236            fields = parent.find( '.ambct-factura-electronica-fields' ),
237            form_row = fields.find( '.form-row' )
238
239            form_row.find( '.optional, .required' ).remove()
240            
241            // if ( _this.prop( 'checked' ) === true ) {
242            if ( _this.val() == 1 ) {
243                fields.slideDown()
244                form_row.addClass( 'validate-required' )
245                form_row.find( 'label' ).append( '<abbr class="required" title="obligatorio">*</abbr>' )
246            } else {
247                form_row.removeClass( 'validate-required' )
248                form_row.find( '.required' ).remove()
249                fields.slideUp()
250            }
251        } )
252    }
253
254    /**
255     * Verify shipping info based on billing country
256     * 
257     * @version 1.0.7
258     * @since 1.0.x
259     */
260    let verify_shipping_info = (obj) => {
261        let checkbox = $('#ship-to-different-address-checkbox')
262
263        if ( obj.val() == 'US' ) {
264            checkbox.prop('checked', true).trigger('change')
265            checkbox.closest('label').addClass('disable-shipping-toggle')
266        } else {
267            checkbox.prop('checked', false).trigger('change')
268            checkbox.closest('label').removeClass('disable-shipping-toggle')
269        }
270    }
271
272    if ( $( '#billing_country' ).length ) {
273        verify_shipping_info( $( '#billing_country' ) )
274    
275        $( document ).on( 'change', '#billing_country', (e) => {
276            let _this = $(e.currentTarget)
277
278            verify_shipping_info( _this )
279        } )
280    }
281
282    /**
283     * @version 2.0.1
284     */
285    let add_product_to_gift_list = () => {
286        let btn_gift_list = $('.elementor-add-to-cart .nmgr-atw-add')
287
288        if ( btn_gift_list.length ) {
289            if ( -1 !== window.location.href.indexOf('trigger') ) {
290                setTimeout(() => {
291                    btn_gift_list.trigger('click')
292                }, 1200)
293            }
294        }
295    }
296
297    /**
298     * Fix reset filters reload with JS to force reload to the /tienda/ page
299     * 
300     * @version 2.2.0
301     */
302    let reset_filter_js = () => {
303        let active_filters = $('.active-filters-list')
304        active_filters.find('a').removeClass('js-product-filter-link')
305    }
306
307    // $('window').load(() => {
308    $(document).on('ready', () => {
309        reset_filter_js()
310        add_product_to_gift_list()
311    })
312
313    /**
314     * Toggle for category filters
315     * 
316     * @version 2.2.2
317     */
318    if ($('.tmcore-wp-widget-product-categories-layered-nav').length) {
319        if (!$('.wc-layered-nav-term').hasClass('chosen')) {
320            $('.tmcore-wp-widget-product-categories-layered-nav .widget-content-inner > ul.show-display-list > .wc-layered-nav-term').prepend('<span class="collapse collapse-close"></span>')
321            $('.tmcore-wp-widget-product-categories-layered-nav .widget-content-inner > ul.show-display-list .children').hide()
322    
323            $(document).on('click', '.wc-layered-nav-term span.collapse', (e) => {
324                e.preventDefault()
325                let _this = $(e.target)
326                _this.closest('.wc-layered-nav-term').find('.children').slideToggle()
327                _this.toggleClass('collapse-close')
328            })
329        }
330    }
331
332    /**
333     * Toggle map on shipping method change
334     * 
335     * @version 2.2.3
336     */
337    if ($('input.shipping_method').length) {    
338        let toggle_map_on_shipping_change = () => {
339            let _this = $('input.shipping_method:checked'), // $(e.currentTarget),
340            map_container = $('#lpac-map-container'),
341            map_save_address = $('#lpac_save_address_checkbox_field'),
342            cur_shipping = $(_this).val()
343    
344            if (cur_shipping === 'wc_pickup_store') {
345                $('#ship-to-different-address-checkbox').prop('checked', false).trigger('change')
346                map_container.addClass('hidden-map')
347                map_save_address.hide()
348            } else {
349                map_container.removeClass('hidden-map')
350                map_save_address.show()
351            }
352        }
353
354        $(document).on('change', 'input.shipping_method', (e) => {
355            toggle_map_on_shipping_change()
356        })
357        toggle_map_on_shipping_change()
358    }
359} );

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.