8 "format": ["h:mm", "A"],
17 "font-family": "Noto Sans",
18 "text-align": "center",
19 "margin-top": "calc(50vh - 90pt)",
20 "text-shadow": "rgba(0, 0, 0, 0.8) 0px 7px 10px",
26 * Scale an image up or down until it's larger than or equal to the viewport
29 var adjustBackground = function ($img) {
30 var viewportWidth = screen.width;
31 var viewportHeight = screen.height;
32 var viewportAspect = viewportWidth/viewportHeight;
33 var imgWidth = $img.width();
34 var imgHeight = $img.height();
35 var imgAspect = imgWidth/imgHeight;
37 /* First determine what is
38 the limiting factor (ie. if the image is wider, then the height is
39 is the limiting factor and needs to be adjustested */
40 if (imgAspect < viewportAspect) {
41 /* The view port is wider compared to its height than
42 the image is compared to the image height meaning
43 the width is the limiting dimension. Therefore we
44 set image width = view ports width use the aspect
45 ratio to set the correct height */
46 $img.width(viewportWidth);
47 $img.height(viewportWidth/imgAspect);
49 /* The image is wider than it is tall compared to the
50 viewport so we adjust the to fit */
51 $img.height(viewportHeight);
52 $img.width(viewportHeight*imgAspect);
54 this.centerImage($img);
57 var centerImage = function($img) {
58 var overlapWidth = $img.width() - screen.width;
59 var overlapHeight = $img.height() - screen.height;
61 console.log("overlapwidth: " + overlapWidth + " overlapHeight " + overlapHeight);
62 // image overlaps viewport, move the image back
63 // half the length of the overlap
66 right: overlapWidth/2,
67 bottom: overlapHeight/2
73 this.use_splash = true;
74 $(document).ready(() => {
80 if (this.use_splash) {
81 this.splash = new SplashScreen();
83 $(this).trigger("ready");
87 login(username, password, callback) {
89 if (typeof lightdm == 'undefined') {
90 console.warn("Cannot attempt login without lightdm");
91 // call async so that events can be binded in cascade
92 setTimeout(() => $(this).trigger("access-deny"));
95 username = username || lightdm.select_user;
96 password = password || "";
97 // session_key = session_key || lightdm.sessions[0].key;
100 lightdm.respond(password);
102 let auth_complete_cb = () => {
103 if (typeof callback == "function")
104 callback(lightdm.is_authenticated);
106 $(this).trigger(lightdm.is_authenticated ? "access-grant" : "access-deny");
108 window.show_prompt = auth_cb;
109 window.authentication_complete = auth_complete_cb;
110 lightdm.authenticate(username);
116 this.$el = $("#splash-screen");
117 this.$content = $("#splash-screen-content");
118 this.options = this.getUserOptions();
119 this.is_open = false;
121 if (!this.$el.length)
122 console.error("Missing-screen element.");
124 // fit background image to sreen size and center
125 this.$img = $(".splash-screen-img");
126 if (!this.$img.length)
127 console.warn("No background images supplied for splash screen.");
128 this.$img.each((i, v) => adjustBackground($(v)));
130 let options = this.options; // shorthand
131 if (typeof options == "object") {
132 this.is_open = false;
133 // initilize global values if specfied in the config
134 if (options.filter == true) {
135 this.$img.addClass("filter");
137 if (options.vignette == true) {
138 this.$vignette = $("#vignette");
139 this.$vignette.show();
141 if (typeof options.clock == "object") {
142 this.initClock(options.clock);
147 /******************** Event Listeners ********************/
148 this.clock = setInterval(() => {
149 $(this).trigger("tick");
152 $(document).keyup((e) => {
153 // handle events in seperate method
154 this.keyHandler.call(this, e);
155 }).keypress((e) => this.keyHandler.call(this, e));
157 $(this).click(() => {
164 $.extend(true, options, DEF_OPT);
165 $.extend(true, options, {});
169 * open and close will toggle the screen and animate it opening and closing
170 * adds a resetTimeout function to automatically close after a period of user
177 }, time, "easeInCubic", () => {
179 clearTimeout(this.resetTimeout);
183 clearTimeout(this.resetTimeout);
184 let reset_duration = 60*1000;
188 this.resetTimeout = setTimeout(this.reset, reset_duration);
193 }, time, "easeInCubic", () => {
195 // close the screen after 1 minute of inactivty
196 this.resetTimeout = setTimeout(() => this.reset, reset_duration);
200 if (this.is_open == true) {
202 $(this).trigger("timeout");
207 * handles the key events for the splash
216 if (this.is_open) this.close();
222 // stop reset timeout since there has been user activity
224 clearTimeout(this.resetTimeout);
229 * Creates clock elements based on the usr config
232 if (typeof opts != "object")
234 // handle arrays and a single clock object
235 if (!Array.isArray(opts))
238 for (let i in opts) {
239 this.$clock = $("<div class='clock'></div>");
240 this.$content.append(this.$clock);
241 this.startClock(this.$clock, opts[i]);
246 * Applys the css specfied in the argument opts to the jQuery oboject $clock.
247 * Subscribes the clock to a tick event
249 startClock($clock, opts) {
250 if (typeof opts != "object") {
251 console.error("Clock opts is not a valid object");
254 // handle multiple formats for multiple clocks on the same line
255 if(typeof opts.format == "string")
256 opts.format = [opts.format];
258 // ensure the format is now an array
259 if(!Array.isArray(opts.format)) {
260 console.error(`Specfied clock format is not a valid type.
261 Type can be a single string or Array.`);
265 if(!Array.isArray(opts.css))
266 opts.css = [opts.css];
268 for (let i in opts.format) {
270 let $format = $("<sub></sub>");
271 // create text field in clock
272 $clock.append($format);
275 if (i < opts.css.length && typeof opts.css[i] == "object")
276 $format.css(opts.css[i]);
279 $format.text(moment().format(opts.format[i]));
280 $(this).on("tick", () => {
281 $format.text(moment().format(opts.format[i]));
285 if (typeof opts["parent-css"] == "object")
286 $clock.css(opts["parent-css"]);
287 console.debug($clock);
294 const greeter = new LoginManager();
295 $(greeter).ready(function() {
296 greeter.login("jay", "");
297 $(greeter).on("access-grant", () => {
298 lightdm.start_session_sync("i3");
299 }).on("access-deny", () => console.log("denied!"));