Sha256: 5bd2387ee5fc1648d7af566e6ae8e6b2edcebbaeddac3bb4e6b55f87ab0f83a9

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

(function($){
	$.strength = function(username, password, options, callback) {
		if (typeof(options) == "function") {
			callback = options;
			options = {};
		} else if (!options) {
			options = {};
		}

		var usernameField = $(username);
		var passwordField = $(password);
		var strength = new PasswordStrength();

		strength.exclude = options["exclude"];

		callback = callback || $.strength.callback;

		var handler = function(){
			strength.username = $(usernameField).val();

			if ($(usernameField).length == 0) {
				strength.username = username;
			}

			strength.password = $(passwordField).val();

			if ($(passwordField).length == 0) {
				strength.password = password;
			}

			strength.test();
			callback(usernameField, passwordField, strength);
		};

		$(usernameField).keydown(handler);
		$(usernameField).keyup(handler);

		$(passwordField).keydown(handler);
		$(passwordField).keyup(handler);
	};

	$.extend($.strength, {
		callback: function(username, password, strength){
			var img = $(password).next("img.strength");

			if (!img.length) {
				$(password).after("<img class='strength'>");
				img = $("img.strength");
			}

			$(img)
				.removeClass("weak")
				.removeClass("good")
				.removeClass("strong")
				.addClass(strength.status)
				.attr("src", $.strength[strength.status + "Image"]);
		},
		weakImage: "/images/weak.png",
		goodImage: "/images/good.png",
		strongImage: "/images/strong.png"
	});
})(jQuery);

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
password_strength-0.3.2 javascripts/jquery.strength.js
password_strength-0.3.1 javascripts/jquery.strength.js
password_strength-0.3.0 javascripts/jquery.strength.js