From d12509957f754ad9977afc8027a2e0676c9fa5c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Cederstr=C3=B6m?= Date: Sat, 7 Jul 2018 16:35:07 +0200 Subject: [PATCH] Abillity to toggle article in fullscreen --- modules/default/newsfeed/README.md | 1 + modules/default/newsfeed/newsfeed.js | 34 ++++++++++++++++++---------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/modules/default/newsfeed/README.md b/modules/default/newsfeed/README.md index 6c559578..f4888ebb 100644 --- a/modules/default/newsfeed/README.md +++ b/modules/default/newsfeed/README.md @@ -41,6 +41,7 @@ MagicMirror's [notification mechanism](https://github.com/MichMich/MagicMirror/t | `ARTICLE_PREVIOUS` | Shows the previous news title (hiding the summary or previously fully displayed article) | `ARTICLE_MORE_DETAILS` | When received the _first time_, shows the corresponding description of the currently displayed news title.
The module expects that the module's configuration option `showDescription` is set to `false` (default value).

When received a _second consecutive time_, shows the full news article in an IFRAME.
This requires that the news page can be embedded in an IFRAME, e.g. doesn't have the HTTP response header [X-Frame-Options](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options) set to e.g. `DENY`.

When received the _next consecutive times_, reloads the page and scrolls down by `scrollLength` pixels to paginate through the article. | `ARTICLE_LESS_DETAILS` | Hides the summary or full news article and only displays the news title of the currently viewed news item. +| `ARTICLE_TOGGLE_FULL` | Toogles article in fullscreen. Note the payload of the sent notification event is ignored. diff --git a/modules/default/newsfeed/newsfeed.js b/modules/default/newsfeed/newsfeed.js index 60562248..1d141b95 100644 --- a/modules/default/newsfeed/newsfeed.js +++ b/modules/default/newsfeed/newsfeed.js @@ -366,19 +366,8 @@ Module.register("newsfeed",{ Log.info(this.name + " - scrolling down"); Log.info(this.name + " - ARTICLE_MORE_DETAILS, scroll position: " + this.config.scrollLength); } - // display full article else { - this.isShowingDescription = !this.isShowingDescription; - this.config.showFullArticle = !this.isShowingDescription; - // make bottom bar align to top to allow scrolling - if(this.config.showFullArticle == true){ - document.getElementsByClassName("region bottom bar")[0].style.bottom = "inherit"; - document.getElementsByClassName("region bottom bar")[0].style.top = "-90px"; - } - clearInterval(timer); - timer = null; - Log.info(this.name + " - showing " + this.isShowingDescription ? "article description" : "full article"); - this.updateDom(100); + this.showFullArticle(); } } else if(notification == "ARTICLE_SCROLL_UP"){ if(this.config.showFullArticle == true){ @@ -391,9 +380,30 @@ Module.register("newsfeed",{ this.resetDescrOrFullArticleAndTimer(); Log.info(this.name + " - showing only article titles again"); this.updateDom(100); + } else if (notification == "ARTICLE_TOGGLE_FULL"){ + if (this.config.showFullArticle){ + this.activeItem++; + this.resetDescrOrFullArticleAndTimer(); + } else { + this.showFullArticle(); + } } else { Log.info(this.name + " - unknown notification, ignoring: " + notification); } }, + showFullArticle: function() { + this.isShowingDescription = !this.isShowingDescription; + this.config.showFullArticle = !this.isShowingDescription; + // make bottom bar align to top to allow scrolling + if(this.config.showFullArticle == true){ + document.getElementsByClassName("region bottom bar")[0].style.bottom = "inherit"; + document.getElementsByClassName("region bottom bar")[0].style.top = "-90px"; + } + clearInterval(timer); + timer = null; + Log.info(this.name + " - showing " + this.isShowingDescription ? "article description" : "full article"); + this.updateDom(100); + } + });