WordPress Load External url modal box Jquery, after show redirect to page error
Question
$.fn.progeApriAjaxModal = function(){
var $this = $(this),
url = $this.attr( 'data-url' );
$this.click(function(){
// CLOSE MODAL FUNCTION
var progeChiudiAjaxModal = function(){
$( '.c-modal' ).fadeOut( 300, function(){
$( '.c-modal .modal-loading' ).show();
$( '.c-modal .modal-box' ).removeClass( 'animated fadeInDown' ).unbind( 'clickoutside' ).hide();
$( 'html' ).removeClass( 'm-modal-active' );
});
// TRIGGER modalClosed EVENT
$.event.trigger({
type: 'modalClosed',
message: 'Modal is closed.',
time: new Date()
});
};
// CREATE / SHOW MODAL
if ( $( '.c-modal' ).length < 1 ) {
var modalHtml = '<div class="c-modal" style="display: none;">';
modalHtml += '<div class="modal-loading"><span class="c-loading-anim"><span></span></span></div>';
modalHtml += '<div class="modal-box" style="display: none;"><button class="modal-close" type="button"></span><span class="icon-box icon-close"></span></button><div class="modal-box-inner"></div></div>';
modalHtml += '</div>';
$( 'body' ).append( modalHtml );
}
var modal = $( '.c-modal' ),
modalLoading = $( '.c-modal .modal-loading' ),
modalBox = $( '.c-modal .modal-box' ),
modalBoxInner = $( '.c-modal .modal-box-inner' ),
modalClose = $( '.c-modal .modal-close' );
modal.fadeIn( 300 );
$( 'html' ).addClass( 'm-modal-active' );
// LOAD CONTENT
modalBoxInner.load( url, function( response, status, xhr ){
// SHOW MODAL BOX
modalLoading.fadeOut( 300 );
modalBox.show().addClass( 'animated fadeInDown' );
// CLICK ON CLOSE
modalClose.click(function(){
progeChiudiAjaxModal();
});
// iOS & Chrome BODY SCROLLING FIX
$( 'body' ).on( 'touchmove', function (e) {
if ( $( '.c-modal' ).is( ':visible' ) ) {
if ( ! $( '.c-modal' ).has( $( e.target ) ).length ) {
e.preventDefault();
}
}
});
$( 'body' ).on( 'mousewheel DOMMouseScroll', function (e) {
if ( $( '.c-modal' ).is( ':visible' ) ) {
if ( ! $( '.c-modal' ).has( $( e.target ) ).length ) {
e.preventDefault();
}
}
});
// CLICK OUTSIDE
/*
modalBox.unbind( ‘clickoutside’ ).bind( ‘clickoutside’, function(){
progeChiudiAjaxModal();
});
*/
// ERROR LOADING CONTENT
if ( status == ‘error’ ) {
modalBoxInner.html( ” ).append( ‘Non è stato possibile caricare il link, si prega di riprovare più tardi.
‘ );
}
// INIT AJAX FORMS
else {
}
// TRIGGER modalOpened EVENT
$.event.trigger({
type: 'modalOpened',
message: 'Modal is opened.',
time: new Date()
});
});
// DISABLE DEFAULT CLICK ACTION
return false;
});
};
<a data-url="https://www.iubenda.com" class="c-button m-open-ajax-modal" rel="nofollow noopener">informativa sulla privacy</a>
0
2 years
2020-12-26T09:10:25-05:00
2020-12-26T09:10:25-05:00 0 Answers
4 views
0
Leave an answer