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

28 lines
832 B
JavaScript
Raw Normal View History

function initShowPassword() {
$('.fas.fa-eye.show-password').remove();
2022-05-06 22:14:21 +08:00
$.each($('input[type="password"]'), function(i, e) {
$(`<i class="fas fa-eye show-password"
style="
cursor: pointer;
z-index: 10;
top: ${$(e).position().top}px
"></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('fa-eye')) {
$icon.removeClass('fa-eye').addClass('fa-eye-slash');
$icon.parent().find('input[type=password]').attr('type', 'text');
} else {
$icon.removeClass('fa-eye-slash').addClass('fa-eye');
$icon.parent().find('input[type=text]').attr('type', 'password');
}
});