Skip to content

Commit

Permalink
Add spinner while waiting for downloading fonts VisualComposer#328
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-kovalov committed Jul 12, 2022
1 parent 789215e commit ff094e3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
3 changes: 2 additions & 1 deletion css/customizer-custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
transform: rotate(-45deg);
}

.vct-popup-buttons {
.vct-popup-buttons,
.vct-spinner-wrapper {
margin-top: 30px;
}

Expand Down
6 changes: 6 additions & 0 deletions inc/customizer/class-visualcomposerstarter-customizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3068,6 +3068,12 @@ public function print_popup_template() {
<button id="vct-popup-accept-button" class="button button-primary"><?php esc_html_e( 'Download & Publish', 'visual-composer-starter' ); ?></button>
<button id="vct-popup-cancel-button" class="button button-primary"><?php esc_html_e( 'Revert & Publish', 'visual-composer-starter' ); ?></button>
</div>
<div class="vct-spinner-wrapper" style="display: none;">
<span>
<img src="<?php echo esc_url( includes_url( 'images/spinner.gif' ) ); ?>"
alt="<?php esc_html_e( 'Spinner', 'visual-composer-starter' ); ?>">
</span>
</div>
</div>
</div>
<?php
Expand Down
26 changes: 22 additions & 4 deletions js/customize-popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,26 @@

// Download fonts
$( document ).on( 'click', '#vct-popup-accept-button', function( e ) {
var $downloadBtn = $(this);
var $revertBtn = $downloadBtn.siblings('button');
var $spinner = $downloadBtn.parents('.vct-popup-buttons').siblings('.vct-spinner-wrapper');

e && e.preventDefault && e.preventDefault();

if ( ! $.isEmptyObject( changedFonts ) ) {
$.post( window.ajaxurl, {
'action': 'vct_download_fonts',
'security': window.googleFontControlData.nonce,
'fonts': changedFonts
$.ajax( {
method: 'POST',
url: window.ajaxurl,
beforeSend: function() {
$downloadBtn.prop('disabled', true);
$revertBtn.prop('disabled', true);
$spinner.show();
},
data: {
'action': 'vct_download_fonts',
'security': window.googleFontControlData.nonce,
'fonts': changedFonts
}
} ).fail( function( xhr ) {
window.alert( xhr.responseText );
} ).done( function( response ) {
Expand All @@ -107,6 +121,10 @@
// Save settings
wp.customize.previewer.save();
}

$downloadBtn.prop('disabled', false);
$revertBtn.prop('disabled', false);
$spinner.hide();
} );
} else {
wp.customize.previewer.save();
Expand Down

0 comments on commit ff094e3

Please sign in to comment.