script.js 5.28 KB
$(
    function() {
       // phoneMask('input[name="Feedback[phone]"]');
        //        /**
        //         * Modal form submit code
        //         */
        //        $(document)
        //            .on(
        //                'beforeSubmit', '#feedback-form', function(e) { 
        //                    var f = this;
        //                    var form = $(this);
        //                    var formData = form.serialize();
        //                    $.ajax(
        //                        {
        //                          url: form.attr("action"),
        //                            type: form.attr("method"),
        //                            data: formData,
        //                            success: function(data) {
        //                                f.reset();
        //                                $('#feedback-modal')
        //                                    .modal('hide');
        //                                $('#success-modal')
        //                                    .modal('show');
        //                            },
        //                            error: function() {
        //                                $('#feedback-modal')
        //                                    .modal('hide');
        //                            }
        //                        }
        //                    );
        //                }
        //            )
        //            .on(
        //                'submit', '#feedback-form', function(e) {
        //                    e.preventDefault();
        //                }
        //            );

        /**
         * Contact form submitting
         */
        //        $(document)
        //            .on(
        //                'beforeSubmit', '#contact-form', function(e) {
        //                    var f = this;
        //                    var form = $(this);
        //                    var formData = form.serialize();
        //                    $.ajax(
        //                        {
        //                            url: form.attr("action"),
        //                            type: form.attr("method"),
        //                            data: formData,
        //                            success: function(data) {
        //                                f.reset();
        //                                form.replaceWith(data.alert)
        //                            },
        //                            error: function() {
        //
        //                            }
        //                        }
        //                    );
        //                }
        //            )
        //            .on(
        //                'submit', '#contact-form', function(e) {
        //                    e.preventDefault();
        //                }
        //            );


        $('.field-feedback-recaptcha').addClass('col-sm-12').addClass('f_center')

        /**
         * Button UP code
         */
        if ($('#back-to-top').length) {
            var scrollTrigger = 100, // px
                backToTop = function() {
                    var scrollTop = $(window)
                        .scrollTop();
                    if (scrollTop > scrollTrigger) {
                        $('#back-to-top')
                            .addClass('show');
                    } else {
                        $('#back-to-top')
                            .removeClass('show');
                    }
                };
            backToTop();
            $(window)
                .on(
                    'scroll', function() {
                        backToTop();
                    }
                );
            $('#back-to-top')
                .on(
                    'click', function(e) {
                        e.preventDefault();
                        $('html,body')
                            .animate(
                                {
                                    scrollTop: 0
                                }, 700
                            );
                    }
                );
        }

        function phoneMask(maskCssSelector) {
            var phoneInput = maskCssSelector;

            if ($('body')
                    .find(phoneInput).length > 0) {
                $(phoneInput)
                    .mask('+38(000)000-00-00', {placeholder: '+38(000)000-00-00'});
                $(phoneInput)
                    .focus(
                        function() {
                            if (($(this)
                                    .val()) == '') {
                                $(this)
                                    .val('+38(0')
                            }
                        }
                    );
                $(phoneInput)
                    .focusout(
                        function() {
                            var phoneVal = $(this)
                                .val()
                            //if(phoneVal == '+38(0' || phoneVal == '+38(' || phoneVal == '+38' || phoneVal == '+3' || phoneVal == '+') {$(this).val('')}
                            if (phoneVal.length < 17) {
                                $(this)
                                    .val('')
                            }
                        }
                    );
            }
        }
    }
);