10 "format": "dddd, MMMM Do",
15 "margin-top": "calc(20vh - 70pt)",
16 "text-align": "center",
18 "font-family": "Noto Sans",
19 "font-weight": "lighter",
20 "text-shadow": "rgba(0, 0, 0, 0.8) 0px 7px 10px",
23 "format": ["h:mm", "A"],
25 {"font-size": "65pt", "font-weight": 200 },
26 {"font-size": "30pt", "font-weight": "lighter", "margin-left": "10pt"}
31 "font-family": "Noto Sans",
32 "text-align": "center",
33 "text-shadow": "rgba(0, 0, 0, 0.8) 0px 7px 10px",
38 "html":"<text style='display: none' class='active-appear'>Press any key to login</text>",
44 "text-align": "center",
45 "color": "rgba(255, 255, 255, 0.8)"
53 this.options = this.getUserOptions();
54 $(this).on("init", () => this._init());
57 this.$el = $("#splash-screen");
58 this.$content = $("#splash-screen-content");
59 this.state = "closed";
61 this.active_timeout = 15;
64 log.error("Missing-screen element.");
66 // fit background image to sreen size and center
67 this.$img = $(".splash-screen-img");
68 if (!this.$img.length)
69 log.warn("No background images supplied for splash screen.");
70 this.$img.each((i, v) => adjustBackground($(v)));
72 let options = this.options; // shorthand
73 if (typeof options == "object") {
74 // initilize global values if specfied in the config
78 if (typeof options["active-timeout"] == "number")
79 this.active_timeout = options["active-timeout"];
80 if (options.filter == true)
81 this.$img.addClass("filter");
82 if (options.vignette == true) {
83 this.$vignette = $("#vignette");
84 this.$vignette.show();
86 if (typeof options.content == "object")
87 this.initContent(options.content);
88 console.log("triggering ready for splash");
89 $(this).trigger("ready");
92 /******************** Event Listeners ********************/
93 this.clock = setInterval(() => {
94 $(this).trigger("tick");
97 $(this).trigger("inactive");
100 // update last active time
101 $(this).on("active", () => this.last_active = moment());
103 $(document).keyup((e) => {
104 // handle events in seperate method
105 this.keyHandler.call(this, e);
106 }).keypress((e) => this.keyHandler.call(this, e));
108 this.$el.click(() => {
110 }).mousemove((e) => {
111 if (!this.isActive())
112 $(this).trigger("active", e)
114 setTimeout(() => $(this).trigger("active"), 1);
117 * Loops through the user specified content and adds them to the DOM in order
119 initContent(content) {
120 for (let content_type in content) {
121 if (content_type == "clock")
122 this.initClock(content[content_type]);
123 else if (content_type == "html")
124 this.initHTML(content[content_type]);
126 log.warn("Specified content " + content_type + " is not valid.");
132 $.extend(true, options, DEF_OPT);
133 $.extend(true, options, {});
138 * open and close will toggle the screen and animate it opening and closing
139 * adds a resetTimeout function to automatically close after a period of user
142 if (this.state == "closed" || this.state == "moving") {
143 log.warn("Cannot close splash screen when state is: " + this.state);
147 this.state = "moving";
149 // this.$el.css("top", "0");
150 // this.$el.css("opacity", "1");
152 this.$el.fadeIn(MOVE_DUR, () => {
153 // this.$el.remove("filter");
158 }, time, "easeOutQuint", () => {
159 >>>>>>> c1d727d6c4753e967cdd3e9df93db3bf993eb389
160 this.state = "closed";
161 this.$content.fadeIn("slow")
167 if (this.state == "open" || this.state == "moving") {
168 log.warn("Cannot open splash screen when state is: " + this.state);
171 clearTimeout(this.resetTimeout);
172 let reset_duration = 60*1000;
174 if (this.state == "open" || this.state == "moving") {
175 this.resetTimeout = setTimeout(this.reset, reset_duration);
178 this.state = "moving";
181 this.$content.fadeOut("fast", () => {
182 // this.$el.remove("filter");
183 this.$el.fadeOut(MOVE_DUR, () => {
189 // this.$el.css("top", "-100%");
190 // this.$el.css("opacity", "0");
193 // setTimeout(() => {
194 // this.state = "open";
202 $el.addClass("move-up");
204 $el.css("top", "-100%").removeClass("move-up");
205 if (typeof cb == "function") cb($el);
210 }, time, "easeInCirc", () => {
212 // close the screen after 1 minute of inactivty
213 this.resetTimeout = setTimeout(() => this.reset, reset_duration);
215 >>>>>>> c1d727d6c4753e967cdd3e9df93db3bf993eb389
218 $el.addClass("move-down");
220 $el.css("top", "0").removeClass("move-down");
221 if (typeof cb == "function") cb($el);
225 * Closes the splash screen if there has been no user activity
228 if (this.state == "open") {
230 $(this).trigger("timeout");
235 * handles the key events for the splash
240 case 13: // Enter key
241 if (this.state == "closed") this.open();
244 if (this.state == "open") this.close();
245 else if (this.state == "closed") this.open();
248 if (e.keyCode != 82 && e.keyCode != 17 && this.state == "closed") // for testing
253 // stop reset timeout since there has been user activity
254 if (this.state == "open")
255 clearTimeout(this.resetTimeout);
257 if (!this.isActive())
258 $(this).trigger("active", e);
262 if (moment().diff(this.last_active, "seconds", true) > 30) {
269 * Creates clock elements based on the usr config
272 if (typeof opts != "object") {
273 log.error("Unable to initialize clock thats not an object");
276 // handle arrays and a single clock object
277 if (!Array.isArray(opts))
280 for (let i in opts) {
281 this.$clock = $("<div id='clock-" + i + "' class='clock'></div>");
282 this.$content.append(this.$clock);
283 this.startClock(this.$clock, opts[i]);
288 * Applys the css specfied in the argument opts to the jQuery oboject $clock.
289 * Subscribes the clock to a tick event
291 startClock($clock, opts) {
292 if (typeof opts != "object") {
293 log.error("Clock opts is not a valid object");
296 // handle multiple formats for multiple clocks on the same line
297 if(typeof opts.format == "string")
298 opts.format = [opts.format];
300 // ensure the format is now an array
301 if(!Array.isArray(opts.format)) {
302 log.error(`Specfied clock format is not a valid type.
303 Type can be a single string or Array.`);
307 if(!Array.isArray(opts.css))
308 opts.css = [opts.css];
310 for (let i in opts.format) {
312 let $format = $("<sub></sub>");
313 // create text field in clock
314 $clock.append($format);
316 if (i < opts.css.length && typeof opts.css[i] == "object")
317 $format.css(opts.css[i]);
320 $format.text(moment().format(opts.format[i]));
321 $(this).on("tick", () => {
322 $format.text(moment().format(opts.format[i]));
326 if (typeof opts["parent-css"] == "object")
327 $clock.css(opts["parent-css"]);
333 * Inserts HTML specified in the user config into the splash screen
334 * accepts plain strings and objects. String literals are interpreted as
335 * normal text element. Objects are set using the jQuery API
338 // handle single objects and strings
339 if (!Array.isArray(opts)) {
343 for (let el of opts) {
344 if (typeof el == "string") {
345 let $el = $("<text>");
347 // create simple text element
348 this.$content.append($el);
349 } else if (typeof el == "object") {
350 // let user specify element properites in object el.
351 let $el = $("<div>");
352 for (let prop in el) {
355 this.$content.append($el);
358 log.warn("Splash screen html element is invalid type");