Show optionally a clock in the header (closes #109)

This commit is contained in:
Bernd Bestel
2018-11-20 19:23:48 +01:00
parent 589ad36855
commit f7f90238f2
5 changed files with 60 additions and 1 deletions

37
public/js/grocy_clock.js Normal file
View File

@@ -0,0 +1,37 @@
$("#show-clock-in-header").on("change", function ()
{
CheckHeaderClockEnabled();
});
function RefreshHeaderClock()
{
$("#clock-small").text(moment().format("l LT"));
$("#clock-big").text(moment().format("LLLL"));
}
Grocy.HeaderClockInterval = null;
function CheckHeaderClockEnabled()
{
// Refresh the clock in the header every second when enabled
if (BoolVal(Grocy.UserSettings.show_clock_in_header))
{
RefreshHeaderClock();
$("#clock-container").removeClass("d-none");
Grocy.HeaderClockInterval = setInterval(function()
{
RefreshHeaderClock();
}, 1000);
}
else
{
if (Grocy.HeaderClockInterval !== null)
{
clearInterval(Grocy.HeaderClockInterval);
Grocy.HeaderClockInterval = null;
}
$("#clock-container").addClass("d-none");
}
}
CheckHeaderClockEnabled();