changeset 1:1c31f4102408

Show a hint if the feed has no entries
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Thu, 04 Oct 2018 09:40:26 +0200
parents bc5cc170163c
children 7b24037ef7b5
files _locales/de/messages.json _locales/en/messages.json content_scripts/feed-preview.js web_resources/feed-preview.xhtml web_resources/style/feed-preview.css
diffstat 5 files changed, 27 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/_locales/de/messages.json	Wed Oct 03 23:40:57 2018 +0200
+++ b/_locales/de/messages.json	Thu Oct 04 09:40:26 2018 +0200
@@ -11,6 +11,10 @@
         "message": "Feed ohne Titel",
         "description": "Default title for feeds."
     },
+    "noEntriesHint": {
+        "message": "Dieser Feed hat keine Einträge.",
+        "description": "Hint to display if there are no entries."
+    },
     "defaultFeedEntryTitle": {
         "message": "Eintrag ohne Titel",
         "description": "Default title for feed entries."
--- a/_locales/en/messages.json	Wed Oct 03 23:40:57 2018 +0200
+++ b/_locales/en/messages.json	Thu Oct 04 09:40:26 2018 +0200
@@ -11,6 +11,10 @@
         "message": "Untitled Feed",
         "description": "Default title for feeds."
     },
+    "noEntriesHint": {
+        "message": "This feed has no entries.",
+        "description": "Hint to display if there are no entries."
+    },
     "defaultFeedEntryTitle": {
         "message": "Untitled Entry",
         "description": "Default title for feed entries."
--- a/content_scripts/feed-preview.js	Wed Oct 03 23:40:57 2018 +0200
+++ b/content_scripts/feed-preview.js	Thu Oct 04 09:40:26 2018 +0200
@@ -329,6 +329,17 @@
                 previewDocument.querySelector('#entry-files-list-template');
         let entryFileTemplateElement =
                 previewDocument.querySelector('#entry-file-template');
+        if (this.entries.length === 0) {
+            let hintTemplateElement =
+                    previewDocument.querySelector('#no-entries-hint-template');
+            let hintNode =
+                    previewDocument.importNode(hintTemplateElement.content,
+                    true);
+            hintNode.querySelector("#no-entries-hint").textContent =
+                browser.i18n.getMessage('noEntriesHint');
+
+            previewDocument.body.append(hintNode);
+        }
         for (let entry of this.entries) {
             let entryNode =
                     previewDocument.importNode(entryTemplateElement.content,
--- a/web_resources/feed-preview.xhtml	Wed Oct 03 23:40:57 2018 +0200
+++ b/web_resources/feed-preview.xhtml	Thu Oct 04 09:40:26 2018 +0200
@@ -43,6 +43,9 @@
       </ul>
     </footer>
   </template>
+  <template id="no-entries-hint-template">
+    <p id="no-entries-hint"></p>
+  </template>
   <template id="entry-file-template">
     <li class="entry-file"><a class="entry-file-link" href="" title=""></a>
     <span class="entry-file-info"></span></li>
--- a/web_resources/style/feed-preview.css	Wed Oct 03 23:40:57 2018 +0200
+++ b/web_resources/style/feed-preview.css	Thu Oct 04 09:40:26 2018 +0200
@@ -28,6 +28,11 @@
   margin: 0 0 16px 0;
 }
 
+#no-entries-hint {
+  color: var(--grey-50);
+}
+
+#no-entries-hint,
 .entry {
   clear: both;
   margin: 16px auto;