mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
Fix for Compliment picker.
Fixes bug where compliments were no longer updated.
This commit is contained in:
parent
a00da4e40c
commit
cf95a2e431
@ -16,26 +16,30 @@ var compliments = {
|
|||||||
*/
|
*/
|
||||||
compliments.updateCompliment = function () {
|
compliments.updateCompliment = function () {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var _list = [];
|
var _list = [];
|
||||||
|
|
||||||
var hour = moment().hour();
|
var hour = moment().hour();
|
||||||
|
|
||||||
|
// In the followign if statement we use .slice() on the
|
||||||
|
// compliments array to make a copy by value.
|
||||||
|
// This way the original array of compliments stays in tact.
|
||||||
|
|
||||||
if (hour >= 3 && hour < 12) {
|
if (hour >= 3 && hour < 12) {
|
||||||
// Morning compliments
|
// Morning compliments
|
||||||
_list = compliments.complimentList['morning'];
|
_list = compliments.complimentList['morning'].slice();
|
||||||
} else if (hour >= 12 && hour < 17) {
|
} else if (hour >= 12 && hour < 17) {
|
||||||
// Afternoon compliments
|
// Afternoon compliments
|
||||||
_list = compliments.complimentList['afternoon'];
|
_list = compliments.complimentList['afternoon'].slice();
|
||||||
} else if (hour >= 17 || hour < 3) {
|
} else if (hour >= 17 || hour < 3) {
|
||||||
// Evening compliments
|
// Evening compliments
|
||||||
_list = compliments.complimentList['evening'];
|
_list = compliments.complimentList['evening'].slice();
|
||||||
} else {
|
} else {
|
||||||
// Edge case in case something weird happens
|
// Edge case in case something weird happens
|
||||||
// This will select a compliment from all times of day
|
// This will select a compliment from all times of day
|
||||||
Object.keys(compliments.complimentList).forEach(function (_curr) {
|
Object.keys(compliments.complimentList).forEach(function (_curr) {
|
||||||
|
_list = _list.concat(compliments.complimentList[_curr]).slice();
|
||||||
_list = _list.concat(compliments.complimentList[_curr]);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,12 +48,12 @@ compliments.updateCompliment = function () {
|
|||||||
|
|
||||||
// If it exists, remove it so we don't see it again
|
// If it exists, remove it so we don't see it again
|
||||||
if (_spliceIndex !== -1) {
|
if (_spliceIndex !== -1) {
|
||||||
_list = _list.slice(_spliceIndex, 1);
|
_list.splice(_spliceIndex, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Randomly select a location
|
// Randomly select a location
|
||||||
var _location = Math.floor(Math.random() * _list.length);
|
var _randomIndex = Math.floor(Math.random() * _list.length);
|
||||||
compliments.currentCompliment = _list[_location];
|
compliments.currentCompliment = _list[_randomIndex];
|
||||||
|
|
||||||
$('.compliment').updateWithText(compliments.currentCompliment, compliments.fadeInterval);
|
$('.compliment').updateWithText(compliments.currentCompliment, compliments.fadeInterval);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user