I'm using jQuery to build simple animations for a login form in my CMS. The jQuery toggles the visibility of two forms, a login form, and a reset password form.
The script works perfectly fine, but I seem to figure out how to shorten it up, since most of the code is redundant.
Note: The .click
function is called twice in each case to force the animations to take place concurrently.
The JS:
$(function() {
var recover_text = "Password Recovery";
var login_text = "Login to CMS";
$("input").labelify({ text: "label", labelledClass: "inside" });
$("#forgot").click(function() {
$("#cms_login").fadeOut("fast", function() {
$("#pw_recover").fadeIn();
});
});
$("#forgot").click(function() {
$("#dialog h2").fadeOut("fast", function() {
$(this).html("" + recover_text + "").fadeIn();
});
document.title = '' + recover_text + '';
});
$("#login").click(function() {
$("#pw_recover").fadeOut("fast", function() {
$("#cms_login").fadeIn();
});
});
$("#login").click(function() {
$("#dialog h2").fadeOut("fast", function() {
$(this).html("" + login_text + "").fadeIn();
});
document.title = '' + login_text + '';
});
});
And the (abridged) HTML:
<div id="form-wrap">
<form id="cms_login">
...login fields...
<a id="forgot" href="#">Forgot password?</a>
</form>
<form id="pw_recover">
...reset password fields...
<a id="login" href="#">⇐ Back to login</a>
</form>
</div>
#pw_recover { display: none; }
How can I optimize/retool this script? Any thoughts?