WordPress/wp-admin/js/password-toggle.js
joedolson 549163d3e9 Upgrade/Install: Show/hide toggle on password fields.
Add a show/hide toggle for new passwords in initial user creation and database access during install and setup process using the same model as on user profiles. Add a new password toggle script. Change setup config table to two columns, matching the install table layout.

Props xmarcos, matt, markjaquith, nazgul, akbigdog, intoxination, rob1n, MichaelH, empireoflight, rmccue, markoheijnen, r0uter, amansurov, bi0xid, DrewAPicture, Narthur, wpnook, markparnell, costdev, clorith, ryokuhi, sabernhardt, bgoewert, ironprogrammer, adeltahri, joedolson, mukesh27, audrasjb, sergeybiryukov.
Fixes #3534.
Built from https://develop.svn.wordpress.org/trunk@56008


git-svn-id: http://core.svn.wordpress.org/trunk@55520 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2023-06-23 23:09:29 +00:00

41 lines
1.3 KiB
JavaScript

/**
* Adds functionality for password visibility buttons to toggle between text and password input types.
*
* @since 6.3.0
* @output wp-admin/js/password-toggle.js
*/
( function () {
var toggleElements, status, input, icon, label, __ = wp.i18n.__;
toggleElements = document.querySelectorAll( '.pwd-toggle' );
toggleElements.forEach( function (toggle) {
toggle.classList.remove( 'hide-if-no-js' );
toggle.addEventListener( 'click', togglePassword );
} );
function togglePassword() {
status = this.getAttribute( 'data-toggle' );
input = this.parentElement.children.namedItem( 'pwd' );
icon = this.getElementsByClassName( 'dashicons' )[ 0 ];
label = this.getElementsByClassName( 'text' )[ 0 ];
if ( 0 === parseInt( status, 10 ) ) {
this.setAttribute( 'data-toggle', 1 );
this.setAttribute( 'aria-label', __( 'Hide password' ) );
input.setAttribute( 'type', 'text' );
label.innerHTML = __( 'Hide' );
icon.classList.remove( 'dashicons-visibility' );
icon.classList.add( 'dashicons-hidden' );
} else {
this.setAttribute( 'data-toggle', 0 );
this.setAttribute( 'aria-label', __( 'Show password' ) );
input.setAttribute( 'type', 'password' );
label.innerHTML = __( 'Show' );
icon.classList.remove( 'dashicons-hidden' );
icon.classList.add( 'dashicons-visibility' );
}
}
} )();