Skip to content

Commit bd25011

Browse files
Refactor login form UI
1 parent 5bbc1e1 commit bd25011

File tree

2 files changed

+46
-13
lines changed

2 files changed

+46
-13
lines changed

assets/js/togglepassword.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
(function ($) {
2+
3+
$.fn.togglepassword = function (btnclass) {
4+
this.each(function(){
5+
let id = $(this).attr('id') ?? ($(this).attr('name') ?? '');
6+
let autofocus = $(this).prop('autofocus') !== true ? '' : ' autofocus';
7+
let name = $(this).attr('name') ?? '';
8+
let classlist = $(this).attr('class') ?? '';
9+
let value = $(this).val();
10+
let content = '<i class="fas fa-eye-slash"></i>';
11+
let title = 'Show password';
12+
btnclass = btnclass ?? '';
13+
return $(this).replaceWith(
14+
$('<div class="input-group mb-3"></div>')
15+
.append($('<input type="password" class="' + classlist + '" id="' + id + '" name="' + name + '" value="' + value + '"' + autofocus + '>'))
16+
.append('<span class="input-group-text" id="basic-addon1"><button type="button" class="' + btnclass + '" data-role="togglepassword" data-target="#' + id + '" title="' + title + '" tabindex="-1">' + content + '</button></span>')
17+
);
18+
});
19+
};
20+
21+
})(jQuery);
22+
23+
$(() => {
24+
25+
$(document).on('click', '[data-role="togglepassword"]', function () {
26+
let target = $(this).data('target');
27+
let is_password = $(target).attr('type') === 'password';
28+
$(target).attr('type', (is_password ? 'text' : 'password'));
29+
$(this).html('<i class="fas fa-eye' + (is_password ? '' : '-slash') + '"></i>');
30+
$(this).attr('title', is_password ? 'Show password' : 'Hide password');
31+
});
32+
33+
});

login.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,7 @@
3232
<div id="content">
3333
<nav class="navbar navbar-light navbar-expand bg-white shadow mb-4 topbar static-top">
3434
<div class="container-fluid"><button class="btn btn-link d-md-none rounded-circle me-3" id="sidebarToggleTop" type="button"><i class="fas fa-bars"></i></button>
35-
<ul class="navbar-nav flex-nowrap ms-auto">
36-
<li class="nav-item dropdown d-sm-none no-arrow"><a class="dropdown-toggle nav-link" aria-expanded="false" data-bs-toggle="dropdown" href="#"><i class="fas fa-search"></i></a>
37-
<div class="dropdown-menu dropdown-menu-end p-3 animated--grow-in" aria-labelledby="searchDropdown">
38-
<form class="me-auto navbar-search w-100">
39-
<div class="input-group"><input class="bg-light form-control border-0 small" type="text" placeholder="Search for ...">
40-
<div class="input-group-append"><button class="btn btn-primary py-0" type="button"><i class="fas fa-search"></i></button></div>
41-
</div>
42-
</form>
43-
</div>
44-
</li>
45-
</ul>
35+
4636
</div>
4737
</nav>
4838
<section class="position-relative py-4 py-xl-5">
@@ -60,8 +50,11 @@
6050
<path d="M8 8a3 3 0 1 0 0-6 3 3 0 0 0 0 6Zm2-3a2 2 0 1 1-4 0 2 2 0 0 1 4 0Zm4 8c0 1-1 1-1 1H3s-1 0-1-1 1-4 6-4 6 3 6 4Zm-1-.004c-.001-.246-.154-.986-.832-1.664C11.516 10.68 10.289 10 8 10c-2.29 0-3.516.68-4.168 1.332-.678.678-.83 1.418-.832 1.664h10Z"></path>
6151
</svg></div>
6252
<form action="functions/login.php" method="post">
63-
<div class="mb-3 text-center"><input class="form-control" type="text" name="username" placeholder="Username" value="<?php echo isset($_COOKIE['username']) ? $_COOKIE['username'] : ''; ?>"></div>
64-
<div class="mb-3 text-center"><input class="form-control" type="password" name="password" placeholder="Password" value="<?php echo isset($_COOKIE['password']) ? $_COOKIE['password'] : ''; ?>"></div>
53+
<div class="mb-3 text-center"><input class="form-control form-control-lg" type="text" name="username" placeholder="Username" value="<?php echo isset($_COOKIE['username']) ? $_COOKIE['username'] : ''; ?>"></div>
54+
<div class="mb-3 text-center"></div>
55+
<div class="input-group mb-3">
56+
<input class="form-control" type="password" name="password" placeholder="Password" value="<?php echo isset($_COOKIE['password']) ? $_COOKIE['password'] : ''; ?>">
57+
</div>
6558
<div class="mb-3">
6659
<input class="form-check-input" name="remember" type="checkbox" aria-label="remember" <?php echo isset($_COOKIE['username']) ? 'checked' : ''; ?>>
6760
<label class="form-check-label text-dark" for="remember">
@@ -99,7 +92,14 @@
9992
<script src="assets/js/listTable.js"></script>
10093
<script src="assets/js/theme.js"></script>
10194
<script src="assets/js/sweetalert.min.js"></script>
95+
<script src="assets/js/togglepassword.js"></script>
10296
<script>
97+
$(() => {
98+
99+
$('[type="password"]').togglepassword('btn btn-sm');
100+
101+
});
102+
103103
const urlParams = new URLSearchParams(window.location.search);
104104
const type = urlParams.get('type');
105105
const message = urlParams.get('message');

0 commit comments

Comments
 (0)