Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce auto hide option which hides the module if the event is in the past #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion MMM-CountDown.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ Module.register("MMM-CountDown",{
hoursLabel: 'h',
minutesLabel: 'm',
secondsLabel: 's',
autoHide: false,
},

// set update interval
start: function() {
var self = this;
setInterval(function() {
self.updateDom(); // no speed defined, so it updates instantly.
}, this.config.customInterval);
}, this.config.customInterval);
},

// Update function
Expand All @@ -36,6 +37,11 @@ Module.register("MMM-CountDown",{
var target = new Date(this.config.date);
var timeDiff = target - today;

// don't show the module if the event is in the past
if (this.config.autoHide === true && timeDiff < 0) {
this.hide();
}

// Set days, hours, minutes and seconds
var diffDays = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
var diffHours = Math.floor((timeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
Expand Down