Sha256: 5af4c09f2af56b3fb071c3d762058d448dda2d037151d78761c42d51dd7b9b50

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 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

2 entries across 2 versions & 1 rubygems

Version Path
password_strength-0.2.0 javascripts/jquery.strength.js
password_strength-0.1.6 lib/jquery.strength.js