All Projects → cferdinandi → X Ray

cferdinandi / X Ray

Licence: mit
X-Ray is a script that lets users toggle password visibility in forms.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to X Ray

Right Height
Dynamically set content areas of different lengths to the same height.
Stars: ✭ 91 (+127.5%)
Mutual labels:  no-dependencies, vanilla-js
Swiped Events
Adds `swiped` events to the DOM in 0.7k of pure JavaScript
Stars: ✭ 249 (+522.5%)
Mutual labels:  no-dependencies, vanilla-js
Houdini
A simple, accessible show-and-hide/accordion script.
Stars: ✭ 148 (+270%)
Mutual labels:  no-dependencies, vanilla-js
Modals
Simple modal dialogue windows
Stars: ✭ 85 (+112.5%)
Mutual labels:  no-dependencies, vanilla-js
Tabby
Lightweight, accessible vanilla JS toggle tabs.
Stars: ✭ 449 (+1022.5%)
Mutual labels:  no-dependencies, vanilla-js
Mailtoui
A simple way to enhance your mailto links with a convenient user interface.
Stars: ✭ 162 (+305%)
Mutual labels:  no-dependencies, vanilla-js
Validate
A lightweight form validation script.
Stars: ✭ 227 (+467.5%)
Mutual labels:  no-dependencies, vanilla-js
form-saver
A simple script that lets users save and reuse form data.
Stars: ✭ 67 (+67.5%)
Mutual labels:  vanilla-js, no-dependencies
Vanilla Emoji Picker
Modern emoji picker. Super light 2kb gzipped, simple and no frameworks 😻
Stars: ✭ 20 (-50%)
Mutual labels:  no-dependencies, vanilla-js
tabbis.js
Pure vanilla javascript tabs with nesting
Stars: ✭ 44 (+10%)
Mutual labels:  vanilla-js, no-dependencies
Smooth Scroll
A lightweight script to animate scrolling to anchor links.
Stars: ✭ 5,350 (+13275%)
Mutual labels:  no-dependencies, vanilla-js
Atomic
A tiny, Promise-based vanilla JS Ajax/HTTP plugin with great browser support.
Stars: ✭ 526 (+1215%)
Mutual labels:  no-dependencies, vanilla-js
Gumshoe
A simple vanilla JS scrollspy script.
Stars: ✭ 640 (+1500%)
Mutual labels:  no-dependencies, vanilla-js
Cpp redis
C++11 Lightweight Redis client: async, thread-safe, no dependency, pipelining, multi-platform - NO LONGER MAINTAINED - Please check https://github.com/cpp-redis/cpp_redis
Stars: ✭ 855 (+2037.5%)
Mutual labels:  no-dependencies
Regie
An observable state management tool for vanilla JS applications based on Proxies
Stars: ✭ 33 (-17.5%)
Mutual labels:  vanilla-js
Stabs
tabs in vanilla JS
Stars: ✭ 9 (-77.5%)
Mutual labels:  vanilla-js
Metro Ui Css
Impressive component library for expressive web development! Build responsive projects on the web with the first front-end component library in Metro Style. And now there are even more opportunities every day!
Stars: ✭ 6,843 (+17007.5%)
Mutual labels:  no-dependencies
Gesture recognition
a gesture recognition verification lock
Stars: ✭ 37 (-7.5%)
Mutual labels:  password
Passhunt
Passhunt is a simple tool for searching of default credentials for network devices, web applications and more. Search through 523 vendors and their 2084 default passwords.
Stars: ✭ 961 (+2302.5%)
Mutual labels:  password
Prompt Password
This repository has been archived, use the built-in password prompt in Enquirer instead.
Stars: ✭ 8 (-80%)
Mutual labels:  password

X-Ray Build Status

A script that lets users toggle password visibility in forms.

Download X-Ray / View the demo


Want to learn how to write your own vanilla JS plugins? Check out "The Vanilla JS Guidebook" and level-up as a web developer. 🚀


Getting Started

Compiled and production-ready code can be found in the dist directory. The src directory contains development code.

1. Include X-Ray on your site.

<link rel="stylesheet" href="dist/css/x-ray.css">
<script src="dist/js/x-ray.js"></script>

2. Add the markup to your HTML.

