Created
March 4, 2012 03:43
-
-
Save zanematthew/1970569 to your computer and use it in GitHub Desktop.
JavaScript used for the WordPress Ajax Login form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* JavaScript file for loading the custom login form. | |
* Note we are using jQuery in "no conflict mode". | |
*/ | |
jQuery(document).ready(function( $ ){ | |
/** | |
* Set-up our default dialog box with the following | |
* parameters. | |
*/ | |
$('#bmx_rs_dialog').dialog({ | |
autoOpen: false, | |
width: 265, // needed since default is 300px | |
resizable: false, | |
modal: true, | |
title: 'Login' | |
}); | |
/** | |
* Close our dialog box when the user clicks anything | |
* inside of the div "bmx_rs_dialog" with the class | |
* of "cancel". | |
*/ | |
$( '#bmx_rs_dialog .cancel' ).live('click', function(){ | |
$( '#bmx_rs_dialog' ).dialog( 'close' ); | |
}); | |
/** | |
* We hook into the form submission and submit it via ajax. | |
* the action maps to our php function, which is added as | |
* an action, and we serialize the entire contents of the form. | |
* note we set global false to prevent other global ajax functions | |
* from firing. | |
*/ | |
$( '#bmx_rs_dialog form' ).live('submit', function(){ | |
$.ajax({ | |
data: "action=zm_register_login_submit&" + $(this).serialize(), | |
global: false, | |
success: function( msg ){ | |
location.reload( true ); // This could be nicer | |
} | |
}); | |
}); | |
/** | |
* When ever a DOM element with a class of "login-handle" is clicked. | |
* We open the dialog box, and send an ajax request to load our form. | |
*/ | |
$('.login-handle').live('click', function( event ){ | |
event.preventDefault(); | |
$('#bmx_rs_dialog').dialog('open'); | |
$.ajax({ | |
data: { | |
"action": "zm_load_template", | |
"target_div": "#bmx_rs_login_target", | |
"template": $( this ).attr("data-template") | |
}, | |
global: false, | |
success: function( msg ){ | |
$( "#bmx_rs_login_target" ).fadeIn().html( msg ); // Give a smooth fade in effect | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment