OSDN Git Service

[更新]:エンターキーで勝手に送信されてしまう問題の修正
[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 var $cover = $(`<div id="block" style="position: absolute;
9 background-color: black;width: 100%; height: 100vh; z-index:9999;"></div>`);
10
11 $(document).ready(() => {
12         $("body").append($cover);
13 });
14
15 // create singleton
16 const greeter = new LoginManager();
17
18 // called after greeter and lightdm are initialized
19 $(greeter).on("ready", function(e) {
20
21         let $user = $("#selectUser");
22         let $session = $("#selectSession");
23         let $password = $("#inputPassword");
24
25
26         /*User the LoginManager's facility for easily filling the user
27         selection boxes and binding the appropriate
28         listeners needed by materialize */
29         greeter.fillUserSelect($user);
30         greeter.fillSessionSelect($session);
31
32
33
34         /* Bind shutdown, restart hibernate and suspend to the
35         appropriate buttons */
36         $("#buttonPoweroff").click(function() {
37                 greeter.shutdown();
38         });
39         $("#buttonRestart").click(function() {
40                 greeter.restart();
41         });
42         $("#hibernate").click(function() {
43                 greeter.hibernate();
44         });
45
46         // Bind listener to the password box
47         $password.keypress((e) => {
48                 // user has typed, remove placeholder and invalid class
49                 $password.prop("placeholder", "").removeClass("invalid");
50
51                 /* Attempt authentication, 'grant' event will be emitted on sucecss
52                 and 'deny' will be emitted on failure */
53                 if (e.keyCode == 13) {
54                         if(!$(this).val() == ""){
55                                 let username = $user.children("option:selected").val();
56                                 let pass = $password.val();
57                                 greeter.auth(username, pass);
58                         }
59                 }
60
61         });
62
63         // when the user is authenticated, do a transition and login
64         $(greeter).on("grant", () => {
65                 let session_key = $session.children("option:selected").val();
66
67                 $cover.fadeIn("slow", () => greeter.login(session_key));
68         })
69         .on("deny", () => {
70                 // inform the user that the credentials are invalid
71                 $password.removeClass("valid").addClass("invalid");
72                 $password.val("").prop("placeholder", "Incorrect Password");
73         });
74
75         $(greeter.plugins.SplashScreen).on("active", function() {
76                 $(".active-appear").fadeIn();
77         }).on("inactive", function() {
78                 $(".active-appear").fadeOut();
79         });
80
81
82         /* Once everything else has loaded, its  safe to remove the black screen
83         hiding the dom. Do it async so that all currently running async
84         functions have a chance to complete */
85         setTimeout(() => $cover.fadeOut(), dur=1);
86 });