From 950fa84d1ce44fc50270aeba19f3864964542b32 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 30 Nov 2016 10:30:49 -0500 Subject: [PATCH] Added capability to load compliments from the host file system. --- modules/default/compliments/compliments.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/modules/default/compliments/compliments.js b/modules/default/compliments/compliments.js index f05cd9c1..3bfdc8be 100644 --- a/modules/default/compliments/compliments.js +++ b/modules/default/compliments/compliments.js @@ -29,6 +29,7 @@ Module.register("compliments",{ ] }, updateInterval: 30000, + remoteFile: null, fadeSpeed: 4000 }, @@ -46,6 +47,12 @@ Module.register("compliments",{ this.lastComplimentIndex = -1; + if (this.config.remoteFile != null) { + this.complimentFile((response) => { + this.config.compliments = JSON.parse(response); + }); + } + // Schedule update timer. var self = this; setInterval(function() { @@ -104,6 +111,21 @@ Module.register("compliments",{ }, + /* complimentFile(callback) + * Retrieve a file from the local filesystem + */ + complimentFile: function(callback) { + var xobj = new XMLHttpRequest(); + xobj.overrideMimeType("application/json"); + xobj.open('GET', this.file(this.config.remoteFile), true); + xobj.onreadystatechange = function () { + if (xobj.readyState == 4 && xobj.status == "200") { + callback(xobj.responseText); + } + }; + xobj.send(null); + }, + /* complimentArray() * Retrieve a random compliment. *