jQuery(document).ready(function($){
var SC='';
$('body').on('evo_init_ajax_success_each_cal', function(event, data, calid, v){
CAL=$('body').find('#'+ calid);
if(!CAL.hasClass('evoWV')) return;
draw_week_grid(CAL);
});
var BUS={};
var wv_range_format={
0: 'MM D', 1: 'MM D, YYYY'
};
$('body').on('evo_init_ajax_success',function(event, data){
$('body').find('.ajde_evcal_calendar.noiajx.evoWV').each(function(){
draw_week_grid($(this));
});
});
function draw_week_grid(CAL){
BUS=$('#evo_global_data').data('d');
if('cal_def' in BUS&&'wv_range_format' in BUS.cal_def){
wv_range_format=BUS.cal_def.wv_range_format;
}
SC=CAL.evo_shortcode_data();
const cal_tz=CAL.evo_get_global({S1:'cal_def',S2:'cal_tz'});
if(SC.week_style=='1')	CAL.find('#evcal_list').addClass('evo_hide');
var now=moment().tz(cal_tz);
var template_data={};
template_data['days']={};
var M=moment.unix(parseInt(SC.focus_start_date_range)).tz(cal_tz);
for(x=1; x<=7; x++){
var month=M.get('month')+1;
template_data['days'][x]={};
template_data['days'][x]['newmo']=(month!=(M.get('month')+1)? M.get('month')+1:'no');
template_data['days'][x]['SU']=M.unix();
template_data['days'][x]['D']=M.get('date');
template_data['days'][x]['DN']=M.day();
template_data['days'][x]['today']=(now.format('YYYY M D')==M.format('YYYY M D')? 'today':'');
M.add(1,'d');
template_data['days'][x]['EU']=M.unix() - 1;
}
template_data['table_style']=SC.table_style;
template_data['week_style']=SC.week_style;
template_data['fixed_week']=SC.fixed_week;
template_data['disable_week_switch']=SC.disable_week_switch;
_HTML=CAL.evo_HB_process_template({
TD:template_data, part:'evowv_week'
});
if(CAL.find('.EVOWV_content').length==0){
_HTMLt=CAL.evo_HB_process_template({
TD:template_data, part:'evowv_top'
});
ELM=CAL.find('#eventon_loadbar_section');
ELM.after(_HTMLt);
}
CAL.find('.EVOWV_grid').html(_HTML);
_draw_week_switcher_init(CAL);
__populate_preload_content(CAL);
setTimeout(function(){ populate_events_into_weekgrid(CAL) },(SC.week_style=='1' ? 500:0));
var SU=parseInt(SC.focus_start_date_range);
var EU=parseInt(SC.focus_end_date_range);
if((now.unix() < SU||EU < now.unix())&&SC.disable_week_switch=='no'){
if(CAL.find('.evowv_this_weekbtn').length==0){
var iSU=parseInt(SC._in_ws);
now_sow=_get_unix_of_now_week_start();
incre=parseInt((now_sow - iSU)/604800);
_txt=CAL.evo_get_txt({V:'this_week'});
CAL.find('.EVOWV_dates').prepend('<a class="evowv_this_weekbtn evcal_btn" data-week_incre="'+incre+'">'+_txt+'</a>');
}}else{
CAL.find('.evowv_this_weekbtn').remove();
}
CAL.find('.evowv_pre_loader').remove();
CAL.find('.evowv_pre_loader_week').remove();
}
function __populate_preload_content(CAL){
CAL.find('.eventon_events_list').addClass('evo_hide');
SC=CAL.evo_shortcode_data();
if(SC.week_style=='1'){
CAL.find('.evowv_col_events').html("<div class='evo_ajax_load_events evowv_pre_loader_x'><span class='wk_ev'></span><span class='wk_ev'></span><span class='wk_ev'></span></div>");
}else{
CAL.find('.evowv_preload_grid').html('<div class="evo_ajax_load_events evowv_pre_loader_x"><span></span><span></span><span></span></div>');
}}
function __remove_preloader(CAL, SC){
CAL.find('.evowv_pre_loader_x').remove();
if(SC.week_style!='1'&&SC.hide_events_onload!='yes'){
CAL.find('.eventon_events_list').removeClass('evo_hide');
}}
function _get_unix_of_now_week_start(){
var now=moment().utc();
$start_ow=$('body').evo_get_cal_def({V: 'start_of_week'});
$today_day=now.day();
if($start_ow >1) $dayDif=$today_day -($start_ow-1);
if($today_day > $start_ow) $dayDif=$today_day - $start_ow;
if($today_day==$start_ow) $dayDif=0;
if($start_ow > $today_day) $dayDif=7 - $start_ow;
now.subtract($dayDif, 'days');
now.startOf('day');
return now.unix();
}
function populate_events_into_weekgrid(CAL){
var eJSON=CAL.find('.evo_cal_events').data('events');
var grid=CAL.find('.EVOWV_grid');
var cal_events=CAL.find('.eventon_list_event');
const cal_tz=CAL.evo_get_global({S1:'cal_def',S2:'cal_tz'});
all_events=0;
dow=1;
grid.find('.evo_wv_day').each(function(index){
var O=$(this);
time_format=CAL.evo_get_global({S1:'cal_def',S2:'wp_time_format'});
EC=0;
SU=parseInt(O.data('su'));
EU=parseInt(O.data('eu'));
var day_events={};
cal_events.each(function(index, elm){
var ED=$(elm).evo_cal_get_basic_eventdata();
if(!ED) return;
ESU=ED.unix_start; EEU=ED.unix_end;
var inrange=CAL.evo_is_in_range({
'S': SU,	'E': EU,	'start': ESU,'end':EEU
});
if(inrange){
EC++; all_events++;
O.addClass('has_events');
if(SC.week_style=='1'){
style=SC.table_style=='0'? 'border-color':'background-color';
_time=__su='';
if((ESU <=SU||ESU <=SU +1)&&EU <=EEU
){
_time=CAL.evo_get_txt({V:'all_day'});
__su=1000;
}else{
m=moment.unix(ESU).tz(cal_tz);
me=moment.unix(EEU).tz(cal_tz);
_time +=(SU <=ESU&&ESU <=EU) ? 	m.format(time_format): '';
if(ED.hide_et=='n'){
_time +=' - ';
_time +=(EEU < EU) ? me.format(time_format):'';
}
__su=ESU;
}
var item_html="<span class='event evowv_tb_event' data-ec='"+ ED.uID +"' data-su='"+__su+"' style='"+style+":"+ ED.hex_color +"' data-uxval='"+ ED.ux_val +"'><span class='time'>"+ _time +"</span>"+ ED.event_title +"</span>";
if(!(__su in day_events)) day_events[ __su ]={};
day_events[ __su ][ ED.uID ]=item_html;
}else{
if(EC<4){
O.find('span.day_events').append("<em class='dayTag' style='background-color:"+ ED.hex_color +"' title='"+ ED.event_title +"'></em>");
}}
}});
if(SC.week_style=='1'){
$.each(day_events , function(index, data){
$.each(data , function(i, d){
O.find(".evowv_col_events").append(d);
})
});
}
if(EC>3&&SC.week_style!='1'){
O.find('span.day_events').append("<em class='dayTag more' title='+"+ EC+"'></em>")
.addClass('has_more_events');
}
if(EC==0){
O.addClass('noE');
}
dow++;
});
__remove_preloader(CAL, SC);
if(all_events==0){
CAL.find('.eventon_events_list').removeClass('evo_hide');
}}
function _draw_week_switcher_init(CAL){
var SC=CAL.evo_shortcode_data();
const cal_tz=CAL.evo_get_global({S1:'cal_def',S2:'cal_tz'});
var SU=parseInt(SC.focus_start_date_range);
var S=moment.unix(SU).tz(cal_tz);
E=moment.unix(parseInt(SC.focus_end_date_range)).tz(cal_tz);
N=CAL.find('.EVOWV_thisdates_range');
N.html(__get_formatted_date_range(S, E)).data('su', SU);
UL=CAL.find('.EVOWV_date_ranges');
_HTML=get_week_switcher_weeks(CAL , 'reset');
UL.html(_HTML);
}
function get_week_switcher_weeks(CAL , change){
UL=CAL.find('.EVOWV_date_ranges');
w=parseInt(UL.data('w'));
week_incre=parseInt(CAL.evo_get_sc_val({F:'week_incre'}));
new_w=(change=='reset') ? week_incre -2:w + change;
UL.attr('data-w', new_w).data('w', new_w);
var SC=CAL.evo_shortcode_data();
const cal_tz=CAL.evo_get_global({S1:'cal_def',S2:'cal_tz'});
unix_incre=new_w - week_incre;
var SU=parseInt(SC.focus_start_date_range);
var S=moment.unix(SU).tz(cal_tz).add(unix_incre,'w');
var E=moment.unix(SU).tz(cal_tz).add(unix_incre +1 ,'w').subtract(1,'s');
_HTML='';
for(x=1; x<=5; x++){
now=(SU==S.unix())? 'thisweek':'';
_HTML +="<li class='"+now+"' data-week_incre='"+new_w+"' data-su='"+ S.unix()+"'><em>"
+ __get_formatted_date_range(S, E) +"</em></li>";
S.add(1,'w');
E.add(1,'w');
new_w++;
}
return _HTML;
}
function __get_formatted_date_range(S, E){
var m1=BUS['dms']['m'];
var m3=BUS['dms']['m3'];
var R='';
if(wv_range_format[0].includes('MMMM')){
R +=m1[ S.month()+1 ]+ ' '+ S.date();
}else if(wv_range_format[0].includes('MM')){
R +=m3[ S.month()+1 ]+ ' '+ S.date();
}
if(wv_range_format[0].includes('YYYY')){
R +=', '+ S.year();
}
R+=' - ';
if(wv_range_format[1].includes('MMMM')){
R +=m1[ E.month()+1 ]+ ' '+ E.date();
}else if(wv_range_format[1].includes('MM')){
R +=m3[ E.month()+1 ]+ ' '+ E.date();
}
if(wv_range_format[1].includes('YYYY')){
R +=', '+ E.year();
}
return R;
}
$('body')
.on('mouseover','em.dayTag',function(){
OBJ=$(this);
PAR=OBJ.closest('.EVOWV_grid');
p=OBJ.offset();
t=PAR.offset();
w=PAR.width();
xleft=p.left - t.left;
xtop=p.top - t.top;
TITLE=OBJ.attr('title');
if((w/2) > xleft){
HTML="<em class='evowv_tooltip' style='top:"+(xtop-40)+"px;left:"+(xleft+3)+"px;'>"+TITLE+"</em>";
}else{
xright=w - xleft;
HTML="<em class='evowv_tooltip left' style='top:"+(xtop-40)+"px;right:"+(xright-3)+"px;'>"+TITLE+"</em>";
}
PAR.append(HTML);
}).on('mouseout','em.dayTag',function(){
OBJ=$(this);
OBJ.closest('.EVOWV_grid').find('.evowv_tooltip').remove();
})
.on('click', '.evowv_tb_event',function(){
O=$(this);
CAL=O.closest('.ajde_evcal_calendar');
var e_cl='event_'+O.data('ec');
CAL.evo_update_cal_sc({F:'ux_val',V:'3'});
const clicked_event_uxval=O.data('uxval');
if(clicked_event_uxval=='1'){
CAL.find('.'+e_cl).find('.desc_trig').data('ux_val', 3);
}
if(clicked_event_uxval=='3a'||clicked_event_uxval=='4'||clicked_event_uxval=='4a'
){
CAL.evo_update_cal_sc({F:'ux_val',V: clicked_event_uxval });
}
CAL.find('.'+e_cl).find('.desc_trig').trigger('click');
})
.on('evo_vSW_clicked_before_ajax',function(event, O, CAL, DD, reload_cal_data){
if(!(O.hasClass('evowv'))) return;
var SC=CAL.evo_shortcode_data();
CAL.evo_update_cal_sc({F:'calendar_type', V: 'weekly'});
})
.on('evo_vSW_clicked',function(event, OBJ, CAL, DD){
if(!(OBJ.hasClass('evowv'))) return;
var SC=CAL.evo_shortcode_data();
var DATA=OBJ.data('d');
const cal_tz=CAL.evo_get_global({S1:'cal_def',S2:'cal_tz'});
_M1=moment().set({'year': SC.fixed_year, 'month':(SC.fixed_month -1), 'date':SC.fixed_day, 'hour':0,'minute':0}).tz(cal_tz);
_M1.startOf('date');
var sow=DATA.sow;
var today_day=_M1.day();
var dayDif=_in_ws='';
if(sow >1) dayDif=today_day -(sow-1);
if(today_day > sow) dayDif=today_day - sow;
if(today_day==sow) dayDif=0;
if(sow > today_day) dayDif=7 - sow;
if(dayDif!=0) _M1.subtract(dayDif ,'days');
_in_ws=_M1.unix();
CAL.evo_update_cal_sc({	F:'focus_start_date_range',	V: _M1.unix() });
_M1.add(6, 'days').endOf('date');
CAL.evo_update_cal_sc({	F:'focus_end_date_range', 	V: _M1.unix() });
CAL.evo_update_cal_sc({F:'fixed_day', V: SC.fixed_day });
CAL.evo_update_cal_sc({F:'calendar_type',V: 'weekly'});
CAL.evo_update_cal_sc({F:'_in_ws',V: _in_ws });
CAL.evo_update_cal_sc({F:'disable_week_switch',V: 'no'});
CAL.evo_update_cal_sc({F:'table_style',V: '0'});
CAL.evo_update_cal_sc({F:'week_style',V: '0'});
draw_week_grid(CAL);
CAL.evo_cal_events_in_range({
S: CAL.evo_get_sc_val({'F':'focus_start_date_range'}),
E: CAL.evo_get_sc_val({'F':'focus_end_date_range'}),
showEV:true,
showEVL:true
});
})
.on('click','.evowv_this_weekbtn',function(){
CAL=$(this).closest('.ajde_evcal_calendar');
week_incre=parseInt($(this).data('week_incre'));
new_week(CAL, week_incre, 'wv_newweek');
CAL.find('.evowv_this_weekbtn').remove();
})
.on('click','.evo_wv_day', function(){
OBJ=O = $(this);
CAL=OBJ.closest('.ajde_evcal_calendar');
SC=CAL.evo_shortcode_data();
if(CAL.hasClass('evoWV_tb')) return;
showEVL=true;
if(O.hasClass('focus_d')){
SC=CAL.evo_shortcode_data();
O.removeClass('focus_d');
SU=parseInt(SC.focus_start_date_range);
EU=parseInt(SC.focus_end_date_range);
showEVL=false;
}else{
OBJ.siblings().removeClass('focus_d');
OBJ.addClass('focus_d');
SU=parseInt(O.data('su'));
EU=parseInt(O.data('eu'));
}
R=CAL.evo_cal_events_in_range({
S: SU,
E: EU,
closeEC: true,
showEV: true,
showEVL: showEVL
});
if(SC.hide_events_onload=='yes'&&!(O.hasClass('focus_d'))){
CAL.find('.eventon_events_list').hide().addClass('evo_hide');
}})
;
$('body')
.on('click', '.EVOWV_change', function(event){
event.preventDefault();
event.stopPropagation();
el=$(this);
CAL=el.closest('.ajde_evcal_calendar');
if(el.hasClass('on')){
_HTML=get_week_switcher_weeks(CAL , 'reset');
CAL.find('.EVOWV_date_ranges').html(_HTML);
CAL.find('.EVOWV_ranger').hide();
el.removeClass('on');
}else{
CAL.find('.EVOWV_ranger').show();
el.addClass('on');
}})
.on('click','.EVOWV_range_mover',function(event){
event.preventDefault();
event.stopPropagation();
var OBJ=$(this),
UL=OBJ.siblings('.EVOWV_ranger_handle').find('ul');
CAL=$(this).closest('.ajde_evcal_calendar');
UL.find('li').addClass('O');
if(OBJ.hasClass('up')){
UL=CAL.find('.EVOWV_date_ranges');
_HTML=get_week_switcher_weeks(CAL , -5);
UL.prepend(_HTML);
UL.css({'top':-150});
UL.animate({'top':0},400,function(){
UL.find('.O').remove();
});
}else{
UL=CAL.find('.EVOWV_date_ranges');
_HTML=get_week_switcher_weeks(CAL , 5);
UL.append(_HTML);
UL.css({'top':0});
UL.animate({'top':-150},400,function(){
UL.find('.O').remove();
UL.css({'top':0});
});
}});
$('body').on('click', '.evowv_arrow', function(event){
event.preventDefault();
var CAL=$(this).closest('.ajde_evcal_calendar');
week_incre=parseInt(CAL.evo_get_sc_val({F:'week_incre'}));
week_incre = !week_incre ? 0: week_incre;
adj=parseInt($(this).data('week'));
new_week_incre=week_incre + adj;
__populate_preload_content(CAL);
new_week(CAL , new_week_incre, 'wv_newweek');
});
$('body').on('click','.EVOWV_date_ranges li',function(){
var CAL=$(this).closest('.ajde_evcal_calendar');
week_incre=parseInt($(this).data('week_incre'));
new_week(CAL, week_incre, 'wv_newweek');
$(this).closest('.EVOWV_ranger').hide();
});
$('body').on('evo_main_ajax_success',function(event, CAL, ajaxtype, data, data_arg){
SC=data_arg.shortcode;
if(SC.calendar_type=='weekly'){
CAL.find('.eventon_events_list').removeClass('evowv_hide');
}});
$('body').on('evo_main_ajax_complete', function(event, CAL,  ajaxtype, data , data_arg){
SC=data_arg.shortcode;
if(SC.calendar_type=='weekly'){
draw_week_grid(CAL);
CAL.find('.evowv_preload_grid').html('');
}});
function new_week(CAL,   week_incre, ajaxtype){
SC=CAL.evo_shortcode_data();
CAL.evo_update_cal_sc({F:'week_incre', V: week_incre});
__populate_preload_content(CAL);
$('body').trigger('evo_run_cal_ajax', [ CAL.attr('id'), 'none', ajaxtype]);
}
function is_mobile(){
return(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) )? true: false;
}});