scinote-web/app/assets/javascripts/sitewide/show_password.js

27 lines
905 B
JavaScript
Raw Normal View History

function initShowPassword() {
$('.sn-icon.sn-icon-visibility-show.show-password').remove();
2022-05-06 22:14:21 +08:00
$.each($('input[type="password"]'), function(i, e) {
2023-06-08 14:33:37 +08:00
$(`<i class="sn-icon sn-icon-visibility-show show-password"
style="
cursor: pointer;
z-index: 10;
"></i>`).insertAfter(e);
2022-05-06 22:14:21 +08:00
$(e).parent().addClass('right-icon');
});
}
$(document).on('turbolinks:load', function() {
2022-11-23 18:57:52 +08:00
initShowPassword();
2022-05-06 22:14:21 +08:00
});
$(document).on('click', '.show-password', function() {
let $icon = $(this);
if ($icon.hasClass('sn-icon-visibility-show')) {
$icon.removeClass('sn-icon-visibility-show').addClass('sn-icon-visibility-hide');
2022-05-06 22:14:21 +08:00
$icon.parent().find('input[type=password]').attr('type', 'text');
} else {
$icon.removeClass('sn-icon-visibility-hide').addClass('sn-icon-visibility-show');
2022-05-06 22:14:21 +08:00
$icon.parent().find('input[type=text]').attr('type', 'password');
}
});