mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 20:22:53 +00:00
Enabled newsfeed default module for gesture events from https://github.com/thobach/MMM-Gestures
This commit is contained in:
parent
8010e6220d
commit
adb8de9754
@ -89,7 +89,8 @@ Module.register("newsfeed",{
|
||||
|
||||
if (this.newsItems.length > 0) {
|
||||
|
||||
if (this.config.showSourceTitle || this.config.showPublishDate) {
|
||||
// this.config.showFullArticle is a run-time configuration, triggered by optional gestures
|
||||
if (!this.config.showFullArticle && (this.config.showSourceTitle || this.config.showPublishDate)) {
|
||||
var sourceAndTimestamp = document.createElement("div");
|
||||
sourceAndTimestamp.className = "light small dimmed";
|
||||
|
||||
@ -151,18 +152,32 @@ Module.register("newsfeed",{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var title = document.createElement("div");
|
||||
title.className = "bright medium light";
|
||||
title.innerHTML = this.newsItems[this.activeItem].title;
|
||||
wrapper.appendChild(title);
|
||||
|
||||
|
||||
if(!this.config.showFullArticle){
|
||||
var title = document.createElement("div");
|
||||
title.className = "bright medium light";
|
||||
title.innerHTML = this.newsItems[this.activeItem].title;
|
||||
wrapper.appendChild(title);
|
||||
}
|
||||
|
||||
if (this.config.showDescription) {
|
||||
var description = document.createElement("div");
|
||||
description.className = "small light";
|
||||
description.innerHTML = this.newsItems[this.activeItem].description;
|
||||
wrapper.appendChild(description);
|
||||
}
|
||||
|
||||
if (this.config.showFullArticle) {
|
||||
var fullArticle = document.createElement("iframe");
|
||||
fullArticle.className = "";
|
||||
fullArticle.style.width = "100%";
|
||||
fullArticle.style.height = "1735px";
|
||||
fullArticle.style.border = "none";
|
||||
fullArticle.src = this.newsItems[this.activeItem].url;
|
||||
wrapper.appendChild(fullArticle);
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
wrapper.innerHTML = this.translate("LOADING");
|
||||
@ -256,7 +271,7 @@ Module.register("newsfeed",{
|
||||
|
||||
self.updateDom(self.config.animationSpeed);
|
||||
|
||||
setInterval(function() {
|
||||
timer = setInterval(function() {
|
||||
self.activeItem++;
|
||||
self.updateDom(self.config.animationSpeed);
|
||||
}, this.config.updateInterval);
|
||||
@ -272,6 +287,76 @@ Module.register("newsfeed",{
|
||||
capitalizeFirstLetter: function(string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
},
|
||||
|
||||
notificationReceived: function(notification, payload, sender) {
|
||||
Log.info(this.name + " - received event");
|
||||
if(notification == 'GESTURE'){
|
||||
Log.info(this.name + " - received gesture");
|
||||
var gesture = payload.gesture;
|
||||
// actually RIGHT, because gesture sensor is built in upside down
|
||||
if(gesture == 'LEFT'){
|
||||
Log.info(this.name + " - received right");
|
||||
var before = this.activeItem;
|
||||
this.activeItem++;
|
||||
if (this.activeItem >= this.newsItems.length) {
|
||||
this.activeItem = 0;
|
||||
}
|
||||
this.config.showDescription = false;
|
||||
this.config.showFullArticle = false;
|
||||
if(!timer){
|
||||
this.scheduleUpdateInterval();
|
||||
}
|
||||
Log.info(this.name + " - going from " + before + " to " + this.activeItem + " (of " + this.newsItems.length + ")");
|
||||
this.updateDom(100);
|
||||
}
|
||||
// actually LEFT, because gesture sensor is built in upside down
|
||||
else if(gesture == 'RIGHT'){
|
||||
Log.info(this.name + " - received left");
|
||||
var before = this.activeItem;
|
||||
this.activeItem--;
|
||||
if (this.activeItem < 0) {
|
||||
this.activeItem = this.newsItems.length - 1;
|
||||
}
|
||||
this.config.showDescription = false;
|
||||
this.config.showFullArticle = false;
|
||||
if(!timer){
|
||||
this.scheduleUpdateInterval();
|
||||
}
|
||||
Log.info(this.name + " - going from " + before + " to " + this.activeItem + " (of " + this.newsItems.length + ")");
|
||||
this.updateDom(100);
|
||||
}
|
||||
// actually UP, because gesture sensor is built in upside down
|
||||
else if(gesture == 'DOWN' && !this.config.showDescription){
|
||||
Log.info(this.name + " - received up");
|
||||
this.config.showDescription = true;
|
||||
this.config.showFullArticle = false;
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
this.updateDom(100);
|
||||
}
|
||||
// actually DOWN, because gesture sensor is built in upside down
|
||||
else if(gesture == 'UP'){
|
||||
Log.info(this.name + " - received down");
|
||||
this.config.showDescription = false;
|
||||
this.config.showFullArticle = false;
|
||||
if(!timer){
|
||||
this.scheduleUpdateInterval();
|
||||
}
|
||||
this.updateDom(100);
|
||||
}
|
||||
// actually UP, because gesture sensor is built in upside down
|
||||
else if(gesture == 'DOWN' && this.config.showDescription){
|
||||
Log.info(this.name + " - received up again");
|
||||
this.config.showFullArticle = true;
|
||||
this.config.showDescription = false;
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
this.updateDom(100);
|
||||
} else {
|
||||
Log.info(this.name + " - received other: " + gesture);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user