From 2093c4e47aaed97fca92709ede30f020e7c48292 Mon Sep 17 00:00:00 2001 From: TrueKuehli Date: Sat, 29 Sep 2018 19:06:02 +0200 Subject: Added AWESOME styling! --- .../src/modules/ui/notification-banner.js | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 WebInterface/NodeJSServer/src/modules/ui/notification-banner.js (limited to 'WebInterface/NodeJSServer/src/modules/ui/notification-banner.js') diff --git a/WebInterface/NodeJSServer/src/modules/ui/notification-banner.js b/WebInterface/NodeJSServer/src/modules/ui/notification-banner.js new file mode 100644 index 0000000..d14845e --- /dev/null +++ b/WebInterface/NodeJSServer/src/modules/ui/notification-banner.js @@ -0,0 +1,75 @@ +export default class BannerController { + constructor(bannerId, textP, dismissBtn) { + this.banner = document.getElementById(bannerId); + this.bannerText = document.getElementById(textP); + this.dismissBtn = document.getElementById(dismissBtn); + this.bannerMsgs = []; + + // Hide Banner after JS loading finished + this.banner.classList.add('hidden'); + } + + register() { + this.dismissBtn.addEventListener('click', () => { + this.dismissCurrent(); + }); + } + + show(name, text) { + let bannerItem = {name, text, 'html': false}; + this.bannerMsgs.push(bannerItem); + + this.update(); + } + + hide(name) { + if (!name) { + this.bannerMsgs = []; + this.banner.classList.add('hidden'); + } else { + for (let i = 0; i < this.bannerMsgs.length; i++) { + if (this.bannerMsgs[i].name == name) { + this.bannerMsgs.splice(i, 1); + } + } + + this.update(); + } + } + + dismissCurrent() { + this.hide(this.current); + } + + update() { + if (this.bannerMsgs.length === 0) { + this.banner.classList.add('hidden'); + return; + } + + const lastNotification = this.bannerMsgs[this.bannerMsgs.length - 1]; + const name = lastNotification.name; + const text = lastNotification.text; + const html = lastNotification.html; + this.banner.classList.remove('hidden'); + + if (html) this.bannerText.innerHTML = text; + else this.bannerText.innerText = text; + + this.current = name; + } + + showPersistence() { + let text = `Storage persistence is disabled, so in-browser storage of created Wikis might not work.\n` + + `Click here to enable storage persistence.`; + let bannerItem = {'name': 'persistence', text, 'html': true}; + this.bannerMsgs.push(bannerItem); + this.update(); + } +} -- cgit v1.2.3-54-g00ecf