@@ -64,31 +64,40 @@ var gfexcel_sortable;
64
64
} ) ;
65
65
} ;
66
66
67
- $ ( document ) . ready ( function ( ) {
67
+ $ ( document ) . ready ( function ( ) {
68
+ const $embedShortcodeEl = $ ( '#embed_code' ) ;
69
+ const secret = $embedShortcodeEl . data ( 'secret' ) ;
70
+
68
71
$ ( '#start_date, #end_date' ) . datepicker ( { dateFormat : 'yy-mm-dd' , changeMonth : true , changeYear : true } ) ;
69
72
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 ( / t y p e = / ) ;
76
+ const regex = has_type ? / t y p e = " [ ^ " ] * " / : / ] $ / ;
77
+
78
+ let type = ` type="${ $ ( this ) . val ( ) } "` ;
72
79
73
- $ ( '#embed_code' ) . val ( shortcode . replace ( / t y p e = \" [ ^ \" ] * \" / , `type="${ e . target . value } "` ) ) ;
80
+ if ( ! has_type ) {
81
+ type += ']' ;
82
+ }
83
+
84
+ $embedShortcodeEl . val ( shortcode . replace ( regex , type ) ) ;
74
85
} ) ;
75
86
76
87
$ ( '#has_embed_secret' ) . on ( 'change' , function ( ) {
77
- const $embedShortcodeEl = $ ( '#embed_code' ) ;
78
- const secret = $embedShortcodeEl . data ( 'secret' ) ;
79
88
let embedShortcode = $embedShortcodeEl . val ( ) ;
80
89
81
90
if ( ! embedShortcode ) {
82
91
return ;
83
92
}
84
93
85
94
if ( $ ( this ) . is ( ':checked' ) ) {
86
- embedShortcode = embedShortcode . replace ( / \ ]$ / , ` secret="${ secret } "]` ) ;
95
+ embedShortcode = embedShortcode . replace ( / ] $ / , ` secret="${ secret } "]` ) ;
87
96
} else {
88
97
embedShortcode = embedShortcode . replace ( / s e c r e t = " [ ^ " ] + " / , '' ) ;
89
98
}
90
99
91
100
$embedShortcodeEl . val ( embedShortcode ) ;
92
- } ) ;
93
- } ) ;
101
+ } ) ;
102
+ } ) ;
94
103
} ) ( jQuery ) ;
0 commit comments