Blame view

frontend/web/js/modal.js 3.37 KB
a0e8d4e0   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
  $(
    function() {
  
  
        modalForms();
        closeForms();
        function modalForms() {
            $('body').on('click','.modal-link', function (e) {
                e.preventDefault();
  
  
                var idForm = $(this).data('form');
                // console.log(idForm);
                // var pos = ($(window).scrollTop()) + 30;
                $('#overlay').fadeIn(400,
                    function(){
                        $('#'+idForm)
                            .css('display', 'block')
                            .animate({opacity: 1}, 200);
                    });
                $("body").addClass("off-scroll");
            })
        }
        function closeForms() {
            $('.close, #overlay').click( function(){
                $('.forms_').animate({opacity: 0, top: '0'}, 200,function(){
                    $(this).css('display', 'none');
                    $('#overlay').fadeOut(400);
                });
                $('#success_form').animate({opacity: 0, top: '0'}, 200,function(){
                    $(this).css('display', 'none');
                    $(this).css({top:'50%'});
                });
                $("body").removeClass("off-scroll");
            });
        }
  
  
        $(".on_input_").on('click', function(){
            $(this).addClass("actived");
            $(this).parent().find("input").focus();
        });
        $(".forms_ input").on('focusout', function(){
            $(".on_input_.actived").removeClass("actived");
        });
  
  
        $(document)
            .on(
                'beforeSubmit', '.forms_ form', function() {
                    var f = this;
                    var form = $(this);
                    var formData = form.serialize();
                    console.log(formData);
                    $.ajax(
                        {
                            url: form.attr("action"),
                            type: form.attr("method"),
                            data: formData,
                            success: function(data) {
                                f.reset();
d0b13318   Alexey Boroda   -Form custom event
62
63
64
                                if (data.type == 'appointment') {
                                    dataLayer.push({'event': 'mainFormSub'});
                                }
a0e8d4e0   Alexey Boroda   first commit
65
66
67
68
69
70
71
                                // form.replaceWith(data.alert)
                                // $(".modal-dialog").append(data.alert);
                                // setTimeout(function(){location.reload()}, 5000);
                                $(".close").click();
                                $(".success_").animate({opacity: 1, top: '40'}, 200).addClass("done_");
                                setTimeout(function(){$(".success_").animate({opacity: 0, top: '0'}, 200,function(){
                                    $(this).removeClass("done_");
d0b13318   Alexey Boroda   -Form custom event
72
                                })}, 4000)
a0e8d4e0   Alexey Boroda   first commit
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
                            },
                            error: function() {
  
                            }
                        }
                    );
                }
            )
            .on(
                'submit', '.forms_ form', function(e) {
                    e.preventDefault();
                }
            );
  
  
        $(".bnm.btn").on('click', function(){
            $("#booknow-modal .modal-title").html($(this).data('title'));
            $("#booknow-modal #booknow-tour").val($(this).data('title'));
        });
        $(".success_ button").click(function(){
            $(".success_").removeClass("done_");
        });
        $(".overlay-new").click(function(){
            $(".close").click();
        });
    }
  );