Laddar aktiviteter...
Aktiviteter
var url = "/evenemang/kategori/for-kvinnor/"
jQuery(document).ready(function(){
jQuery("#calContent").hide();
jQuery("#calContentLoader").show();
jQuery.get(url+"?ical=1&tribe_display=list", function(data){
var lines = data.split("\n");
var events = {}
var events_i = 0;
for (i = 0; i < lines.length; i++) {
if(lines[i].includes('BEGIN:VEVENT')){
events[events_i] = {};
}
else if (lines[i].includes('DTSTART')) {
var date = lines[i].split(":");
events[events_i]['startDate'] = dateParser(date[1]);
events[events_i]['rawStartDate'] = date[1];
}
else if (lines[i].includes('SUMMARY')) {
var title = lines[i].split(":");
events[events_i]["title"] = cleanText(title[1]);
}else if(lines[i].includes('DESCRIPTION')){
var t = lines[i].replace("DESCRIPTION:", "")
events[events_i]["description"] = cleanText(t);
}else if(lines[i].includes('CATEGORIES:')){
var t = lines[i].replace("CATEGORIES:", "")
events[events_i]["categories"] = cleanText(t);
}
else if(lines[i].includes('DTEND')){
var t = lines[i].split(":");
events[events_i]["endDate"] = dateParser(t[1]);
events[events_i]['rawEndDate'] = t[1];
}else if(lines[i].includes('URL:') && !lines[i].includes('X-ORIGINAL-URL:')){
var t = lines[i].replace("URL:", "");
events[events_i]["href"] = t[1];
}
else if (lines[i].includes('END:VEVENT')) {
events_i++;
}
}
if(Object.values(events).length == 0){
jQuery("#calContent").html("
Inga kommande aktiviteter
");
jQuery("#calContent").fadeIn();
jQuery("#calContentLoader").fadeOut();
}
function dateParser(str){
var year = str.substr(0,4);
var month = parseInt(str.substr(4,2)) - 1;
var day = str.substr(6,2);
var hour = str.substr(9,2);
var minute = str.substr(11,2);
var d = new Date(year, month, day, hour, minute, 00, 00);
console.log(d);
console.log(hour);
return d;
}
function cleanText(str){
str = str.replace(/(\\r\\n|\\r|\\n)/g, '
');
str = str.replace(/(\\,)/g, ',');
return str;
}
function hourMinFix(t){
if(t < 10){
return "0"+t;
}
return t;
}
function outputDate(startDate, endDate, fullDay){
var monthNames = [
"Januari", "Februari", "Mars",
"April", "Maj", "Juni", "Juli",
"Augusti", "September", "Oktober",
"November", "December"
];
var days = ["Söndag", "Måndag", "Tisdag", "Onsdag", "Torsdag", "Fredag", "Lördag"]
if(fullDay){
endDate.setDate(endDate.getDate()-1);
}
if(fullDay && startDate.getDate() == endDate.getDate()){
return days[startDate.getDay()] +" "+ startDate.getDate() + " " + monthNames[startDate.getMonth()];
}else if(fullDay && startDate.getDate() != endDate.getDate()){
return days[startDate.getDay()] +" "+ startDate.getDate() + " "+ monthNames[startDate.getMonth()] + " till " + endDate.getDate() + " "+ monthNames[endDate.getMonth()]
}else if(!fullDay){
if(startDate.getDate() == endDate.getDate()){
if(startDate.getHours() == endDate.getHours()){
return days[startDate.getDay()] +" "+ startDate.getDate()+ " "+ monthNames[startDate.getMonth()] + " kl. " + hourMinFix(startDate.getHours()) +":"+hourMinFix(startDate.getMinutes());
}else{
return days[startDate.getDay()] +" "+ startDate.getDate()+ " "+ monthNames[startDate.getMonth()] + " kl. " + hourMinFix(startDate.getHours()) +":"+hourMinFix(startDate.getMinutes()) + "-"+hourMinFix(endDate.getHours()) +":"+ hourMinFix(endDate.getMinutes());
}
}else{
return days[startDate.getDay()] +" "+ startDate.getDate()+ " "+ monthNames[startDate.getMonth()] + " kl. " + hourMinFix(startDate.getHours()) +":"+hourMinFix(startDate.getMinutes()) + "-"+ endDate.getDate()+ " "+ monthNames[endDate.getMonth()] +" "+hourMinFix(endDate.getHours()) +":"+hourMinFix(endDate.getMinutes());
}
}
}
Object.values(events).forEach(function(event){
var fullDay = false;
if(!event.rawStartDate.includes("T") && !event.rawEndDate.includes("T")){
fullDay = true;
}
var c = jQuery("
").addClass("man-cal")
var e = jQuery("
").addClass("man-cal-content");
var t = jQuery("
").addClass("man-cal-header");
var cat = jQuery("
").addClass("man-cal-header-category");
var d = jQuery("
").addClass("man-cal-description");
var s = jQuery("
").addClass("man-cal-timestamp");
t.html(event.title);
d.html(event.description);
if(event.categories){
cat.html(event.categories);
t.append(cat);
}
s.html(outputDate(event.startDate, event.endDate, fullDay));
e.append(t);
e.append(s);
e.append(d);
c.append(e);
jQuery("#calContent").append(c);
});
jQuery("#calContent").fadeIn();
jQuery("#calContentLoader").fadeOut();
}
)
});
#calContent{
margin-top: 15px;
}
.man-cal{
padding-bottom: 15px;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
padding-right: 10px;
padding-left: 10px;
margin-bottom: 10px;
}
.man-cal-content{
padding: 15px 30px;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: start;
-webkit-justify-content: flex-start;
-ms-flex-pack: start;
justify-content: flex-start;
overflow: hidden;
position: relative;
background-color: #fff;
width: 100%;
border: 0 solid #818a91;
-webkit-transition: all .25s;
-o-transition: all .25s;
transition: all .25s;
-webkit-box-shadow: 0 0 10px 0 rgba(0,0,0,.15);
box-shadow: 0 0 10px 0 rgba(0,0,0,.15);
}
.man-cal-header{
font-family: 'Calibri';
}
.man-cal-timestamp{
font-weight: bold;
}
#calContentLoader{
text-align: center;
font-size: 20px;
}
.man-cal-header-category{
font-size: 16px;
background: #4095d2!important;
padding: 2px 4px;
color: #FFF;
line-height: 16px;
border-radius: 2px;
}
.man-cal-noentries{
text-align: center;
background: #fff6c4;
padding: 10px 20px;
color: #b7a331;
border-radius:4px;
}