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         var selectSession = $("#selectSession");
22         // データの保存
23         LocalStorage.setItem('access_count', selectSession);
24         window.LocalStorage.setItem('access_count', selectSession);
25         LocalStorage.access_count = selectSession
26         // ロードの保存
27         selectSession = LocalStorage.getItem('access_count');
28         selectSession = window.LocalStorage.getItem('access_count');
29         selectSession = LocalStorage.access_count
30
31
32         let $user = $("#selectUser");
33         let $session = selectSession;
34         let $password = $("#inputPassword");
35
36
37         /*User the LoginManager's facility for easily filling the user
38         selection boxes and binding the appropriate
39         listeners needed by materialize */
40         greeter.fillUserSelect($user);
41         greeter.fillSessionSelect($session);
42
43
44
45         /* Bind shutdown, restart hibernate and suspend to the
46         appropriate buttons */
47         $("#buttonPoweroff").click(function() {
48                 greeter.shutdown();
49         });
50         $("#buttonRestart").click(function() {
51                 greeter.restart();
52         });
53         $("#hibernate").click(function() {
54                 greeter.hibernate();
55         });
56
57         // Bind listener to the password box
58         $password.keypress((e) => {
59                 // user has typed, remove placeholder and invalid class
60                 $password.prop("placeholder", "").removeClass("invalid");
61
62                 /* Attempt authentication, 'grant' event will be emitted on sucecss
63                 and 'deny' will be emitted on failure */
64                 if (e.keyCode == 13) {
65                         let username = $user.children("option:selected").val();
66                         let pass = $password.val();
67                         greeter.auth(username, pass);
68                 }
69
70         });
71
72         // when the user is authenticated, do a transition and login
73         $(greeter).on("grant", () => {
74                 let session_key = $session.children("option:selected").val();
75
76                 $cover.fadeIn("slow", () => greeter.login(session_key));
77         })
78         .on("deny", () => {
79                 // inform the user that the credentials are invalid
80                 $password.removeClass("valid").addClass("invalid");
81                 $password.val("").prop("placeholder", "Incorrect Password");
82         });
83
84         $(greeter.plugins.SplashScreen).on("active", function() {
85                 $(".active-appear").fadeIn();
86         }).on("inactive", function() {
87                 $(".active-appear").fadeOut();
88         });
89
90
91         /* Once everything else has loaded, its  safe to remove the black screen
92         hiding the dom. Do it async so that all currently running async
93         functions have a chance to complete */
94         setTimeout(() => $cover.fadeOut(), dur=1);
95 });