forms.js 3.27 KB
$(document).ready(function(){
    function addRemoveBlocks(){
        $('#overlay, .forms-modal-hide').remove();
        $('body').append('<div id="overlay"></div>').append('<div class="forms-modal-hide"></div>');
    }

    function addToFavorites(){
        $.post("/site/forms-modal-fav", function (data) {
            $('.forms-modal-hide').append(data)
        })
            .fail(function(){
                $('#overlay, .forms-modal-hide').remove();
                alert(txtErrorModal)
            })
            .done(function() {
                var newMarg = $(window).scrollTop();
                $('#overlay').fadeIn(400,
                    function(){
                        $('.forms-modal-hide>div')
                            .css({display:'block', marginTop:-230+newMarg})
                            .animate({opacity: 1, top: '50%'}, 200);
                    });
            })
    }

    function addToOffer(){
        $.post("/site/forms-modal-offer", function (data) {
            $('.forms-modal-hide').append(data)
        })
            .fail(function(){
                $('#overlay, .forms-modal-hide').remove();
                alert(txtErrorModal)
            })
            .done(function() {
                var newMarg = $(window).scrollTop();
                $('#overlay').fadeIn(400,
                    function(){
                        $('.forms-modal-hide>div')
                            .css({display:'block', marginTop:-230+newMarg})
                            .animate({opacity: 1, top: '50%'}, 200);
                    });
            })
    }

    function addContacts() {
        $.post("/site/forms-modal-contacts", function (data) {
                $('.forms-modal-hide').append(data)
        })
            .fail(function(){
                $('#overlay, .forms-modal-hide').remove();
            alert(txtErrorModal)
        })
            .done(function() {
            var newMarg = $(window).scrollTop();
                $('#overlay').fadeIn(400,
                    function(){
                        $('.forms-modal-hide>div')
                            .css({display:'block', marginTop:-230+newMarg})
                            .animate({opacity: 1, top: '50%'}, 200);
                    });
        })
    }

    //contacts
    $('a.contactsLinkModalFirst').click(function(e){
        e.preventDefault()
        addRemoveBlocks()
        addContacts()
    })
    //bookmarks
    $('.get-list, .performance-vacancy-add-favorite a, .blog-buttons-add-favorite').click(function(e){
        e.preventDefault()
        addRemoveBlocks()
        addToFavorites()
    })
    //offer
    $('a.get-project, .blog-buttons-offer').click(function(e){
        e.preventDefault()
        addRemoveBlocks()
        addToOffer()
    })

    var txtErrorModal = 'ВОЗНИКЛА ОШИБКА, ПОПРОБУЙТЕ ЕЩЕ РАЗ ПОЗЖЕ!';

    clocseModalForms()
    function clocseModalForms(){
        $('body').on('click','.closed-form, #overlay', function(){
            $('.forms-modal-hide>div')
                .animate({opacity: 0, top: '30%'}, 200,
                function(){
                    $(this).css('display', 'none')
                    $('#overlay').fadeOut(400,function(){$('#overlay, .forms-modal-hide').remove()})
                }
            )

        });
    }

})