| 1 |
jQuery(function($){ |
| 2 |
$('body').on('submit', '#loginform', function(e){ |
| 3 |
if($(this).data('action')){ |
| 4 |
e.preventDefault(); |
| 5 |
|
| 6 |
$('div#login_error').remove(); |
| 7 |
$(this).removeClass('shake'); |
| 8 |
|
| 9 |
$(this).wpjam_submit(function(data){ |
| 10 |
if(data.errcode){ |
| 11 |
$('h1').after('<div id="login_error" class="notice notice-error">'+data.errmsg+'</div>'); |
| 12 |
$(this).addClass('shake'); |
| 13 |
}else{ |
| 14 |
if($('p.types').data('action') == 'bind'){ |
| 15 |
window.location.reload(); |
| 16 |
}else{ |
| 17 |
if($('body').hasClass('interim-login')){ |
| 18 |
$('body').addClass('interim-login-success'); |
| 19 |
$(window.parent.document).find('.wp-auth-check-close').click(); |
| 20 |
}else{ |
| 21 |
window.location.href = $.trim($('input[name="redirect_to"]').val()); |
| 22 |
} |
| 23 |
} |
| 24 |
} |
| 25 |
}); |
| 26 |
} |
| 27 |
}); |
| 28 |
|
| 29 |
$('body').on('click', 'p.types a', function(e){ |
| 30 |
e.preventDefault(); |
| 31 |
|
| 32 |
$('div#login_error').remove(); |
| 33 |
|
| 34 |
$('#loginform').removeClass('shake').hide(); |
| 35 |
|
| 36 |
let action = $('p.types').data('action'); |
| 37 |
let url = new URL(window.location.href); |
| 38 |
|
| 39 |
if(action == 'login' && $(this).data('type') == 'login'){ |
| 40 |
$('p#nav').show(); |
| 41 |
|
| 42 |
$('div.fields').html(login_fields); |
| 43 |
$('#loginform').data('action', '').slideDown(300); |
| 44 |
|
| 45 |
$('.types a').removeClass('current'); |
| 46 |
$(this).addClass('current'); |
| 47 |
|
| 48 |
url.searchParams.delete(action+'_type'); |
| 49 |
window.history.replaceState(null, null, url.toString()); |
| 50 |
}else{ |
| 51 |
$('p#nav').hide(); |
| 52 |
|
| 53 |
$(this).wpjam_action(function(data){ |
| 54 |
if(data.errcode != 0){ |
| 55 |
alert(data.errmsg); |
| 56 |
}else{ |
| 57 |
$('div.fields').html(data.fields); |
| 58 |
$('#loginform').data('action', data.action).data('data', data.data).data('nonce', data.nonce).slideDown(300); |
| 59 |
|
| 60 |
if(data.submit_text){ |
| 61 |
$('input#wp-submit').val(data.submit_text); |
| 62 |
} |
| 63 |
|
| 64 |
$('.types a').removeClass('current'); |
| 65 |
$(this).addClass('current'); |
| 66 |
|
| 67 |
url.searchParams.set(action+'_type', $(this).data('type')); |
| 68 |
window.history.replaceState(null, null, url.toString()); |
| 69 |
} |
| 70 |
}); |
| 71 |
} |
| 72 |
|
| 73 |
return true; |
| 74 |
}); |
| 75 |
|
| 76 |
$('p.types').insertBefore('p.submit'); |
| 77 |
|
| 78 |
$('<div class="fields"></div>').prependTo('#loginform'); |
| 79 |
|
| 80 |
$('input#user_login').parent().appendTo('div.fields'); |
| 81 |
$('div.user-pass-wrap, p.forgetmenot').appendTo('div.fields'); |
| 82 |
|
| 83 |
let login_fields = $('div.fields').html(); |
| 84 |
|
| 85 |
if($('p.types').data('action') == 'bind'){ |
| 86 |
$('title').html('绑定'); |
| 87 |
} |
| 88 |
|
| 89 |
if($('p.types a.current').data('type') != 'login'){ |
| 90 |
$('p.types a.current').click(); |
| 91 |
} |
| 92 |
}); |