var ep_map, ep_can_drag_map, ep_view, ep_vectorSource, ep_feature, ep_proj_source, ep_proj_destination, marker, ep_marker, lat, lon, map_id, ep_geoloasked = false, ep_geolocalized = false, ep_currentloc = [0, 0];
// DATE
/**
*
* @param {type} str
* @returns {unresolved}
*/
function eventpost_numdate(str) {
var r = new RegExp("[-: T/]", "g");
if (str.replace) {
str = str.replace(r, '');
}
return parseInt(str);
}
/**
*
* @param {type} field
* @returns {unresolved|String}
*/
function eventpost_getdate(field) {
d = jQuery('#' + field + '_date').val();
return d ? eventpost_numdate(d.substring(0, 16) + ':00') : '';
}
/**
*
* @param {type} field
* @returns {jQuery}
*/
function eventpost_getdate_sql(field) {
return jQuery('#' + field + '_date').val();
}
/**
*
* @returns {undefined}
*/
function eventpost_concat_time() {
jQuery('.eventpost-datepicker-simple-wrap').each(function () {
d = jQuery(this).find('.eventpost-datepicker-simple-date').val() + ' '
+ jQuery(this).find('.eventpost-datepicker-simple-hour').val() + ':'
+ jQuery(this).find('.eventpost-datepicker-simple-time').val() + ':00';
jQuery(this).find('.eventpost-datepicker-simple').val(d);
});
jQuery('.eventpost-datepicker-native-wrap').each(function () {
year = parseInt(jQuery(this).find('.eventpost-datepicker-native-year').val());
month = parseInt(jQuery(this).find('.eventpost-datepicker-native-month').val());
if(month<10){
month='0'+month;
}
day = parseInt(jQuery(this).find('.eventpost-datepicker-native-day').val());
if(day<10){
day='0'+day;
}
hour = parseInt(jQuery(this).find('.eventpost-datepicker-native-hour').val());
if(hour<10){
hour='0'+hour;
}
minute = parseInt(jQuery(this).find('.eventpost-datepicker-native-minute').val());
if(minute<10){
minute='0'+minute;
}
d = year + '-'
+ month + '-'
+ day + ' '
+ (isNaN(hour)?'00':hour) + ':'
+ (isNaN(minute)?'00':minute) + ':00';
jQuery(this).find('.eventpost-datepicker-native').val(d);
});
}
function eventpost_set_allday(){
set = jQuery('#event-post-date-all-day').is(':checked');
if(set===true){
jQuery('.eventpost-datepicker-native-hour, .eventpost-datepicker-native-minute, .eventpost-datepicker-simple-hour, .eventpost-datepicker-simple-time').val('00').trigger('change').parent().hide(300);
}
else{
jQuery('.eventpost-datepicker-native-hour, .eventpost-datepicker-native-minute, .eventpost-datepicker-simple-hour, .eventpost-datepicker-simple-time').parent().show(300);
}
}
/**
*
* @returns {undefined}
*/
function eventpost_chkdate() {
//console.log('change date');
var date_start = eventpost_getdate(eventpost.META_START);
var date_end = eventpost_getdate(eventpost.META_END);
//console.log(date_start + ' ' + date_end);
if (date_end === '' || date_start > date_end) {
jQuery('#' + eventpost.META_END + '_date').val(jQuery('#' + eventpost.META_START + '_date').val());
jQuery('#' + eventpost.META_END + '_date').parents('label').find('.human_date').html(jQuery('#' + eventpost.META_START + '_date').parents('label').find('.human_date').html());
jQuery('#' + eventpost.META_END + '_date').parents('label').effect( "shake" );
fields = [
'simple-date',
'simple-hour',
'simple-time',
'native-year',
'native-month',
'native-day',
'native-hour',
'native-minute',
]
for(f in fields){
fname = fields[f];
jQuery('.eventpost-datepicker-'+fname, jQuery('#' + eventpost.META_END + '_date').parents('label')).val(jQuery('.eventpost-datepicker-'+fname, jQuery('#' + eventpost.META_START + '_date').parents('label')).val());
}
jQuery(".eventpost-datepicker-control", jQuery('#' + eventpost.META_END + '_date').parents('label')).last().trigger('change');
date_end = date_start;
}
//console.log(date_start);
// UI
if (date_start === 0) {
jQuery('.event-post-event_begin_date-remove').hide();
} else {
jQuery('.event-post-event_begin_date-remove').show();
}
if (date_end === 0) {
jQuery('.event-post-event_end_date-remove').hide();
} else {
jQuery('.event-post-event_end_date-remove').show();
}
}
// MAP
/**
*
* @param {type} location
* @returns {undefined}
*/
function eventpost_getlocation(location) {
ep_currentloc = [location.coords.latitude, location.coords.longitude];
}
/**
*
* @returns {Array|ep_currentloc}
*/
function eventpost_location() {
if ("geolocation" in navigator) {
if (ep_geoloasked === false) {
ep_geoloasked = true;
navigator.geolocation.getCurrentPosition(eventpost_getlocation);
var watchID = navigator.geolocation.watchPosition(function (position) {
if (ep_geolocalized === false) {
ep_geolocalized = true;
eventpost_getlocation(position);
eventpost_apply('', ep_currentloc[0], ep_currentloc[1]);
}
});
} else if (ep_geolocalized === true) {
eventpost_apply('', ep_currentloc[0], ep_currentloc[1]);
}
}
if (ep_currentloc !== 'no') {
return ep_currentloc;
} else {
return [lat, lon];
}
}
/**
*
* @param {type} addr
* @param {type} lat
* @param {type} lon
* @returns {undefined}
*/
function eventpost_apply(addr, lat, lon) {
if (jQuery('#geo_address').val() === '' && addr !== '') {
jQuery('#geo_address').val(addr);
}
jQuery('#geo_latitude').val(lat);
jQuery('#geo_longitude').val(lon).trigger('change');
eventpost_search_form();
}
/**
*
* @returns {undefined}
*/
function eventpost_edit() {
sctype = jQuery('#ep_sce_type').val();
if (sctype === 'list') {
jQuery('#ep_sce_maponly').hide();
jQuery('#ep_sce_listonly').show();
}
if (sctype === 'map') {
jQuery('#ep_sce_maponly').show();
jQuery('#ep_sce_listonly').hide();
}
var ep_sce = '[events_' + sctype;
jQuery('#event_post_sc_edit input,#event_post_sc_edit select').each(function () {
if (!jQuery(this).hasClass('event_post_sc_no_use')) {
var pc = jQuery(this).parent().parent().parent().attr('class');
var att = jQuery(this).data('att');
var val = jQuery(this).val();
if (att !== null && val !== '' && (pc === 'all' || pc === sctype)) {
ep_sce += ' ' + att + '="' + val + '"';
}
}
});
ep_sce += ']';
jQuery('#ep_sce_shortcode').html(ep_sce);
}
/**
*
* @param {type} str
* @returns {undefined}
*/
function eventpost_insertcontent(str) {
if (IEbof) {
switchEditors.go('content', 'html');
document.post.content.value += str;
switchEditors.go('content', 'tinymce');
} else {
document.post.content.value += str;
if (document.all) {
value = str;
document.getElementById('content_ifr').name = 'content_ifr';
var ec_sel = document.getElementById('content_ifr').document.selection;
if (tinyMCE.activeEditor.selection) {
tinyMCE.activeEditor.selection.setContent(str);
} else if (tinyMCE.activeEditor) {
tinyMCE.activeEditor.execCommand("mceInsertRawHTML", false, str);
} else if (ec_sel) {
var ec_rng = ec_sel.createRange();
ec_rng.pasteHTML(value);
} else {
}
} else {
document.getElementById('content_ifr').name = 'content_ifr';
if (document.content_ifr) {
document.content_ifr.document.execCommand('insertHTML', false, str);
} else if (document.getElementById('content_ifr').contentDocument) {
document.getElementById('content_ifr').contentDocument.execCommand('insertHTML', false, str);
} else if (tinyMCE.activeEditor.selection) {
tinyMCE.activeEditor.selection.setContent(str);
} else {
tinyMCE.activeEditor.execCommand("mceInsertRawHTML", false, str);
}
}
}
}
/**
*
* @returns {undefined}
*/
function eventpost_search_location() {
var addr = jQuery('#event_address_search_txt').attr('value');
if (addr === '') {
eventpost_search_form();
jQuery('#eventaddress_result').append('' + eventpost.empty_address + '');
return;
}
//console.log(addr);
var data = {
action: 'EventPostGetLatLong',
q: addr
};
jQuery('#eventaddress_result').html(addr + '
');
jQuery.post(eventpost.ajaxurl, data, function (data) {
eventpost_search_form();
var html_ret = '';
for (var lieu in data) {
//console.log(data[lieu]);
lieu = data[lieu];
if (lieu.lat !== undefined && lieu.lon !== undefined && lieu.display_name !== undefined) {
html_ret += '
';
if (lieu.icon !== undefined) {
html_ret += '';
}
html_ret += lieu.display_name + '