9 "format": "dddd, MMMM Do",
14 "margin-top": "calc(20vh - 70pt)",
15 "text-align": "center",
17 "font-family": "Noto Sans",
18 "font-weight": "lighter",
19 "text-shadow": "rgba(0, 0, 0, 0.8) 0px 7px 10px",
22 "format": ["h:mm", "A"],
24 {"font-size": "65pt", "font-weight": 200 },
25 {"font-size": "30pt", "font-weight": "lighter", "margin-left": "10pt"}
30 "font-family": "Noto Sans",
31 "text-align": "center",
32 "text-shadow": "rgba(0, 0, 0, 0.8) 0px 7px 10px",
37 "html":"<text style='display: none' class='active-appear'>Press any key to login</text>",
43 "text-align": "center",
44 "color": "rgba(255, 255, 255, 0.8)"
52 this.options = this.getUserOptions();
53 $(this).on("init", () => this._init());
56 this.$el = $("#splash-screen");
57 this.$content = $("#splash-screen-content");
58 this.state = "closed";
60 this.active_timeout = 15;
63 log.error("Missing-screen element.");
65 // fit background image to sreen size and center
66 this.$img = $(".splash-screen-img");
67 if (!this.$img.length)
68 log.warn("No background images supplied for splash screen.");
69 this.$img.each((i, v) => adjustBackground($(v)));
71 let options = this.options; // shorthand
72 if (typeof options == "object") {
73 // initilize global values if specfied in the config
77 if (typeof options["active-timeout"] == "number")
78 this.active_timeout = options["active-timeout"];
79 if (options.filter == true)
80 this.$img.addClass("filter");
81 if (options.vignette == true)
82 this.$vignette = $("#vignette");
83 this.$vignette.show();
84 if (typeof options.content == "object")
85 this.initContent(options.content);
86 console.log("triggering ready for splash");
87 $(this).trigger("ready");
90 /******************** Event Listeners ********************/
91 this.clock = setInterval(() => {
92 $(this).trigger("tick");
95 $(this).trigger("inactive");
98 // update last active time
99 $(this).on("active", () => this.last_active = moment());
101 $(document).keyup((e) => {
102 // handle events in seperate method
103 this.keyHandler.call(this, e);
104 }).keypress((e) => this.keyHandler.call(this, e));
106 this.$el.click(() => {
108 }).mousemove((e) => {
109 if (!this.isActive())
110 $(this).trigger("active", e)
112 setTimeout(() => $(this).trigger("active"), 1);
115 * Loops through the user specified content and adds them to the DOM in order
117 initContent(content) {
118 for (let content_type in content) {
119 if (content_type == "clock")
120 this.initClock(content[content_type]);
121 else if (content_type == "html")
122 this.initHTML(content[content_type]);
124 log.warn("Specified content " + content_type + " is not valid.");
130 $.extend(true, options, DEF_OPT);
131 $.extend(true, options, {});
136 * open and close will toggle the screen and animate it opening and closing
137 * adds a resetTimeout function to automatically close after a period of user
140 if (this.state == "closed" || this.state == "moving") {
141 log.warn("Cannot close splash screen when state is: " + this.state);
145 this.state = "moving";
149 }, time, "easeOutQuint", () => {
150 this.state = "closed";
151 clearTimeout(this.resetTimeout);
155 if (this.state == "open" || this.state == "moving") {
156 log.warn("Cannot open splash screen when state is: " + this.state);
159 clearTimeout(this.resetTimeout);
160 let reset_duration = 60*1000;
162 if (this.state == "open" || this.state == "moving") {
163 this.resetTimeout = setTimeout(this.reset, reset_duration);
166 this.state = "moving";
169 }, time, "easeInCirc", () => {
171 // close the screen after 1 minute of inactivty
172 this.resetTimeout = setTimeout(() => this.reset, reset_duration);
176 if (this.state == "open") {
178 $(this).trigger("timeout");
183 * handles the key events for the splash
188 case 13: // Enter key
189 if (this.state == "closed") this.open();
192 if (this.state == "open") this.close();
193 else if (this.state == "closed") this.open();
196 if (e.keyCode != 82 && e.keyCode != 17 && this.state == "closed") // for testing
201 // stop reset timeout since there has been user activity
202 if (this.state == "open")
203 clearTimeout(this.resetTimeout);
205 if (!this.isActive())
206 $(this).trigger("active", e);
210 if (moment().diff(this.last_active, "seconds", true) > 30) {
217 * Creates clock elements based on the usr config
220 if (typeof opts != "object") {
221 log.error("Unable to initialize clock thats not an object");
224 // handle arrays and a single clock object
225 if (!Array.isArray(opts))
228 for (let i in opts) {
229 this.$clock = $("<div id='clock-" + i + "' class='clock'></div>");
230 this.$content.append(this.$clock);
231 this.startClock(this.$clock, opts[i]);
236 * Applys the css specfied in the argument opts to the jQuery oboject $clock.
237 * Subscribes the clock to a tick event
239 startClock($clock, opts) {
240 if (typeof opts != "object") {
241 log.error("Clock opts is not a valid object");
244 // handle multiple formats for multiple clocks on the same line
245 if(typeof opts.format == "string")
246 opts.format = [opts.format];
248 // ensure the format is now an array
249 if(!Array.isArray(opts.format)) {
250 log.error(`Specfied clock format is not a valid type.
251 Type can be a single string or Array.`);
255 if(!Array.isArray(opts.css))
256 opts.css = [opts.css];
258 for (let i in opts.format) {
260 let $format = $("<sub></sub>");
261 // create text field in clock
262 $clock.append($format);
264 if (i < opts.css.length && typeof opts.css[i] == "object")
265 $format.css(opts.css[i]);
268 $format.text(moment().format(opts.format[i]));
269 $(this).on("tick", () => {
270 $format.text(moment().format(opts.format[i]));
274 if (typeof opts["parent-css"] == "object")
275 $clock.css(opts["parent-css"]);
281 * Inserts HTML specified in the user config into the splash screen
282 * accepts plain strings and objects. String literals are interpreted as
283 * normal text element. Objects are set using the jQuery API
286 // handle single objects and strings
287 if (!Array.isArray(opts)) {
291 for (let el of opts) {
292 if (typeof el == "string") {
293 let $el = $("<text>");
295 // create simple text element
296 this.$content.append($el);
297 } else if (typeof el == "object") {
298 // let user specify element properites in object el.
299 let $el = $("<div>");
300 for (let prop in el) {
303 this.$content.append($el);
306 log.warn("Splash screen html element is invalid type");