ftp-manager/app/assets/javascripts/passwords.js

37 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

function getPassword($container, password) {
$container.data('password', password);
$container.find('span').html(password);
$container.find('a').detach();
$container.prepend('<i class="fa fa-unlock fa-lg"></i>');
}
function hidePassword($src){
$src.siblings('span').html('********');
$src.removeClass('fa-unlock').addClass('fa-lock');
}
function revealPassword($src){
$src.siblings('span').html($src.parent().data('password'));
$src.removeClass('fa-lock').addClass('fa-unlock');
}
2016-09-28 21:23:01 -05:00
// Use this instead of typical $().ready
// because turbolinks.
document.addEventListener("turbolinks:load", function() {
2016-09-28 22:39:42 -05:00
$("[data-id=genpass]").on("ajax:success", "a", function(e, data){
$(e.target).parent().find("input").val(data.hash);
});
$("[data-id=passwd]").on("ajax:success", "a", function(e, data){
getPassword($(e.target).parent(), data.hash);
});
$("[data-id=passwd]").on('click', 'i', function(){
if($(this).hasClass('fa-unlock')){
hidePassword($(this));
} else {
revealPassword($(this));
}
});
});