Skip to content

Commit

Permalink
Add type to shortcode when missing, refactor constants.
Browse files Browse the repository at this point in the history
  • Loading branch information
doekenorg committed Mar 7, 2024
1 parent 2ba74f5 commit 93c5a2b
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions public/js/gravityexport-lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,40 @@ var gfexcel_sortable;
});
};

$(document).ready(function () {
$( document ).ready( function () {
const $embedShortcodeEl = $( '#embed_code' );
const secret = $embedShortcodeEl.data( 'secret' );

$( '#start_date, #end_date' ).datepicker( { dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true } );

$( '#file_extension' ).on( 'change', function ( e ) {
const shortcode = $( '#embed_code' ).val();
$( '#file_extension' ).on( 'change', function () {
const shortcode = $embedShortcodeEl.val();
const has_type = shortcode.match( / type=/ );
const regex = has_type ? / type="[^"]*"/ : /]$/ ;

let type = ` type="${ $( this ).val() }"`;

$( '#embed_code' ).val( shortcode.replace( /type=\"[^\"]*\"/, `type="${ e.target.value }"` ) );
if ( ! has_type ) {
type += ']';
}

$embedShortcodeEl.val( shortcode.replace(regex , type ) );
} );

$( '#has_embed_secret' ).on( 'change', function () {
const $embedShortcodeEl = $( '#embed_code' );
const secret = $embedShortcodeEl.data( 'secret' );
let embedShortcode = $embedShortcodeEl.val();

if ( !embedShortcode ) {
return;
}

if ( $( this ).is( ':checked' ) ) {
embedShortcode = embedShortcode.replace( /\]$/, ` secret="${ secret }"]` );
embedShortcode = embedShortcode.replace( /]$/, ` secret="${ secret }"]` );
} else {
embedShortcode = embedShortcode.replace( / secret="[^"]+"/, '' );
}

$embedShortcodeEl.val( embedShortcode );
});
});
} );
} );
})(jQuery);

0 comments on commit 93c5a2b

Please sign in to comment.