<form>
	<div>
		<label>Password</label>
		<input id="pw" type="password">
	</div>
	<div>
		<button class="x-ray" data-x-ray="#pw" data-default="show">
			<span class="x-ray-show" data-x-ray-show>Show Password</span>
			<span class="x-ray-hide" data-x-ray-hide>Hide Password</span>
		</button>
	</div>
</form>

Turn any link or button into a password visibility toggle by adding the .x-ray class and [data-x-ray] attribute. The value of the [data-x-ray] attribute should match the selector for the target password field. If you would like passwords to be visible by default, set the optional [data-default] attribute to show.

Use <span> elements with the .x-ray-show class and [data-x-ray-show] data attribute or .x-ray-hide class and [data-x-ray-hide] data attribute to change the toggle element based on whether or not the password is visible.

Using Checkboxes

If you'd prefer, you can use a checkbox instead of a button to toggle password visibility.

<form>
	<div>
		<label>Username</label>
		<input type="text">
	</div>
	<div>
		<label>Password</label>
		<input id="pw" type="password">
	</div>
	<div>
		<label class="x-ray">
			<input type="checkbox" data-x-ray="#pw" data-default="show" checked>
			Show password
		</label>
	</div>
</form>

Toggling Multiple Password Fields

You can toggle multiple password fields with one button or checkbox by using a class selector instead of an ID.

<form>
	<div>
		<label>Old Password</label>
		<input class="pw" type="password">
	</div>
	<div>
		<label>New Password</label>
		<input class="pw" type="password">
	</div>
	<div>
		<label class="x-ray">
			<input type="checkbox" data-x-ray=".pw" data-default="show" checked>
			Show passwords
		</label>
	</div>
</form>

3. Initialize X-Ray.

<script>
	xray.init();
</script>

In the footer of your page, after the content, initialize X-Ray. And that's it, you're done. Nice work!

Installing with Package Managers

You can install X-Ray with your favorite package manager.

  • NPM: npm install cferdinandi/x-ray
  • Bower: bower install https://github.com/cferdinandi/x-ray.git
  • Component: component install cferdinandi/x-ray

Working with the Source Files

If you would prefer, you can work with the development code in the src directory using the included Gulp build system. This compiles, lints, and minifies code.

Dependencies

Make sure these are installed first.

Quick Start

  1. In bash/terminal/command line, cd into your project directory.
  2. Run npm install to install required files.
  3. When it's done installing, run one of the task runners to get going:
    • gulp manually compiles files.
    • gulp watch automatically compiles files and applies changes using LiveReload.

Options and Settings

X-Ray includes smart defaults and works right out of the box. But if you want to customize things, it also has a robust API that provides multiple ways for you to adjust the default options and settings.

Global Settings

You can pass options and callbacks into X-Ray through the init() function:

xray.init({
	selector: '[data-x-ray]', // Selector for the password toggle (must be a valid CSS selector)
	selectorShow: '[data-x-ray-show]', // Selector for the "show password" text (must be a valid CSS selector)
	selectorHide: '[data-x-ray-hide]', // Selector for the "hide password" text  (must be a valid CSS selector)
	toggleActiveClass: 'active', // Class added to active password toggle button
	initClass: 'js-x-ray', // Class added to <html> element when initiated
	callback: function ( toggle, pwID ) {} // Function that's run after password visibility is toggled
});

Use X-Ray events in your own scripts

You can also call X-Ray's toggle password event in your own scripts.

runToggle()

Toggle password visibility on or off.

xray.runToggle(
	toggle, // Node that toggles the password visibility. ex. document.querySelector('[data-x-ray="#pw"]')
	pwID, // The ID or class of the password area(s) to show. ex. '#pw'
	options, // Classes and callbacks. Same options as those passed into the init() function.
	event // Optional, if a DOM event was triggered.
);

Example

var toggle = document.querySelector('[data-x-ray="#pw"]');
xray.runToggle( toggle, '#pw' );

destroy()

Destroy the current xray.init(). This is called automatically during the init function to remove any existing initializations.

xray.destroy();

Browser Compatibility

X-Ray works in all modern browsers, and IE 10 and above. You can extend browser support back to IE 9 with the classList.js polyfill.

X-Ray is built with modern JavaScript APIs, and uses progressive enhancement. If the JavaScript file fails to load, or if your site is viewed on older and less capable browsers, passwords will be masked by default.

How to Contribute

In lieu of a formal style guide, take care to maintain the existing coding style. Please apply fixes to both the development and production code. Don't forget to update the version number, and when applicable, the documentation.

License

The code is available under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].