Created
October 9, 2012 16:28
-
-
Save darookee/3859889 to your computer and use it in GitHub Desktop.
Display password from a password field (like wifi-passwords in windows)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
$( document ).ready( function() { | |
$( 'input[type=password]' ).each( function( k, e ) { | |
var me = $( this ); | |
if( typeof myId == 'undefined' ) | |
var myId = me.attr( 'id' ); | |
if( typeof myName == 'undefined' ) | |
var myName = me.attr( 'name' ); | |
if( typeof w == 'undefined' ) | |
var w = me.wrap( '<span>' ).parent(); | |
if( typeof currentDisplay == 'undefined' ) | |
var currentDisplay = me.css( 'display' ); | |
if( typeof tinput == 'undefined' ) | |
var tinput = $( '<input type="text" style="display: none;" />' ).appendTo( w ); | |
if( typeof hinput == 'undefined' ) { | |
var hinput = $( '<input type="hidden" />' ).attr( 'id', myId ).attr( 'name', myName ).appendTo( w ); | |
me.removeAttr( 'id' ).removeAttr( 'name' ); | |
} | |
if( typeof pbox == 'undefined' ) { | |
var pbox = $( '<input type="checkbox" />' ).bind( 'change', function() { | |
if( typeof h == 'undefined' ) | |
var h = $( this ).prev( 'input[type=hidden]' ); | |
if( typeof e == 'undefined' ) | |
var e = h.prev( 'input[type=text]' ); | |
if( typeof ee == 'undefined' ) | |
var ee = e.prev( 'input[type=password]' ); | |
if( e.css( 'display' ) == 'none' ) { | |
h.attr( 'value', ee.attr( 'value' ) ); | |
e.attr( 'value', h.attr( 'value' ) ).css( 'display', currentDisplay ); | |
ee.css( 'display', 'none' ); | |
} else { | |
h.attr( 'value', e.attr( 'value' ) ); | |
e.css( 'display', 'none' ); | |
ee.css( 'display', currentDisplay ).attr( 'value', h.attr( 'value' ) ); | |
} | |
}) | |
.attr( 'id', myId + '-showpass' ); | |
pbox.appendTo( w ); | |
if( typeof pbl == 'undefined' ) { | |
var pbl = $( '<label>' ).html( 'Show Password' ).attr( 'for', myId + '-showpass' ).insertAfter( pbox ); | |
} | |
} | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment