From cf95a2e431cbfcf60eb50ea3b2da91a305081093 Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Tue, 3 Nov 2015 14:22:31 +0100 Subject: [PATCH 1/2] Fix for Compliment picker. Fixes bug where compliments were no longer updated. --- js/compliments/compliments.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/js/compliments/compliments.js b/js/compliments/compliments.js index d1c8831b..04953fba 100644 --- a/js/compliments/compliments.js +++ b/js/compliments/compliments.js @@ -16,26 +16,30 @@ var compliments = { */ compliments.updateCompliment = function () { + + var _list = []; 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) { // Morning compliments - _list = compliments.complimentList['morning']; + _list = compliments.complimentList['morning'].slice(); } else if (hour >= 12 && hour < 17) { // Afternoon compliments - _list = compliments.complimentList['afternoon']; + _list = compliments.complimentList['afternoon'].slice(); } else if (hour >= 17 || hour < 3) { // Evening compliments - _list = compliments.complimentList['evening']; + _list = compliments.complimentList['evening'].slice(); } else { // Edge case in case something weird happens // This will select a compliment from all times of day Object.keys(compliments.complimentList).forEach(function (_curr) { - - _list = _list.concat(compliments.complimentList[_curr]); - + _list = _list.concat(compliments.complimentList[_curr]).slice(); }); } @@ -44,12 +48,12 @@ compliments.updateCompliment = function () { // If it exists, remove it so we don't see it again if (_spliceIndex !== -1) { - _list = _list.slice(_spliceIndex, 1); + _list.splice(_spliceIndex, 1); } // Randomly select a location - var _location = Math.floor(Math.random() * _list.length); - compliments.currentCompliment = _list[_location]; + var _randomIndex = Math.floor(Math.random() * _list.length); + compliments.currentCompliment = _list[_randomIndex]; $('.compliment').updateWithText(compliments.currentCompliment, compliments.fadeInterval); From e0de5667f95a9b9c72c8ce5609a2ebffcbdfe662 Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Tue, 3 Nov 2015 14:22:46 +0100 Subject: [PATCH 2/2] Increase update time for compliments. --- js/config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/config.js b/js/config.js index a1cafff8..ec362724 100755 --- a/js/config.js +++ b/js/config.js @@ -15,7 +15,7 @@ var config = { } }, compliments: { - interval: 2000, + interval: 30000, fadeInterval: 4000, morning: [ 'Good morning, handsome!',