OSDN Git Service

ea3bf8f7b0fb6e22f813fc4f25b28f4feace93b6
[alterlinux/lightdm-webkit2-theme-alter.git] / js / theme.js
1 /* This is sample front end code, uses the facilities provided by LoginManager
2 to easily create a login manager without having to deal with specific
3 implementation details. LoginManager uses jQuery events to wrap the
4 standard lightdm interface */
5
6 /* add a black box to hide enverything while its still loading,
7 this will be removed after LoginManager triggers its 'ready' event. */
8 $("body").append(`<div id="block" style="position: absolute;background-color: black;
9 width: 100%; height: 100vh; z-index:9999;"></div>`);
10
11 // create singleton
12 const greeter = new LoginManager();
13
14 // called after greeter and lightdm are initialized
15 $(greeter).on("ready", function(e) {
16
17         let $user = $("#selectUser");
18         let $session = $("#selectSession");
19         let $password = $("#inputPassword");
20
21         /*User the LoginManager's facility for easily filling the user
22         selection boxes and binding the appropriate
23         listeners needed by materialize */
24         greeter.fillUserSelect($user);
25         greeter.fillSessionSelect($session);
26
27         
28
29         /* Bind shutdown, restart hibernate and suspend to the
30         appropriate buttons */
31         $("#buttonPoweroff").click(function() {
32                 greeter.shutdown();
33         });
34         $("#buttonRestart").click(function() {
35                 greeter.restart();
36         });
37         $("#hibernate").click(function() {
38                 greeter.hibernate();
39         });
40
41         // Bind listener to the password box
42         $password.keypress((e) => {
43                 // user has typed, remove placeholder and invalid class
44                 $password.prop("placeholder", "").removeClass("invalid");
45
46                 /* Attempt authentication, 'grant' event will be emitted on sucecss
47                 and 'deny' will be emitted on failure */
48                 if (e.keyCode == 13) {
49                         let username = $user.children("option:selected").val();
50                         let pass = $password.val();
51                         greeter.auth(username, pass);
52                 }
53
54         });
55
56         // when the user is authenticated, do a transition and login
57         $(greeter).on("grant", () => {
58                 let session_key = $session.children("option:selected").val();
59                 greeter.login(session_key);
60         })
61         .on("deny", () => {
62                 // inform the user that the credentials are invalid
63                 $password.removeClass("valid").addClass("invalid");
64                 $password.val("").prop("placeholder", "Incorrect Password");
65         });
66
67         $(greeter.plugins.SplashScreen).on("active", function() {
68                 $(".active-appear").fadeIn();
69         }).on("inactive", function() {
70                 $(".active-appear").fadeOut();
71         });
72
73
74         /* Once everything else has loaded, its  safe to remove the black screen
75         hiding the dom. Do it async so that all currently running async
76         functions have a chance to complete */
77         setTimeout(() => $("#block").remove(), dur=1);
78 });