-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Dokan Login Form popup (#575)
- Loading branch information
1 parent
a547e20
commit 1c2b5c7
Showing
9 changed files
with
265 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// Dokan Login Form Popup | ||
(function($) { | ||
dokan.login_form_popup = { | ||
form_html: '', | ||
|
||
init: function () { | ||
$( 'body' ).on( 'dokan:login_form_popup:show', this.get_form ); | ||
$( 'body' ).on( 'submit', '#dokan-login-form-popup-form', this.submit_form ); | ||
$( 'body' ).on( 'dokan:login_form_popup:working', this.working ); | ||
$( 'body' ).on( 'dokan:login_form_popup:done_working', this.done_working ); | ||
}, | ||
|
||
get_form: function (e, options) { | ||
if ( dokan.login_form_popup.form_html ) { | ||
dokan.login_form_popup.show_popup(); | ||
return; | ||
} | ||
|
||
options = $.extend(true, { | ||
nonce: dokan.nonce, | ||
action: 'dokan_get_login_form' | ||
}, options ); | ||
|
||
$( 'body' ).trigger( 'dokan:login_form_popup:fetching_form' ); | ||
|
||
$.ajax( { | ||
url: dokan.ajaxurl, | ||
method: 'get', | ||
dataType: 'json', | ||
data: { | ||
_wpnonce: options.nonce, | ||
action: options.action | ||
} | ||
} ).done( function ( response ) { | ||
dokan.login_form_popup.form_html = response.data; | ||
dokan.login_form_popup.show_popup(); | ||
$( 'body' ).trigger( 'dokan:login_form_popup:fetched_form' ); | ||
} ); | ||
}, | ||
|
||
show_popup: function () { | ||
$.magnificPopup.open({ | ||
items: { | ||
src: dokan.login_form_popup.form_html, | ||
type: 'inline' | ||
}, | ||
|
||
callbacks: { | ||
open: function () { | ||
$( 'body' ).trigger( 'dokan:login_form_popup:opened' ); | ||
} | ||
} | ||
}); | ||
}, | ||
|
||
submit_form: function ( e ) { | ||
e.preventDefault(); | ||
|
||
var form_data = $( this ).serialize(); | ||
var error_section = $( '.dokan-login-form-error', '#dokan-login-form-popup-form' ); | ||
|
||
error_section.removeClass( 'has-error' ).text(''); | ||
|
||
$( 'body' ).trigger( 'dokan:login_form_popup:working' ); | ||
|
||
$.ajax( { | ||
url: dokan.ajaxurl, | ||
method: 'post', | ||
dataType: 'json', | ||
data: { | ||
_wpnonce: dokan.nonce, | ||
action: 'dokan_login_user', | ||
form_data: form_data | ||
} | ||
} ).done( function ( response ) { | ||
$( 'body' ).trigger( 'dokan:login_form_popup:logged_in' ); | ||
$.magnificPopup.close(); | ||
} ).always( function () { | ||
$( 'body' ).trigger( 'dokan:login_form_popup:done_working' ); | ||
} ).fail( function ( jqXHR ) { | ||
if ( jqXHR.responseJSON && jqXHR.responseJSON.data && jqXHR.responseJSON.data.message ) { | ||
error_section.addClass( 'has-error' ).text( jqXHR.responseJSON.data.message ); | ||
} | ||
} ); | ||
}, | ||
|
||
working: function () { | ||
$( 'fieldset', '#dokan-login-form-popup-form' ).prop( 'disabled', true ); | ||
$( '#dokan-login-form-submit-btn' ).addClass( 'dokan-hide' ); | ||
$( '#dokan-login-form-working-btn' ).removeClass( 'dokan-hide' ); | ||
}, | ||
|
||
done_working: function () { | ||
$( 'fieldset', '#dokan-login-form-popup-form' ).prop( 'disabled', false ); | ||
$( '#dokan-login-form-submit-btn' ).removeClass( 'dokan-hide' ); | ||
$( '#dokan-login-form-working-btn' ).addClass( 'dokan-hide' ); | ||
} | ||
}; | ||
|
||
dokan.login_form_popup.init(); | ||
})(jQuery); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
.dokan-login-form-popup-wrapper { | ||
width: 430px !important; | ||
padding: 16px !important; | ||
margin: 0 auto !important; | ||
|
||
.dokan-login-form-title { | ||
border-bottom: 1px solid #ddd; | ||
padding-bottom: 15px; | ||
margin-bottom: 15px; | ||
} | ||
|
||
fieldset { | ||
padding: 0; | ||
border: 0; | ||
margin: 0; | ||
} | ||
|
||
.dokan-login-form-error { | ||
color: @brand-danger; | ||
background-color: @state-danger-bg; | ||
font-size: 0.9em; | ||
|
||
&.has-error { | ||
padding: 5px 8px; | ||
margin-bottom: 5px; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<div class="white-popup dokan-login-form-popup-wrapper" id="dokan-login-form-popup"> | ||
<?php dokan_login_form( array( 'id' => 'dokan-login-form-popup-form' ), true ); ?> | ||
</div> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php if ( $title ): ?> | ||
<h2 class="dokan-login-form-title"><?php echo $title; ?></h2> | ||
<?php endif; ?> | ||
|
||
<form class="dokan-form-container" id="<?php echo esc_attr( $id ); ?>"> | ||
<fieldset> | ||
<div class="dokan-form-group"> | ||
<label class="dokan-form-label" for="dokan-login-form-username"><?php esc_html_e( 'Username', 'dokan-lite' ) ?>:</label> | ||
<input requireds class="dokan-form-control" type="text" name='dokan_login_form_username' id='dokan-login-form-username'/> | ||
</div> | ||
|
||
<div class="dokan-form-group"> | ||
<label class="dokan-form-label" for="dokan-login-form-password"><?php esc_html_e( 'Password', 'dokan-lite' ) ?>:</label> | ||
<input requireds class="dokan-form-control" type="password" name='dokan_login_form_password' id='dokan-login-form-password'/> | ||
</div> | ||
|
||
<div class="dokan-form-group"> | ||
<div class="dokan-login-form-error"></div> | ||
|
||
<button type="submit" class="dokan-w5 dokan-btn dokan-btn-theme" id="dokan-login-form-submit-btn"> | ||
<?php esc_html_e( 'Login', 'dokan-lite' ); ?> | ||
</button> | ||
|
||
<button type="button" class="dokan-w5 dokan-btn dokan-btn-theme dokan-hide" id="dokan-login-form-working-btn"> | ||
<i class="fa fa-refresh fa-spin"></i> <?php esc_html_e( 'Logging in', 'dokan-lite' ); ?>... | ||
</button> | ||
</div> | ||
|
||
<?php wp_nonce_field( esc_html( $nonce_action ), esc_html( $nonce_name ) ); ?> | ||
</fieldset> | ||
</form> | ||
<div class="dokan-clearfix"></div> |