mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 03:39:55 +00:00
move compliments out into its own file
This commit is contained in:
parent
ed5fbed7d9
commit
4bca536404
@ -27,6 +27,7 @@
|
||||
<script src="js/moment-with-langs.min.js"></script>
|
||||
<script src="js/config.js"></script>
|
||||
<script src="js/rrule.js"></script>
|
||||
<script src="js/compliments/compliments.js" type="text/javascript"></script>
|
||||
<script src="js/main.js?nocache=<?php echo md5(microtime()) ?>"></script>
|
||||
<!-- <script src="js/socket.io.min.js"></script> -->
|
||||
|
||||
|
63
js/compliments/compliments.js
Normal file
63
js/compliments/compliments.js
Normal file
@ -0,0 +1,63 @@
|
||||
var compliments = {
|
||||
complimentLocation: '.compliment',
|
||||
currentCompliment: '',
|
||||
complimentList: {
|
||||
'morning': morning,
|
||||
'afternoon': afternoon,
|
||||
'evening': evening
|
||||
},
|
||||
updateInterval: 30000,
|
||||
fadeInterval: 4000,
|
||||
intervalId: null
|
||||
};
|
||||
|
||||
compliments.updateCompliment = function () {
|
||||
|
||||
var _list = [];
|
||||
|
||||
var hour = moment().hour();
|
||||
|
||||
if (hour >= 3 && hour < 12) {
|
||||
// Morning compliments
|
||||
_list = compliments.complimentList['morning'];
|
||||
} else if (hour >= 12 && hour < 17) {
|
||||
// Afternoon compliments
|
||||
_list = compliments.complimentList['afternoon'];
|
||||
} else if (hour >= 17 || hour < 3) {
|
||||
// Evening compliments
|
||||
_list = compliments.complimentList['evening'];
|
||||
} 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]);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
// Search for the location of the current compliment in the list
|
||||
var _spliceIndex = _list.indexOf(compliments.currentCompliment);
|
||||
|
||||
// If it exists, remove it so we don't see it again
|
||||
if (_spliceIndex !== -1) {
|
||||
_list = _list.slice(_spliceIndex, 1);
|
||||
}
|
||||
|
||||
// Randomly select a location
|
||||
var _location = Math.floor(Math.random() * _list.length);
|
||||
compliments.currentCompliment = _list[_location];
|
||||
|
||||
$('.compliment').updateWithText(compliments.currentCompliment, compliments.fadeInterval);
|
||||
|
||||
}
|
||||
|
||||
compliments.init = function () {
|
||||
|
||||
this.updateCompliment();
|
||||
|
||||
this.intervalId = setInterval(function () {
|
||||
this.updateCompliment();
|
||||
}.bind(this), this.updateInterval)
|
||||
|
||||
}
|
27
js/main.js
27
js/main.js
@ -200,32 +200,7 @@ jQuery(document).ready(function($) {
|
||||
}, 1000);
|
||||
})();
|
||||
|
||||
(function updateCompliment()
|
||||
{
|
||||
//see compliments.js
|
||||
while (compliment == lastCompliment) {
|
||||
|
||||
//Check for current time
|
||||
var compliments;
|
||||
var date = new Date();
|
||||
var hour = date.getHours();
|
||||
//set compliments to use
|
||||
if (hour >= 3 && hour < 12) compliments = morning;
|
||||
if (hour >= 12 && hour < 17) compliments = afternoon;
|
||||
if (hour >= 17 || hour < 3) compliments = evening;
|
||||
|
||||
compliment = Math.floor(Math.random()*compliments.length);
|
||||
}
|
||||
|
||||
$('.compliment').updateWithText(compliments[compliment], 4000);
|
||||
|
||||
lastCompliment = compliment;
|
||||
|
||||
setTimeout(function() {
|
||||
updateCompliment(true);
|
||||
}, 30000);
|
||||
|
||||
})();
|
||||
compliments.init();
|
||||
|
||||
(function updateCurrentWeather()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user