Skip to content

Commit ea27578

Browse files
committed
Add type to shortcode when missing, refactor constants.
1 parent 82d852d commit ea27578

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

public/js/gravityexport-lite.js

+18-9
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,40 @@ var gfexcel_sortable;
6464
});
6565
};
6666

67-
$(document).ready(function () {
67+
$( document ).ready( function () {
68+
const $embedShortcodeEl = $( '#embed_code' );
69+
const secret = $embedShortcodeEl.data( 'secret' );
70+
6871
$( '#start_date, #end_date' ).datepicker( { dateFormat: 'yy-mm-dd', changeMonth: true, changeYear: true } );
6972

70-
$( '#file_extension' ).on( 'change', function ( e ) {
71-
const shortcode = $( '#embed_code' ).val();
73+
$( '#file_extension' ).on( 'change', function () {
74+
const shortcode = $embedShortcodeEl.val();
75+
const has_type = shortcode.match( / type=/ );
76+
const regex = has_type ? / type="[^"]*"/ : /]$/ ;
77+
78+
let type = ` type="${ $( this ).val() }"`;
7279

73-
$( '#embed_code' ).val( shortcode.replace( /type=\"[^\"]*\"/, `type="${ e.target.value }"` ) );
80+
if ( ! has_type ) {
81+
type += ']';
82+
}
83+
84+
$embedShortcodeEl.val( shortcode.replace(regex , type ) );
7485
} );
7586

7687
$( '#has_embed_secret' ).on( 'change', function () {
77-
const $embedShortcodeEl = $( '#embed_code' );
78-
const secret = $embedShortcodeEl.data( 'secret' );
7988
let embedShortcode = $embedShortcodeEl.val();
8089

8190
if ( !embedShortcode ) {
8291
return;
8392
}
8493

8594
if ( $( this ).is( ':checked' ) ) {
86-
embedShortcode = embedShortcode.replace( /\]$/, ` secret="${ secret }"]` );
95+
embedShortcode = embedShortcode.replace( /]$/, ` secret="${ secret }"]` );
8796
} else {
8897
embedShortcode = embedShortcode.replace( / secret="[^"]+"/, '' );
8998
}
9099

91100
$embedShortcodeEl.val( embedShortcode );
92-
});
93-
});
101+
} );
102+
} );
94103
})(jQuery);

0 commit comments

Comments
 (0)