PageSourceSearch

https://indiawest.com/wp-content/plugins/easy-contact-form-builder/assets/js/frontend/main.js?ver=7.1.2

js indiawest.com collected 2026-10-01 08:50:55 UTC 24,391 bytes, 641 lines download raw bytes

1jQuery('.form_loading_icon').on('click', function(){
2    return false;
3});
4
5jQuery(window).on('load', function(){
6    jQuery('.form_loading_icon').css('display', 'none');
7});
8
9jQuery(document).ready(function() {
10
11    function isValidEmailAddress(emailAddress) {
12        var pattern = new RegExp(/^(("[\w-+\s]+")|([\w-+]+(?:\.[\w-+]+)*)|("[\w-+\s]+")([\w-+]+(?:\.[\w-+]+)*))(@((?:[\w-+]+\.)*\w[\w-+]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][\d]\.|1[\d]{2}\.|[\d]{1,2}\.))((25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\.){2}(25[0-5]|2[0-4][\d]|1[\d]{2}|[\d]{1,2})\]?$)/i);
13        return pattern.test(emailAddress);
14    }
15
16
17    jQuery('.gdfrm-required input,.gdfrm-required textarea,.gdfrm-required select').each(function(){
18        var _this = jQuery(this);
19
20        if(! _this.hasClass('gdfrm-quantity')){
21            _this.shake = function () {
22                _this.on('blur',function () {
23                    setTimeout(function(){
24                        if(_this.val()==''){
25                            _this.effect( "shake", { direction: "up", times: 2, distance: 5}, 500 );
26                            _this.addClass('user-error');
27                        } else{
28                            _this.removeClass('user-error');
29                        }
30                    },100);
31
32                })
33            }
34
35            _this.stateChange = function () {
36                _this.on('change',function () {
37                    if(_this.val()!==''){
38                        _this.removeClass('user-error');
39                        _this.siblings('.error-block').text('');
40                    }
41                })
42            }
43
44            setTimeout(function(){
45                _this.shake();
46                _this.stateChange();
47            },100);
48        }
49    });
50
51    jQuery('.gdfrm-form-field.hidden input,.gdfrm-form-field.hidden textarea').on('focus',function(){
52        var _this = jQuery(this);
53
54        _this.closest('.gdfrm-form-field').addClass('field-focus');
55    });
56
57    jQuery('.gdfrm-form-field.hidden .hidden-placeholder').on('click',function(){
58        var _this = jQuery(this);
59
60        _this.closest('.gdfrm-form-field').find('input,textarea').focus();
61    });
62
63
64
65
66
67
68
69    function validateInputs(obj){
70        var success = true;
71        var form_cont_id = obj.attr('id');
72
73        var required_empty_error = jQuery('#'+form_cont_id).children('.required-empty-error').val();
74        if(required_empty_error == '') required_empty_error = 'This field is required';
75
76        var email_format_error = jQuery('#'+form_cont_id).children('.email-format-error').val();
77        if(email_format_error == '') email_format_error = 'Wrong Email Format';
78
79        var upload_size_error = jQuery('#'+form_cont_id).children('.upload-size-error').val();
80        if(upload_size_error == '') upload_size_error = 'Max Upload Size Exceeded';
81
82        var file_format_error = jQuery('#'+form_cont_id).children('.file-format-error').val();
83        if(file_format_error == '') file_format_error = 'Wrong File Format';
84
85
86            /* validate required fields */
87        jQuery('#'+form_cont_id+' .gdfrm-required').each(function () {
88            var Field ;
89            var _this = jQuery(this);
90
91            if(_this.hasClass('gdfrm-checkbox') || jQuery(this).hasClass('gdfrm-imageselect')){
92                Field = _this.find('input[type=checkbox]');
93
94                var field_name = Field.attr('name');
95
96                if(!Field.is(':checked')){
97                    success = false;
98                    _this.addClass('empty');
99                    _this.find('.error-block').text(required_empty_error).show();
100                }
101            } else{
102                Field = jQuery(this).find('div').find('input,textarea,select');
103                if( Field.val()=='' ){
104                    success = false;
105                    _this.addClass('empty');
106                    _this.find('.error-block').text(required_empty_error).show();
107                }
108            }
109        })
110
111        /* validate email fields */
112        jQuery('#'+form_cont_id+' .email').each(function () {
113            var emailField = jQuery(this).find('input[type=email]');
114
115            if(!isValidEmailAddress(emailField.val())){
116                success = false;
117                jQuery(this).find('.error-block').text(email_format_error).show();
118            }
119        })
120
121        /* validate max selected checkboxes */
122        jQuery('.gdfrm-checkbox-options').each(function () {
123            var max_sel = jQuery(this).attr('data-max-sel');
124
125            var options_number = jQuery(this).find('.gdfrm-checkbox-option').length;
126
127            if( max_sel > options_number ) max_sel = options_number;
128
129            if( max_sel > 0 ){
130                    var selected = jQuery(this).find('input[type="checkbox"]:checked').length;
131
132                    if( selected > max_sel ){
133                        success = false;
134                        jQuery(this).next('.error-block').text('You can select max '+max_sel+' option(s)').show();
135                    }
136
137            }
138        })
139
140        return success;
141    }
142
143    /* checkbox option select */
144    jQuery('.gdfrm-checkbox-option input[type=checkbox]').on('change',function (e) {
145        var max_sel = jQuery(this).closest('.gdfrm-checkbox-options').attr('data-max-sel');
146        var _this_cont = jQuery(this).closest('.gdfrm-checkbox-option');
147        var _this = jQuery(this);
148
149        var already_selected = jQuery(this).closest('.gdfrm-checkbox-options').find('input[type="checkbox"]:checked').length;
150
151        if( max_sel < already_selected && max_sel>0){
152            _this.attr('checked',false);
153            _this_cont.removeClass('gdfrm-selected');
154
155            alert('You can select only '+max_sel+' option(s)');
156        } else {
157            _this_cont.toggleClass('selected');
158        }
159    })
160
161
162    /* form submit */
163    jQuery('.gdfrm-form').on("submit",function (e) {
164        e.preventDefault();
165        var form = jQuery(this);
166        var button = form.find('input[type=submit]');
167        var button_text = button.val();
168        var form_id = form.attr('form-id');
169
170        var validateSuccess = validateInputs(form);
171
172        if(validateSuccess){
173
174            var formData = new FormData();
175
176            var files = jQuery('.gdfrm-inputfile');
177
178            var postData = form.serialize();
179
180            var paypalForm = jQuery('#paypal-form-'+form_id);
181
182            jQuery.each(jQuery(files), function(i, obj) {
183                jQuery.each(obj.files,function(j,file){
184                    formData.append(obj.name, file);
185                })
186            });
187
188            formData.append('action', 'gdfrm_submit_form');
189            formData.append('form_id', form_id);
190            formData.append('postData', postData);
191
192            jQuery.ajax({
193                type: 'POST',
194                url: ajaxurl,
195                data : formData,
196                contentType: false,
197                processData: false,
198                beforeSend: function(){
199
200                    button.unbind( "click" );
201                    // button.val( "Sending..." );
202
203                },
204                success: function( response ){
205                    response = JSON.parse(response);
206                    if (response.success) {
207                            if(paypalForm.length > 0){
208                                if(response.submission_id) {
209                                    paypalForm.append('<input type="hidden" name="custom" value="'+response.submission_id+'">');
210                                }
211                                jQuery('#paypal-form-'+form_id+' input[type=submit]').click();
212                                button.val( 'Redirecting to PayPal...' ).css('pointer-events','none');
213
214                            } else {
215                                button.val( button_text ).css('pointer-events','none');
216
217                                if( response.action_onsubmit == '1' ){ /*success message */
218                                    form.closest('.gdfrm-form-section').append('<div class="success-message">'+response.success_message+'</div>');
219                                    if(response.hide_form == '1'){
220                                        form.remove();
221                                    }
222                                } else if(response.action_onsubmit == '2'){ /*redirect */
223                                    if(response.redirect_url!=''){
224                                        window.location.replace(response.redirect_url)
225                                    }
226                                } else if(response.action_onsubmit == '3'){ /*reset form */
227                                    document.getElementById("gdfrm-"+form_id).reset();
228                                }
229                            }
230                        jQuery('.error-block').html('');
231                    } else if( response.validation_errors ){
232                            var errors = response.validation_errors;
233                         jQuery.each(errors,function(k,error){
234                                var id = error.field;
235                                var error = error.error;
236                                jQuery('.gdfrm-form-field.field-'+id+' .error-block').html(error).show();
237                            });
238                            button.val( button_text ).css('pointer-events','auto');
239
240                    } else if( response.user_errors ){
241                        var error = response.user_errors;
242
243                        if(jQuery('#gdfrm-'+form_id+' .form-error-block').length){
244                            jQuery('#gdfrm-'+form_id+' .form-error-block').html(error);
245                        } else {
246                            jQuery('#gdfrm-'+form_id).append('<div class="form-error-block">'+error+'</div>');
247                        }
248                        button.val( button_text ).css('pointer-events','auto');
249
250                    } else {
251                        console.log('not done');
252                        }
253                    }
254            });
255
256            return false;
257        }
258    });
259
260
261    /* datepicker */
262    jQuery( ".datepicker" ).each(function () {
263        var min_date = jQuery( this ).attr('min-date');
264        var max_date = jQuery( this ).attr('max-date');
265        var format   = jQuery( this ).attr('format');
266        if(min_date!='' && max_date!='' ){
267            jQuery( this ).datepicker({ minDate: new Date(min_date) , maxDate:  new Date(max_date) , dateFormat: format});
268        } else if(min_date!='' && max_date==''){
269            jQuery( this ).datepicker({ minDate: new Date(min_date) , dateFormat: format});
270        } else if(min_date=='' && max_date!=''){
271            jQuery( this ).datepicker({ maxDate:  new Date(max_date) , dateFormat: format});
272        } else{
273            jQuery(this).datepicker({ dateFormat: format});
274        }
275    })
276
277
278    /* text and textarea length limit */
279    jQuery('.gdfrm-form-field.gdfrm-text input,.gdfrm-form-field.gdfrm-password input,.gdfrm-form-field.gdfrm-textarea textarea').on('keydown',function (e) {
280        if(!jQuery(this).is('[readonly]')  && jQuery(this).attr('limit')!='' ){
281            jQuery(this).next('.limit-text').show();
282            var limit = parseInt(jQuery(this).attr('limit'));
283            var limitType = jQuery(this).attr('limitType');
284
285            if(limit>0){
286                if(limitType=='char'){
287                    if(jQuery(this).val().length == limit && e.keyCode!='8'){
288                        e.preventDefault();
289                    } else{
290                        if(e.keyCode=='8'){
291                            jQuery(this).next('.limit-text').find('.left').text((jQuery(this).val().length == 0) ? limit-jQuery(this).val().length : limit-jQuery(this).val().length + 1);
292                        } else{
293                            jQuery(this).next('.limit-text').find('.left').text(limit-jQuery(this).val().length-1);
294                        }
295                    }
296                } else if(limitType=='word'){
297                    var words = jQuery(this).val().split(' ');
298                    if(words.length == limit+1){
299                        if(e.keyCode!== 8){
300                            e.preventDefault();
301                        }
302                    } else{
303                        jQuery(this).next('.limit-text').find('.left').text((e.keyCode === 8) ? limit-words.length + 1 : limit-words.length);
304                    }
305                }
306            }
307        }
308    });
309
310    /* password view toggle */
311    jQuery('.gdfrm-password-block').on('click','.gdfrm-view-password',function () {
312        passwordField = jQuery(this).closest('.gdfrm-password-block').find('input');
313        if(passwordField.attr('type') == 'password') {
314            passwordField.attr('type','text') ;
315        }
316        else {
317            passwordField.attr('type','password') ;
318        }
319    })
320
321})
322
323/* initialize google map */
324function gdfrm_initMap() {
325    jQuery('.gdfrm-map-block').each(function () {
326        var map_lat = jQuery(this).attr('center_lat');
327        var map_lng = jQuery(this).attr('center_lng');
328        var center = {lat: parseFloat(map_lat), lng: parseFloat(map_lng)};
329        var id = jQuery(this).attr('id');
330        var draggable = jQuery(this).attr('draggable');
331
332        var map = new google.maps.Map(document.getElementById(id), {
333            zoom: 8,
334            center: center,
335            draggable: draggable
336        });
337
338        var marker = new google.maps.Marker({
339            position: center,
340            map: map
341        });
342    })
343
344}
345
346function myForm(form_id){
347    var _this = this;
348
349    _this.init = function(){
350        _this.form = jQuery('#'+form_id);
351        _this.form_id = form_id;
352        _this.sitekey = jQuery('#'+form_id+'-recaptcha').attr('sitekey');
353        _this.theme = jQuery('#'+form_id+'-recaptcha').attr('theme');
354        _this.recaptchaWidgetId = '';
355        _this.size = jQuery('#'+form_id+'-recaptcha').attr('size');
356
357        if(jQuery('#'+form_id+'-recaptcha').is('div')){
358            _this.recaptchaType = 'regular';
359        } else {
360            _this.recaptchaType = 'hidden';
361        }
362
363        if(typeof grecaptcha === 'undefined' || typeof grecaptcha.render !== 'function'){
364            setTimeout(function(){
365                _this.init();
366            },100);
367        }else{
368            _this.initRecaptcha();
369        }
370    };
371
372
373    _this.onSubmit = function(){
374        _this.form.submit();
375        return false;
376
377    };
378
379    _this.initRecaptcha = function(){
380        if(_this.recaptchaType=='regular'){
381            _this.recaptchaWidgetId = grecaptcha.render(_this.form_id+'-recaptcha', {
382                sitekey: _this.sitekey,
383                theme: _this.theme,
384                size : _this.size
385            })
386        } else {
387            _this.recaptchaWidgetId = grecaptcha.render(_this.form_id+'-recaptcha', {
388                sitekey: _this.sitekey,
389                callback: _this.onSubmit
390            })
391        }
392
393    };
394
395    _this.init();
396
397}
398jQuery('.gdfrm-form').each(function(){
399    var _el = jQuery(this);
400    setTimeout(function(){
401        myForm(_el.attr('id'));
402    },0);
403});
404
405
406/* refresh simple captcha */
407function gdfrm_refresh_captcha(e) {
408    e.preventDefault();
409    captchaid = jQuery(this).attr('captchaid');
410    captchacontainer=jQuery(this).closest('.gdfrm-captcha-box');
411    img = captchacontainer.find('img').eq(0);
412
413    user='user';
414    var general_data = {
415        action: "gdfrm_refresh_simple_captcha",
416        captchaid: captchaid
417    };
418
419    jQuery.post(ajaxurl, general_data, function (response) {
420        if (response) {
421            console.log(response);
422            img.remove();
423
424            newimg='<img src="'+response.url+'">';
425
426            captchacontainer.find('input[name=captcha-id]').val(response.id);
427
428            jQuery(newimg).prependTo(captchacontainer);
429
430        } else {
431            console.log('not done');
432        }
433    }, "json");
434}
435
436/* upload file */
437var inputs = document.querySelectorAll( '.gdfrm-inputfile' );
438Array.prototype.forEach.call( inputs, function( input )
439{
440    var filenames	 = input.nextElementSibling;
441
442    input.addEventListener( 'change', function( e )
443    {
444        var fileName = '';
445        if( this.files && this.files.length > 0 ){
446            var file_list = this.files;
447            jQuery.each(file_list,function(idx,elm){
448                fileName += '<div class="single-file"><span>'+elm.name+'</span></div>';
449            });
450        }
451
452        if( fileName )
453            filenames.innerHTML = fileName;
454    });
455});
456
457
458/* phone,text mask */
459jQuery('.masked').each(function () {
460    var maskpattern = jQuery(this).attr('data-pattern');
461    jQuery(this).mask( maskpattern );
462
463    jQuery(this).on("blur", function() {
464        var last = jQuery(this).val().substr( jQuery(this).val().indexOf("-") + 1 );
465
466        if( last.length == 3 ) {
467            var move = jQuery(this).val().substr( jQuery(this).val().indexOf("-") - 1, 1 );
468            var lastfour = move + last;
469
470            var first = jQuery(this).val().substr( 0, 9 );
471
472            jQuery(this).val( first + '-' + lastfour );
473        }
474    });
475})
476
477/* select2 dropdowns */
478
479jQuery(".select2").each(function () {
480    var search_on = jQuery(this).attr('search');
481    var placeholder = jQuery(this).closest('div').find('.select2-placeholder').val();
482    var theme_class = 'gdfrm-select2';
483
484    if(jQuery(this).closest('.gdfrm-form-container').attr('data-theme')) {
485        theme_class = 'gdfrm'+jQuery(this).closest('.gdfrm-form-container').attr('data-theme')+'-select2';
486        if(jQuery(this).closest('.gdfrm-form-field').hasClass('gdfrm-date') || jQuery(this).closest('.gdfrm-form-field').hasClass('gdfrm-address')){
487            theme_class += ' gdfrm-small-select2';
488        }
489    }
490
491    if(jQuery(this).hasClass('select-country')) placeholder = "Select Country";
492
493    if(search_on && search_on!=0){
494        jQuery(this).select2({
495            placeholder: placeholder,
496            dropdownCssClass : theme_class,
497        });
498    } else {
499        jQuery(this).select2({
500            placeholder: placeholder,
501            minimumResultsForSearch: -1,
502            dropdownCssClass : theme_class,
503        });
504    }
505});
506
507/* refresh simple captcha on refresh button click */
508jQuery('.gdfrm-captcha-box>a').click(gdfrm_refresh_captcha);
509
510
511if(jQuery('.total-box').length){
512
513    if(jQuery('.total-box').length > 1) jQuery('.total-box').not(':first').remove();
514
515    var refreshTotal = function(form){
516
517        var payment_fields = jQuery('form#gdfrm-'+form+' .payment-field');
518
519        var total = 0;
520
521        var items = '';
522
523        var count = 0;
524
525        payment_fields.each(function () {
526            if(jQuery(this).hasClass('select2')){
527                var quantity = jQuery(this).siblings('.gdfrm-quantity-cont').find('.gdfrm-quantity').val();
528                var price =  parseFloat(jQuery(this).find(":selected").attr('data-price'));
529                var name = jQuery(this).find(":selected").text();
530
531                if( price * quantity ) count ++;
532                total += price * quantity;
533                items += '<input name="item_name_'+count+'" type="hidden" value="'+name+'" />'+
534                         '<input name="item_number_'+count+'" type="hidden" value="sku1" />'+
535                         '<input name="amount_'+count+'" type="hidden" value="'+price+'" />'+
536                         '<input name="quantity_'+count+'" type="hidden" value="'+quantity+'" />';
537            } else if(jQuery(this).hasClass('gdfrm-checkbox-options')){
538                checked_elements = jQuery(this).find(":checked");
539                if(checked_elements.length){
540                    checked_elements.each(function () {
541                        var quantity = jQuery(this).closest('.gdfrm-checkbox-option').find('.gdfrm-quantity-cont').find('.gdfrm-quantity').val();
542                        var price =  parseFloat(jQuery(this).attr('data-price'));
543                        var name = jQuery(this).attr('data-name');
544                        if( price * quantity ) count ++;
545                        total += price * quantity;
546                        items += '<input name="item_name_'+count+'" type="hidden" value="'+name+'" />'+
547                            '<input name="item_number_'+count+'" type="hidden" value="sku1" />'+
548                            '<input name="amount_'+count+'" type="hidden" value="'+price+'" />'+
549                            '<input name="quantity_'+count+'" type="hidden" value="'+quantity+'" />';
550
551                    })
552                }
553            } else if(jQuery(this).hasClass('gdfrm-radio-options')){
554                if(jQuery(this).find(":checked").length){
555                    var quantity = jQuery(this).siblings('.gdfrm-quantity-cont').find('.gdfrm-quantity').val();
556                    var price =  parseFloat(jQuery(this).find(":checked").attr('data-price'));
557                    var name = jQuery(this).find(":checked").attr('data-name');
558                    if( price * quantity ) count ++;
559                    total += price* quantity;
560                    items += '<input name="item_name_'+count+'" type="hidden" value="'+name+'" />'+
561                        '<input name="item_number_'+count+'" type="hidden" value="sku1" />'+
562                        '<input name="amount_'+count+'" type="hidden" value="'+price+'" />'+
563                        '<input name="quantity_'+count+'" type="hidden" value="'+quantity+'" />';
564                }
565            } else if(jQuery(this).hasClass('gdfrm-donation')){
566                var name = 'Donation';
567
568                if(jQuery(this).find("li.selected").length){
569                    var price =  parseFloat(jQuery(this).find("li.selected").attr('data-price'));
570                    var quantity = jQuery(this).find('.gdfrm-quantity').val();
571                } else {
572                    var price =  parseFloat(jQuery(this).find("input[type=number]").val());
573                    if(isNaN(price) || price < 0) price = 0;
574                    var quantity = jQuery(this).find('.gdfrm-quantity').val();
575                }
576
577                if( price * quantity ) count ++;
578                total += price * quantity;
579
580                items += '<input name="item_name_'+count+'" type="hidden" value="'+name+'" />'+
581                    '<input name="item_number_'+count+'" type="hidden" value="sku1" />'+
582                    '<input name="amount_'+count+'" type="hidden" value="'+price+'" />'+
583                    '<input name="quantity_'+count+'" type="hidden" value="'+quantity+'" />';
584            }
585        })
586
587        if(jQuery('#total-row-'+form+'').length){
588            jQuery('#total-row-'+form+' .total').text(total);
589        } else{
590            jQuery('.total-box').append('<div id="total-row-'+form+'">'+
591                '<div class="total-value">'+
592                '<span class="form-name">'+jQuery('#gdfrm-'+form+' ').attr('data-title')+'</span>'+
593                '<span class="currency">'+jQuery('#paypal-currency').val()+'</span>'+
594                '<span class="total"> '+total+'</span>'+
595                '</div>'+
596                '</div>');
597        }
598
599
600        jQuery('#paypal-form-'+form+' .items').html(items);
601    }
602
603    jQuery('.gdfrm-payment-form').each(function () {
604        var form = jQuery(this).attr('form-id');
605        refreshTotal(form);
606    })
607
608
609
610    jQuery(document).on('change keyup','.payment-field input,select.payment-field,.gdfrm-selectbox input.gdfrm-quantity,.gdfrm-radio input.gdfrm-quantity',function () {
611        var form = jQuery(this).closest('form').attr('form-id');
612        refreshTotal(form);
613    })
614
615
616    jQuery(document).on('click','.gdfrm-donation ul li',function () {
617        var form = jQuery(this).closest('form').attr('form-id');
618
619        jQuery('#gdfrm-'+form+' .gdfrm-donation ul li').not(jQuery(this)).removeClass('selected');
620
621        jQuery(this).toggleClass('selected');
622
623        if(jQuery('#gdfrm-'+form+' .gdfrm-donation ul li.selected').length){
624            jQuery('#gdfrm-'+form+' .gdfrm-donation input[type=number]').val(0);
625        }
626
627        refreshTotal(form);
628    })
629
630    jQuery(document).on('focus','.gdfrm-donation input[type=number]',function () {
631        var form = jQuery(this).closest('form').attr('form-id');
632        jQuery('#gdfrm-'+form+' .gdfrm-donation ul li').not(jQuery(this)).removeClass('selected');
633
634        refreshTotal(form);
635    })
636}
637
638
639
640
641

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.