mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 12:12:20 +00:00
Merge pull request #1826 from sdetweil/fixcompliments
Fix compliments to support \n
This commit is contained in:
commit
0e93713464
@ -10,10 +10,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- new script to help setup pm2, without install installers/fixuppm2.sh
|
- new script to help setup pm2, without install installers/fixuppm2.sh
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
|
- updated compliments.js to handle newline in text, as textfields to not interpolate contents
|
||||||
- updated raspberry.sh installer script to handle new platform issues, split node/npm, pm2, and screen saver changes
|
- updated raspberry.sh installer script to handle new platform issues, split node/npm, pm2, and screen saver changes
|
||||||
- improve handling for armv6l devices, where electron support has gone away, add optional serveronly config option
|
- improve handling for armv6l devices, where electron support has gone away, add optional serveronly config option
|
||||||
- change electron version
|
- change electron version
|
||||||
---
|
|
||||||
|
|
||||||
❤️ **Donate:** Enjoying MagicMirror²? [Please consider a donation!](https://magicmirror.builders/donate) With your help we can continue to improve the MagicMirror² core.
|
❤️ **Donate:** Enjoying MagicMirror²? [Please consider a donation!](https://magicmirror.builders/donate) With your help we can continue to improve the MagicMirror² core.
|
||||||
|
|
||||||
|
@ -36,9 +36,10 @@ Module.register("compliments", {
|
|||||||
morningStartTime: 3,
|
morningStartTime: 3,
|
||||||
morningEndTime: 12,
|
morningEndTime: 12,
|
||||||
afternoonStartTime: 12,
|
afternoonStartTime: 12,
|
||||||
afternoonEndTime: 17
|
afternoonEndTime: 17,
|
||||||
|
random: true
|
||||||
},
|
},
|
||||||
|
lastIndexUsed:-1,
|
||||||
// Set currentweather from module
|
// Set currentweather from module
|
||||||
currentWeatherType: "",
|
currentWeatherType: "",
|
||||||
|
|
||||||
@ -147,19 +148,43 @@ Module.register("compliments", {
|
|||||||
* return compliment string - A compliment.
|
* return compliment string - A compliment.
|
||||||
*/
|
*/
|
||||||
randomCompliment: function() {
|
randomCompliment: function() {
|
||||||
|
// get the current time of day compliments list
|
||||||
var compliments = this.complimentArray();
|
var compliments = this.complimentArray();
|
||||||
var index = this.randomIndex(compliments);
|
// variable for index to next message to display
|
||||||
|
let index=0
|
||||||
|
// are we randomizing
|
||||||
|
if(this.config.random){
|
||||||
|
// yes
|
||||||
|
index = this.randomIndex(compliments);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// no, sequetial
|
||||||
|
// if doing sequential, don't fall off the end
|
||||||
|
index = (this.lastIndexUsed >= (compliments.length-1))?0: ++this.lastIndexUsed
|
||||||
|
}
|
||||||
|
|
||||||
return compliments[index];
|
return compliments[index];
|
||||||
},
|
},
|
||||||
|
|
||||||
// Override dom generator.
|
// Override dom generator.
|
||||||
getDom: function() {
|
getDom: function() {
|
||||||
var complimentText = this.randomCompliment();
|
|
||||||
|
|
||||||
var compliment = document.createTextNode(complimentText);
|
|
||||||
var wrapper = document.createElement("div");
|
var wrapper = document.createElement("div");
|
||||||
wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright pre-line";
|
wrapper.className = this.config.classes ? this.config.classes : "thin xlarge bright pre-line";
|
||||||
|
// get the compliment text
|
||||||
|
var complimentText = this.randomCompliment();
|
||||||
|
// split it into parts on newline text
|
||||||
|
var parts= complimentText.split('\n')
|
||||||
|
// create a span to hold it all
|
||||||
|
var compliment=document.createElement('span')
|
||||||
|
// process all the parts of the compliment text
|
||||||
|
for (part of parts){
|
||||||
|
// create a text element for each part
|
||||||
|
compliment.appendChild(document.createTextNode(part))
|
||||||
|
// add a break `
|
||||||
|
compliment.appendChild(document.createElement('BR'))
|
||||||
|
}
|
||||||
|
// remove the last break
|
||||||
|
compliment.lastElementChild.remove();
|
||||||
wrapper.appendChild(compliment);
|
wrapper.appendChild(compliment);
|
||||||
|
|
||||||
return wrapper;
|
return wrapper;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user