window.JT_BAD_UX_POPUP={};
jQuery(function($){
window.JT_BAD_UX_POPUP.init=function (){
var $container=$('#jt_popup_container');
var $popup_group=$('#jt_popup_playground');
var $overlay=$('#jt_popup_overlay');
var is_mobile=$('html').hasClass('mobile')||$('html').hasClass('tablet') ;
var popup_count=0;
var language=$('html').attr('lang') ;
var home_url='';
is_mobile=is_mobile||(! is_mobile&&navigator.maxTouchPoints&&navigator.maxTouchPoints > 2&&/MacIntel/.test(navigator.platform) );
try {
home_url=(window.__JTPOP.home_url||'');
} catch(e){ }
$.ajax({
url: home_url + '/wp-json/jt-bad-ux-popup/list/',
method: 'get',
data: {
type:(is_mobile ? 'mobile':'pc'),
location: location.href,
language:(typeof window.__JTPOP.language!=='undefined' ? window.__JTPOP.language:language),
is_home:(typeof window.__JTPOP.is_home!=='undefined' ? window.__JTPOP.is_home:$('body').hasClass('home') ),
blog_id:(typeof window.__JTPOP.blog_id!=='undefined' ? window.__JTPOP.blog_id:null)
},
success: function(res){
if(res&&typeof res.html!=='undefined'){
$('body').append(res.html);
$container=$('#jt_popup_container');
$popup_group=$('#jt_popup_playground');
$overlay=$('#jt_popup_overlay');
run();
}},
error:function(res){
$.ajax({
url: home_url + '/hansangvn-admin-login/admin-ajax.php',
method: 'get',
data: {
action: 'jt_bad_ux_popup',
type:(is_mobile ? 'mobile':'pc'),
location: location.href,
language:(typeof window.__JTPOP.language!=='undefined' ? window.__JTPOP.language:language),
is_home:(typeof window.__JTPOP.is_home!=='undefined' ? window.__JTPOP.is_home:$('body').hasClass('home') ),
blog_id:(typeof window.__JTPOP.blog_id!=='undefined' ? window.__JTPOP.blog_id:null)
},
success: function(res){
if(res&&typeof res.html!=='undefined'){
$('body').append(res.html);
$container=$('#jt_popup_container');
$popup_group=$('#jt_popup_playground');
$overlay=$('#jt_popup_overlay');
run();
}}
});
}});
function run(){
$('.jt_popup_item').each(function (){
if($.cookie($(this).attr('id') )=='today_none'){
$(this).remove();
}else{
popup_count++;
}});
if(is_mobile==false){
$('.jt_popup_item').each(function (){
var $this=$(this);
$this.imagesLoaded(function (){
if(popup_count==1&&! parseInt($('.jt_popup_item').css('left').replace('px', '') )&&! parseInt($('.jt_popup_item').css('top').replace('px', '') )){
$('.jt_popup_item').css({
'position': 'fixed',
'margin-top': -($('.jt_popup_item').height() / 2) + 'px',
'margin-left': -($('.jt_popup_item').width() / 2) + 'px',
'top': '50%',
'left': '50%'
});
}
if(! $overlay.is(':visible') ){
$overlay.fadeIn('fast');
}
$this.fadeIn('fast');
$this.draggable({
start: function(event, ui){
var popupZIndex=0;
$('.jt_popup_item').each(function (){
popupZIndex=(popupZIndex < parseInt($(this).css('z-index') ) ? parseInt($(this).css('z-index') ):popupZIndex);
});
$this.css('z-index', popupZIndex + 1);
}});
});
});
$overlay.on('click', function (){
$container.fadeOut('fast', function (){
$(this).remove();
});
});
}
if(is_mobile==true){
if($('.jt_popup_item').length > 0){
$('body').addClass('bad_ux_popup_scroll_remove');
window.scroll(function (){
$overlay.height(window.innerHeight);
});
if($('.jt_popup_item').length > 1){
$popup_group.on('init', function(event, slick){
$overlay.fadeIn('fast');
$('#jt_popup_mobile_close_all').fadeIn('fast');
$popup_group.css({
opacity: 1,
visibility: 'visible'
});
});
$popup_group.slick({
slidesToShow: 1,
slidesToScroll: 1,
infinite: false,
autoplay: false,
speed: 300,
swipeToSlide: true,
arrows: false,
dots: false,
variableWidth: true,
centerMode: false,
centerPadding: 0
});
}else{
$('#jt_popup_container').addClass('only_one_slide');
$('.jt_popup_item').each(function (){
var $this=$(this);
$this.find('img').on('load', function (){
$('#jt_popup_playground').css({
'margin-left': -($('.jt_popup_item').width() / 2) + 'px',
'left': '50%'
});
if(! $overlay.is(':visible') ){
$overlay.fadeIn('fast');
}
$this.fadeIn('fast');
});
});
}
$('#jt_popup_mobile_close_all').on('click', function(e){
e.preventDefault();
$('body').removeClass('bad_ux_popup_scroll_remove');
$container.fadeOut('fast', function (){
$(this).remove();
});
});
}}
$('.jt_popup_close').on('click', function(e){
e.preventDefault();
if($('.jt_popup_item').length > 0){
if(is_mobile==true){
$('body').removeClass('bad_ux_popup_scroll_remove');
}
if($('.jt_popup_item').length > 1){
if(is_mobile==false){
$(this).parents('.jt_popup_item').fadeOut('fast', function (){
$(this).remove();
});
}else{
$popup_group.slick('slickRemove', $(this).parents('.jt_popup_item').index());
}}else{
$container.fadeOut('fast', function (){
$(this).remove();
});
}}
});
$('.jt_popup_notoday').on('click', function(e){
e.preventDefault();
var parent_wrap=$(this).parents('.jt_popup_item');
$.cookie(parent_wrap.attr('id'), 'today_none', { expires: 1, path: '/' });
if($('.jt_popup_item').length > 0){
if(is_mobile==true){
$('body').removeClass('bad_ux_popup_scroll_remove');
}
if($('.jt_popup_item').length > 1){
if(is_mobile==false){
$(this).parents('.jt_popup_item').fadeOut('fast', function (){
$(this).remove();
});
}else{
$popup_group.slick('slickRemove', $(this).parents('.jt_popup_item').index());
}}else{
$container.fadeOut('fast', function (){
$(this).remove();
});
}}
});
}}
window.JT_BAD_UX_POPUP.init();
});