Open/close block button in a modal window?

What will be the script, the opening and closing unit in a modal window?
In the modal window the content is loaded via ajax

The model window opens for the script:

$('.popup-post-modal-open').bind('click', DimaPopup);
 $('.popup-background').bind('click', Popupclose);

 DimaPopup function(e){
e.preventDefault();

 $('.popup-background').css('opacity', '1');
 $('.popup-background').css('visibility', 'visible');

 var url = $(this).attr('href');

 // And just change the link
 if(url != window.location){
 window.history.pushState(null, null, url);
}

$('.popup-loader').fadeIn(100);
$('.popup-post').addClass('active');
window.setTimeout(function(){$('.popup-post').scrollTop(0);},50);
$('#content_owerflow').addClass('active');
$('body').addClass('html_noscroll');
 $('body').css('padding-right', '17px');

$.ajax(
{
 type : 'POST',
 url : 'https://' + location.host + '/wp-admin/admin-ajax.php',
 data: { action: 'popup_post', popup_post_id:$(this).parents('.title').children('.post-click-popup').children('span').text()
},
 success: function(data){ 
$('.post-generat-content').eq(0).html(data);
$('.popup-loader').fadeOut(100);


 $('.close').bind('click', Popupclose);
},
 error: function(error)
{
console.log('Error');
}
});
}
 var window_location = window.location.href;
 function Popupclose() {
 $('.popup-background').css('opacity', '0');
 $('.popup-background').css('visibility', 'hidden');
$('.popup-post').removeClass('active');
 window.history.pushState(null, null, window_location);
$('body').removeClass('html_noscroll');
 $('body').css('padding-right', '0');
}
 window.addEventListener('popstate', function(e) {
 $('.popup-background').css('opacity', '0');
 $('.popup-background').css('visibility', 'hidden');
$('.popup-post').removeClass('active');
$('body').removeClass('html_noscroll');
 $('body').css('padding-right', '0');
 var url = $(this).attr('href');
 if(url != window.history.back){
 window.history.pushState(null, null, null);
}
});


Thank you!
June 14th 19 at 20:18

Find more questions by tags AJAXJavaScriptjQuery