Skip to content

Commit

Permalink
make first Weekday configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
wernerjoss committed Mar 22, 2023
1 parent 95646cd commit 50d682d
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 90 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v0.3.4
## 03/20/2023

1. [](#new)
* make first Weekday configurable

# v0.3.3
## 09/01/2022

Expand Down
31 changes: 18 additions & 13 deletions assets/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ function whenJqReady() {
var defaultLocale = 'en';
var cfgWeekNums = jQuery('#weeknums').text(); // get Paramter from DOM
weekNums = false;
var firstWeekDay = 0; // Default, new 20.03.23
var cfgfirstWeekDay = jQuery('#1stweekday').text(); // get Paramter from DOM
if (Number(cfgfirstWeekDay) > 0) firstWeekDay = Number(cfgfirstWeekDay);
if (verbose) console.log("1st Weekday: ", firstWeekDay);
if (cfgWeekNums > 0) weekNums = true;
if (verbose) console.log('Weeknums:', weekNums);
var cfgLocale = jQuery('#cfgLocale').text(); // get Paramter from DOM
Expand Down Expand Up @@ -100,23 +104,23 @@ function whenJqReady() {
var showlegend = jQuery('#showlegend').text(); // get Paramter from DOM'
showlegend = (showlegend > 0) ? showlegend : false;
if (verbose) console.log('showlegend:', showlegend);

var defaultEnableDescPopup = false; // DONE: make this configurable via admin
var cfg_enableDescPopup = jQuery('#enableDescPopup').text();
var enableDescPopup = (cfg_enableDescPopup !== null) ? cfg_enableDescPopup : defaultEnableDescPopup;

var cfg_tz_offset_single = jQuery('#tzoffset_single').text(); // Offset for single Events
var default_tz_offset_single = 0; // Default
var tz_offset_single = (cfg_tz_offset_single !== null) ? cfg_tz_offset_single : default_tz_offset_single;

var cfg_tz_offset_minutes = jQuery('#tzoffset_minutes').text(); // minutes Offset for single Events
var default_tz_offset_minutes = 0; // Default
var tz_offset_minutes = (cfg_tz_offset_minutes !== null) ? cfg_tz_offset_minutes : default_tz_offset_minutes;

var cfg_tz_offset_rec = jQuery('#tzoffset_recur').text(); // Offset for single Events
var default_tz_offset_rec = 0; // Default
var tz_offset_rec = (cfg_tz_offset_rec !== null) ? cfg_tz_offset_rec : default_tz_offset_rec;

var useIcsTimezone = jQuery('#useIcsTimezone').text(); // get Paramter from DOM'
useIcsTimezone = (useIcsTimezone > 0) ? useIcsTimezone : false;
var icsTimezone = 'Europe/Berlin'; // Default
Expand All @@ -139,7 +143,7 @@ function whenJqReady() {
// console.log(data);
var jcalData = ICAL.parse(data); // directly parse data, no need to split to lines first ! 14.02.20
var comp = new ICAL.Component(jcalData);

var tzComps = comp.getAllSubcomponents("vtimezone");
tzids = jQuery.map(tzComps, function(item) {
var entry = item.getFirstPropertyValue("tzid");
Expand Down Expand Up @@ -180,7 +184,7 @@ function whenJqReady() {
var calTimezone = 'local'; // Default
if (useIcsTimezone) calTimezone = icsTimezone;
if (verbose) console.log('calTimezone: ', calTimezone);

// page is now ready, initialize the calendar...
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
Expand All @@ -196,6 +200,7 @@ function whenJqReady() {
editable: false,
eventLimit: false, // allow "more" link when too many events
fixedWeekCount: false,
firstDay: firstWeekDay, // new 20.03.23 - DONE: make this configurable !
eventClick: function(info) {
info.jsEvent.preventDefault(); // don't let the browser navigate
// console.log(info.event.extendedProps["description"]);
Expand Down Expand Up @@ -243,11 +248,11 @@ function whenJqReady() {
// $( '#test' ).html(data);
}
})
.done(function( data, textStatus, jqXHR ) {
.done(function( data, textStatus, jqXHR ) {
if (verbose) console.log(data);
var jcalData = ICAL.parse(data); // directly parse data, no need to split to lines first ! 14.02.20
var comp = new ICAL.Component(jcalData);

var comp = new ICAL.Component(jcalData);
var eventComps = comp.getAllSubcomponents("vevent");
// map them to FullCalendar events Objects
Expand All @@ -269,7 +274,7 @@ function whenJqReady() {
if (entry !== null) fcevents["url"] = entry;
var entry = item.getFirstPropertyValue("dtstart");
if (entry !== null) { fcevents["start"] = entry.toJSDate(); var start = entry;}

// tz_offset_single = 0; // now from plugin config 01.01.22
if (verbose) console.log('tz_offset_single:', tz_offset_single);
if (tz_offset_single != 0) {
Expand All @@ -284,7 +289,7 @@ function whenJqReady() {
fcevents["start"] = start.toJSDate();
if (verbose) console.log('newstart', start);
}

var entry = item.getFirstPropertyValue("dtend");
if (entry !== null) { fcevents["end"] = entry.toJSDate(); var end = entry; }
duration = fcevents["end"] - fcevents["start"]; // calculate event duration 29.08.20
Expand Down Expand Up @@ -321,8 +326,8 @@ function whenJqReady() {
var tz_offset_dl = parseInt(tz_offset_rec); // default
M = parseInt(start["month"]);
// console.log('Month:', M); // start["month"]);
if ((M > dlstart) && (M <= dlend)) {
tz_offset_dl = tz_offset_dl + 1; // add 1h during DAYLIGHT saving period
if ((M > dlstart) && (M <= dlend)) {
tz_offset_dl = tz_offset_dl + 1; // add 1h during DAYLIGHT saving period
} // DONE: get DAYLIGHT Start/Endmonth from ICS
// console.log(tz_offset_dl);
if (tz_offset_dl != 0) {
Expand Down
136 changes: 68 additions & 68 deletions assets/monthpic.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
/* new approach for update month picture upon next - prev - home click
evaluate Text in Month div fc-center: this is the Month name in current locale
build pic name from that.
pic files must be named like months in current locale !
*/

$(document).ready(function() {
var debug = false;
var lastmonthname = null;
if($('#actMonth').length){ // do not setup image load/change when div actMonth does not exist
setInterval(function() { // statt setTimeout() - siehe https://www.w3schools.com/jsref/met_win_settimeout.asp
function fileExists(filename) {
var response = $.ajax({
url: filename,
type: 'HEAD',
async: false // does not work with true :-/
}).status;
if (debug) console.log('response:',response);
return (response != "200") ? false : true;
}
var activemonth = $('div.fc-center h2').text(); // fc 4.3
if (debug) console.log('activemonth:', activemonth);
var monthname = activemonth.split(" ")[0];

if (monthname.length > 0) {
var path = document.location.pathname;
var monthpic = path + '/' + monthname + '.jpg';
if (debug) console.log('monthpic:', monthpic);
if (monthname != lastmonthname) {
if (debug) console.log('monthpic:', monthpic);
if (fileExists(monthpic)) { // 25.08.20 see https://github.com/wernerjoss/grav-plugin-fullcalendar/issues/20
$.ajax({
type: "HEAD",
async: true,
url: window.location + '/' + monthname + '.jpg'
}).done(function() {
if (debug) console.log("monthpic found");
if (document.getElementById('actMonth') != null) document.getElementById('actMonth').innerHTML = "<img src=" + monthpic + ">";
}).fail(function() {
if (debug) console.log(window.location + '/' + monthname + '.jpg' + ' not found');
})
lastmonthname = monthname;
$(".fc-button").click(function() { // fc-button ist für vor UND zurück !
activemonth = $('div.fc-center h2').text(); // fc 4.3
if (debug) console.log('button clicked, month:', activemonth, 'lastmonth:', lastmonthname);
monthname = activemonth.split(" ")[0];
if (lastmonthname != monthname) {
lastmonthname = monthname;
$.ajax({
type: "HEAD",
async: true,
url: window.location + '/' + monthname + '.jpg'
}).done(function() {
if (debug) console.log("new monthpic found");
monthpic = path + '/' + monthname + '.jpg';
if (document.getElementById('actMonth') != null) document.getElementById('actMonth').innerHTML = "<img src=" + monthpic + ">";
}).fail(function() {
if (debug) console.log(window.location + '/' + monthname + '.jpg' + ' not found');
})
}
});
}
}
}
}, 2500); // was: 1000
}
})
/* new approach for update month picture upon next - prev - home click
evaluate Text in Month div fc-center: this is the Month name in current locale
build pic name from that.
pic files must be named like months in current locale !
*/

$(document).ready(function() {
var debug = false;
var lastmonthname = null;

if($('#actMonth').length){ // do not setup image load/change when div actMonth does not exist
setInterval(function() { // statt setTimeout() - siehe https://www.w3schools.com/jsref/met_win_settimeout.asp
function fileExists(filename) {
var response = $.ajax({
url: filename,
type: 'HEAD',
async: false // does not work with true :-/
}).status;
if (debug) console.log('response:',response);
return (response != "200") ? false : true;
}
var activemonth = $('div.fc-center h2').text(); // fc 4.3
if (debug) console.log('activemonth:', activemonth);
var monthname = activemonth.split(" ")[0];

if (monthname.length > 0) {
var path = document.location.pathname;
var monthpic = path + '/' + monthname + '.jpg';
if (debug) console.log('monthpic:', monthpic);
if (monthname != lastmonthname) {
if (debug) console.log('monthpic:', monthpic);
if (fileExists(monthpic)) { // 25.08.20 see https://github.com/wernerjoss/grav-plugin-fullcalendar/issues/20
$.ajax({
type: "HEAD",
async: true,
url: window.location + '/' + monthname + '.jpg'
}).done(function() {
if (debug) console.log("monthpic found");
if (document.getElementById('actMonth') != null) document.getElementById('actMonth').innerHTML = "<img src=" + monthpic + ">";
}).fail(function() {
if (debug) console.log(window.location + '/' + monthname + '.jpg' + ' not found');
})
lastmonthname = monthname;
$(".fc-button").click(function() { // fc-button ist für vor UND zurück !
activemonth = $('div.fc-center h2').text(); // fc 4.3
if (debug) console.log('button clicked, month:', activemonth, 'lastmonth:', lastmonthname);
monthname = activemonth.split(" ")[0];
if (lastmonthname != monthname) {
lastmonthname = monthname;
$.ajax({
type: "HEAD",
async: true,
url: window.location + '/' + monthname + '.jpg'
}).done(function() {
if (debug) console.log("new monthpic found");
monthpic = path + '/' + monthname + '.jpg';
if (document.getElementById('actMonth') != null) document.getElementById('actMonth').innerHTML = "<img src=" + monthpic + ">";
}).fail(function() {
if (debug) console.log(window.location + '/' + monthname + '.jpg' + ' not found');
})
}
});
}
}
}
}, 2500); // was: 1000
}
})
8 changes: 7 additions & 1 deletion blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: FullCalendar
version: 0.3.3
version: 0.3.4
description: show Calendar Widget from ICS File(s), based on fullcalendar.io
icon: calendar
author:
Expand Down Expand Up @@ -103,5 +103,11 @@ form:
label: Time Offset (hours) to correct recurring Events
help: only use this if you encounter a Time shift on displayed recurring Events
default: 0
firstWeekDay:
type: number
size: small
label: first Day of Week
help: 0 for Sunday, 1 for Monday, 2 for Tuesday ...
default: 0


3 changes: 2 additions & 1 deletion fullcalendar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ useIcsTimezone: false
enableDescPopup: false
tz_offset_single: 0
tz_offset_rec: 0
enableOnAllPages: false
enableOnAllPages: false
firstWeekDay: 1
16 changes: 9 additions & 7 deletions templates/calendar.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@
{% set num_mpics = 0 %}
{% set calendars = [] %} {# empty array #}
{% for file in page.media %}
{% if debug %} {{ dump(file|print_r) }} {% endif %}
{#
{% if debug %} {{ dump('file:',file|print_r) }} {% endif %}
#}
{% if (file.filename|ends_with('.ics')) %}
{% if (debug) %} {{ dump(file.filename|string) }} {% endif %}
{% if (debug) %} {{ dump('calendarfile:',file.filename|string) }} {% endif %}
{% set calendars = calendars|merge([file.filename|string]) %}
{% set numcalendars = numcalendars + 1 %}
{% endif %}
{% if (file.filename|ends_with('.jpg')) %}
{% if (debug) %} {{ dump(file.filename|string) }} {% endif %}
{% if (debug) %} {{ dump('monthpic:',file.filename|string) }} {% endif %}
{% set num_mpics = num_mpics + 1 %}
{% endif %}
{% endfor %}
{% if (debug) %}
{{ dump(numcalendars) }}
{{ dump(num_mpics) }}
{{ dump(calendars|print_r) }}
{% if (debug) %}
{{ dump('numcalendars:',numcalendars) }}
{{ dump('num_pics:',num_mpics) }}
{{ dump('calendars:',calendars|print_r) }}
{% endif %}
{% if (num_mpics|int) >= 12 %} {# 12 pics sollten für 1 Jahr reichen :-) #}
<div id='actMonth'></div>
Expand Down
1 change: 1 addition & 0 deletions templates/partials/fullcalendar.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
<div id='tzoffset_single' style='display:none;'>{{ config.plugins.fullcalendar.tz_offset_single }}</div>
<div id='tzoffset_minutes' style='display:none;'>{{ config.plugins.fullcalendar.tz_offset_minutes }}</div>
<div id='tzoffset_recur' style='display:none;'>{{ config.plugins.fullcalendar.tz_offset_rec }}</div>
<div id='1stweekday' style='display:none;'>{{ config.plugins.fullcalendar.firstWeekDay }}</div>

0 comments on commit 50d682d

Please sign in to comment.