Skip to content

Commit

Permalink
Adding option to pre-load login and register forms, #80.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane committed May 7, 2015
1 parent e6fd278 commit 3520bf7
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 69 deletions.
31 changes: 8 additions & 23 deletions assets/login.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
jQuery( document ).ready(function( $ ){

window.zMAjaxLoginDialog = {
open: function(){
$('#ajax-login-register-login-dialog').dialog('open');

$.ajax({
global: false,
type: "POST",
url: _ajax_login_settings.ajaxurl,
data: {
action: 'load_template',
referer: 'login_form',
template: 'login-form',
security: $('#ajax-login-register-login-dialog').attr('data-security')
},
success: function( msg ){
$( "#ajax-login-register-login-target" ).fadeIn().html( msg ); // Give a smooth fade in effect
}
});
}
};

/**
* We hook into the form submission and submit it via ajax.
* the action maps to our php function, which is added as
Expand Down Expand Up @@ -129,16 +108,22 @@ jQuery( document ).ready(function( $ ){
$this.attr( 'href', _ajax_login_settings.wp_logout_url );

} else {

$( document ).on('click', _ajax_login_settings.login_handle, function( event ){

event.preventDefault();
zMAjaxLoginDialog.open();
zMAjaxLoginRegister.open_login();

if ( ! _ajax_login_settings.pre_load_forms.length ){
zMAjaxLoginRegister.load_login();
}

});
}
}

$( document ).on('click', '.not-a-member-handle', function(){
$( document ).on('click', '.not-a-member-handle', function( e ){
e.preventDefault();
$('#ajax-login-register-login-dialog').dialog('close');
zMAjaxLoginRegisterDialog.open();
});
Expand Down
27 changes: 4 additions & 23 deletions assets/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,14 @@ jQuery( document ).ready(function( $ ){
$(this).closest('.ajax-login-register-container').dialog('close');
});

window.zMAjaxLoginRegisterDialog = {
open: function(){
$('#ajax-login-register-dialog').dialog('open');

var data = {
action: 'load_template',
template: 'register-form',
referer: 'register_form',
security: $('#ajax-login-register-dialog').attr('data-security')
};

$.ajax({
global: false,
data: data,
type: "POST",
url: _ajax_login_settings.ajaxurl,
success: function( msg ){
$( "#ajax-login-register-target" ).fadeIn().html( msg ); // Give a smooth fade in effect
}
});
}
};

if ( _ajax_login_settings.register_handle.length ){
$( document ).on('click', _ajax_login_settings.register_handle, function( event ){
event.preventDefault();
zMAjaxLoginRegisterDialog.open();
zMAjaxLoginRegister.open_register();
if ( ! _ajax_login_settings.pre_load_forms.length ){
zMAjaxLoginRegister.load_register();
}
});
}

Expand Down
80 changes: 58 additions & 22 deletions assets/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,64 @@ var zMAjaxLoginRegister = {
}

return msg;
},

open_login: function(){

jQuery('#ajax-login-register-login-dialog').dialog('open');

},

//
load_login: function(){
jQuery.ajax({
global: false,
type: "POST",
url: _ajax_login_settings.ajaxurl,
data: {
action: 'load_template',
referer: 'login_form',
template: 'login-form',
security: jQuery('#ajax-login-register-login-dialog').attr('data-security')
},
success: function( msg ){
jQuery( "#ajax-login-register-login-target" ).fadeIn().html( msg ); // Give a smooth fade in effect
}
});
},

//
open_register: function(){

jQuery('#ajax-login-register-dialog').dialog('open');

},

//
load_register: function(){

var data = {
action: 'load_template',
template: 'register-form',
referer: 'register_form',
security: jQuery('#ajax-login-register-dialog').attr('data-security')
};

jQuery.ajax({
global: false,
data: data,
type: "POST",
url: _ajax_login_settings.ajaxurl,
success: function( msg ){
jQuery( "#ajax-login-register-target" ).fadeIn().html( msg ); // Give a smooth fade in effect
}
});
}
};


jQuery( document ).ready(function( $ ){

window.zMAjaxLoginDialog = {
open: function(){
$('#ajax-login-register-login-dialog').dialog('open');

$.ajax({
global: false,
type: "POST",
url: _ajax_login_settings.ajaxurl,
data: {
action: 'load_template',
referer: 'login_form',
template: 'login-form',
security: $('#ajax-login-register-login-dialog').attr('data-security')
},
success: function( msg ){
$( "#ajax-login-register-login-target" ).fadeIn().html( msg ); // Give a smooth fade in effect
}
});
}
};


window.ajax_login_register_show_message = function( form_obj, msg ) {
if ( msg.code == 'success_login' || msg.code == 'success_registration' ){
Expand Down Expand Up @@ -156,4 +187,9 @@ jQuery( document ).ready(function( $ ){
of: 'body'
});

});
if ( _ajax_login_settings.pre_load_forms.length ){
zMAjaxLoginRegister.load_login();
zMAjaxLoginRegister.load_register();
}

});
6 changes: 6 additions & 0 deletions controllers/abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ public function get_settings(){
'label' => __('Force Check Password','ajax_login_register'),
'type' => 'checkbox',
'description' => __('Use this option if your are experiencing compatibility issues with other login and or register plugins.','ajax_login_register')
),
array(
'key' => 'ajax_login_register_pre_load_forms',
'label' => __('Pre-load Forms','ajax_login_register'),
'type' => 'checkbox',
'description' => __('Setting this option will pre-load the forms, allowing them to be loaded prior to being clicked on.','ajax_login_register')
)
);

Expand Down
3 changes: 2 additions & 1 deletion plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ function zm_ajax_login_register_localized_js(){
'is_user_logged_in' => is_user_logged_in() ? 1 : 0,
'wp_logout_url' => wp_logout_url( site_url() ),
'logout_text' => __('Logout', 'ajax_login_register' ),
'close_text' => __('Close', 'ajax_login_register' )
'close_text' => __('Close', 'ajax_login_register' ),
'pre_load_forms' => get_option( 'ajax_login_register_pre_load_forms' )
);

$localized = apply_filters( 'zm_ajax_login_register_localized_js', $defaults );
Expand Down

0 comments on commit 3520bf7

Please sign in to comment.