CoreFiles by mySites.guru
password-toggle.js45 lines, 1,406 bytes, from wordpress-7.2-beta4.zip
Raw History Compare with 7.2-beta3
md5
a1fe6fca12a8a7c76a17154d23799e06
sha1
9058d71a0b8998fd677739783fbd62884b6ffa5d
sha256
017cd0430ea9d35d9f4ab51dce5cbba143966046b0cf41ca3d0a9570de7f5ccd
/**
 * @output wp-admin/js/password-toggle.js
 */

/**
 * Adds functionality for password visibility buttons to toggle between text and password input types.
 *
 * @since 6.3.0
 */
( 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 );
	} );

	/**
	 * Toggles the password input field visibility.
	 */
	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' );
		}
	}
} )();

The same content is in 6 releases, WordPress 7.2-beta1 to 7.2-RC1. See them all, or every version of this file.