Skip to content

Commit

Permalink
Fix: AJAX preview loading when disabled on settings pages (#928)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmigf authored Dec 13, 2024
1 parent 7a3ab4a commit b1b50b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions assets/js/admin-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ jQuery( function( $ ) {
$( this ).closest( 'tr' ).nextAll( 'tr' ).has( 'input#next_invoice_number' ).first().show();
}
} ).trigger( 'change' );

// disable encrypted pdf option for non UBL 2.1 formats
$( "[name='wpo_wcpdf_documents_settings_invoice_ubl[ubl_format]']" ).on( 'change', function( event ) {
let $encryptedPdfCheckbox = $( this ).closest( 'form' ).find( "[name='wpo_wcpdf_documents_settings_invoice_ubl[include_encrypted_pdf]']" );

if ( $( this ).val() !== 'ubl_2_1' ) {
$encryptedPdfCheckbox.prop( 'checked', false ).prop( 'disabled', true );
} else {
Expand Down Expand Up @@ -384,7 +384,14 @@ jQuery( function( $ ) {
} );

// Trigger the Preview
function triggerPreview( timeoutDuration ) {
function triggerPreview( timeoutDuration = 0 ) {
$previewStates = $( '#wpo-wcpdf-preview-wrapper' ).data( 'preview-states' );

// Check if preview is disabled and return
if ( 'undefined' === $previewStates || 1 === $previewStates ) {
return;
}

timeoutDuration = typeof timeoutDuration == 'number' ? timeoutDuration : 0;

loadPreviewData();
Expand Down Expand Up @@ -441,6 +448,7 @@ jQuery( function( $ ) {

// Load the Preview with AJAX
function ajaxLoadPreview() {
console.log( 'Loading preview...' );
let worker = wpo_wcpdf_admin.pdfjs_worker;
let canvasId = 'preview-canvas';
let data = {
Expand Down
Loading

0 comments on commit b1b50b8

Please sign in to comment.