PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 4.2
Shortcoder — Create Shortcodes for Anything v4.2
trunk 3.0 3.0.1 3.1 3.2 3.3 3.4 3.4.1 4.0 4.0.1 4.0.2 4.0.3 4.1 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2 4.3 4.4 4.5 4.6 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.1 5.2 5.2.1 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.4 5.5 5.6 5.7 5.8 6.0 6.1 6.2 6.3 6.3.1 6.3.2 6.4 6.5 6.5.1 6.5.2 6.5.3
shortcoder / admin / js / script.js
shortcoder / admin / js Last commit date
tinymce 7 years ago script-insert.js 7 years ago script.js 7 years ago
script.js
359 lines
1 (function($){
2 $(document).ready(function(){
3
4 var delete_ctext = 'Are you sure want to delete this shortcode ?';
5 var last_sort = 'desc';
6 var tags_filt_api = false;
7
8 var init = function(){
9 if(window.sc_cm_editor){
10 window.sc_cm = CodeMirror.fromTextArea( document.getElementById( 'sc_content' ), {
11 lineNumbers: true,
12 mode: "htmlmixed",
13 indentWithTabs: false,
14 lineWrapping: true,
15 styleActiveLine: true
16 });
17 sc_cm.setSize( null, 500 );
18 sc_cm.on( 'change', function(){
19 sc_cm.save();
20 });
21 }
22
23 if( $.fn.selectize ){
24
25 $('.sc_edit_tags').selectize({
26 create: true
27 });
28
29 if( $('.sc_tags_filter').length ){
30
31 $tags_filter_ele = $('.sc_tags_filter').selectize({
32 onChange: filter_list_tags
33 });
34
35 tags_filt_api = $tags_filter_ele[0].selectize;
36
37 }
38 }
39
40 var $sc_copy_field = $('.sc_copy_field');
41 if( $sc_copy_field.length ){
42 var sc_code = $sc_copy_field.val();
43 $sc_copy_field.width(sc_code.length * 6);
44 }
45
46 }
47
48 var sort = function( ele, orderby ){
49 var total = ele.length;
50 while( total ){
51 ele.each(function(){
52 var $cur = $(this);
53 var $next = $cur.next();
54 if( $next.length ){
55 var cur_name = $cur.attr( 'data-name' ).toLowerCase();
56 var nxt_name = $next.attr( 'data-name' ).toLowerCase();
57 if( ( orderby == 'asc' && cur_name > nxt_name ) || ( orderby == 'desc' && cur_name < nxt_name ) ){
58 $next.after( $cur );
59 }
60 }
61 });
62 total--;
63 }
64 }
65
66 var insert_in_editor = function( data ){
67 if( window.sc_cm_editor ){
68 var doc = window.sc_cm.getDoc();
69 doc.replaceRange( data, doc.getCursor() );
70 }else{
71 send_to_editor( data );
72 }
73 }
74
75 var filter_list_tags = function(){
76
77 var sel_tags = tags_filt_api.items;
78 var $sc_list = $( '.sc_list > li' );
79
80 if( sel_tags.length == 0){
81 $sc_list.show();
82 return true;
83 }
84
85 $sc_list.each(function(){
86 var $sc_item = $( this );
87 var sc_tags = $sc_item.attr( 'data-tags' );
88
89 if( typeof sc_tags === 'undefined' ){
90 $sc_item.hide();
91 return true;
92 }else{
93 $sc_item.show();
94 }
95
96 var sc_tags_split = sc_tags.split( ',' );
97 var has_tag = false;
98
99 $.each( sel_tags, function( i, tag ){
100 if( sc_tags_split.includes( tag ) ){
101 has_tag = true;
102 return true;
103 }
104 });
105
106 if( has_tag ){
107 $sc_item.show();
108 }else{
109 $sc_item.hide();
110 }
111
112 });
113 }
114
115 $( document ).on( 'click', '.sc_delete', function(e){
116
117 e.preventDefault();
118
119 var del_btn = $(this);
120 var href = del_btn.attr( 'href' );
121 var confirm_user = confirm( delete_ctext );
122
123 if( confirm_user ){
124
125 var ajax = $.get( href );
126 del_btn.addClass( 'spin' );
127
128 ajax.done(function( data ){
129 if( data.search( 'DELETED' ) != -1 ){
130 del_btn.closest( 'li' ).fadeOut( 'slow', function(){
131 $(this).remove();
132 });
133 }else{
134 alert( 'Delete failed ! - ' + data );
135 }
136 });
137
138 ajax.fail(function(){
139 alert( 'Auth failed !' );
140 });
141
142 }
143
144 });
145
146 $( document ).on( 'click', '.sc_delete_ep', function(e){
147
148 e.preventDefault();
149
150 var $delete_btn = $(this);
151 var href = $delete_btn.attr( 'href' );
152 var confirm_user = confirm( delete_ctext );
153
154 if( confirm_user ){
155
156 var ajax = $.get( href );
157 $delete_btn.addClass( 'spin' );
158
159 ajax.done(function( data ){
160 if( data.search( 'DELETED' ) != -1 ){
161 var back_href = $( '.sc_back_btn' ).attr( 'href' );
162 window.location = back_href + '&msg=3';
163 }else{
164 alert( 'Delete failed ! - ' + data );
165 }
166 });
167
168 ajax.fail(function(){
169 alert( 'Auth failed !' );
170 });
171
172 $delete_btn.removeClass( 'spin' );
173
174 }
175
176 });
177
178 $( document ).on( 'click', '.sc_copy', function(e){
179
180 e.preventDefault();
181
182 var btn = $(this);
183 var box = btn.closest( 'li' ).find( '.sc_copy_box' );
184
185 $( '.sc_copy_box' ).not( box ).hide();
186
187 box.fadeToggle();
188 box.select();
189
190 });
191
192 $(window).load(function(){
193
194 var insert_button = function(){
195 return '<button class="button button-primary sc_insert_params"><span class="dashicons dashicons-plus"></span> Insert shortcode paramerters <span class="dashicons dashicons-arrow-down"></span></button>';
196 }
197
198 $( '.wp-media-buttons' ).append( insert_button );
199 $( '.sc_editor_list' ).appendTo( '.wp-media-buttons' );
200
201 if( window.sc_cm_editor ){
202 $( '.sc_cm_menu' ).append( insert_button );
203 $( '.sc_editor_list' ).appendTo( '.sc_cm_menu' );
204 }
205
206 $( '.params_wrap' ).appendTo( 'body' );
207
208 });
209
210 $( document ).on( 'click', '.sc_insert_params', function(e){
211
212 e.preventDefault();
213
214 var offset = $(this).offset();
215 var mtop = offset.top + $(this).outerHeight();
216
217 $( '.params_wrap' ).css({
218 top: mtop,
219 left: offset.left
220 }).toggle();
221 });
222
223 $( document ).on( 'click', '.sc_tags_filt_icon', function(e){
224
225 e.preventDefault();
226 $( this ).closest( '.sc_tags_filt_btn' ).toggleClass( 'active' );
227
228 });
229
230 $( document ).on( 'click', '.sc_tags_list li', function(e){
231
232 if(tags_filt_api){
233 var tag = $(this).attr( 'data-tag-id' );
234 tags_filt_api.addItem( tag );
235 $( '.sc_tags_filt_btn' ).addClass( 'active' );
236 }
237
238 });
239
240 $( document ).on( 'click', '.sc_copy_field', function(e){
241 e.preventDefault();
242 $(this).select();
243 });
244
245 $( document ).on( 'click', '.cp_btn', function(){
246
247 var $cp_box = $( '.cp_box' );
248 var $cp_info = $( '.cp_info' );
249 var param_val = $cp_box.val().trim();
250
251 if( param_val != '' && $cp_box[0].checkValidity() ){
252 insert_in_editor( '%%' + param_val + '%%' );
253 $cp_info.removeClass( 'red' );
254 $( '.params_wrap' ).hide();
255 }else{
256 $cp_info.addClass( 'red' );
257 }
258
259 });
260
261 $( document ).on( 'click', '.cf_btn', function(){
262
263 var $cf_box = $( '.cf_box' );
264 var $cf_info = $( '.cf_info' );
265 var param_val = $cf_box.val().trim();
266
267 if( param_val != '' && $cf_box[0].checkValidity() ){
268 insert_in_editor( '$$custom_field:' + param_val + '$$' );
269 $cf_info.removeClass( 'red' );
270 $( '.params_wrap' ).hide();
271 }else{
272 $cf_info.addClass( 'red' );
273 }
274
275 });
276
277 $( document ).on( 'click', '.wp_params li', function(){
278 insert_in_editor('$$' + $(this).data( 'id' ) + '$$');
279 $( '.params_wrap' ).hide();
280 });
281
282 $( document ).on( 'change', '.coffee_amt', function(){
283 var btn = $( '.buy_coffee_btn' );
284 btn.attr( 'href', btn.data( 'link' ) + $(this).val() );
285 });
286
287 $( document ).on( 'click', '.sort_btn', function(){
288 last_sort = ( last_sort == 'asc' ) ? 'desc' : 'asc';
289 sort( $( '.sc_list > li' ), last_sort );
290 $( '.sort_icon' ).toggleClass( 'dashicons-arrow-down-alt' );
291 $( '.sort_icon' ).toggleClass( 'dashicons-arrow-up-alt' );
292 });
293
294 $( document ).on( 'change', '#import', function(){
295 if( !confirm( $( '.import_desc' ).text() ) ){
296 return false;
297 }
298
299 if( confirm( $( '.import_desc2' ).text() ) ){
300 $( '#fresh_import' ).prop( 'checked', true );
301 }else{
302 $( '#fresh_import' ).prop( 'checked', false );
303 }
304
305 $( '#import_form' ).submit();
306 });
307
308 $( document ).on( 'change', '.sc_editor', function(e){
309 window.location = window.location + '&editor=' + $(this).val();
310 });
311
312 $( document ).on( 'click', '.search_btn', function(e){
313 var $search_box = $(this).find('.search_box');
314 if(e.target === $search_box[0]){
315 return false;
316 }
317 $(this).toggleClass('active');
318 $search_box.focus();
319
320 });
321
322 $( document ).on( 'keyup', '.search_box', function(){
323 var search_term = $(this).val();
324 var re = new RegExp(search_term, 'gi');
325 $('.sc_list > li').each(function(){
326 var name = $(this).attr('data-name');
327 if(name.match(re) === null){
328 $(this).hide();
329 }else{
330 $(this).show();
331 }
332 });
333
334 if(search_term){
335 $(this).parent().addClass('filtered');
336 }else{
337 $(this).parent().removeClass('filtered');
338 }
339
340 var visible = $('.sc_list > li:visible').length;
341 var $no_scs_msg = $('.sc_list').find('p');
342 if( visible == 0 ){
343 if( $no_scs_msg.length == 0 ){
344 $('.sc_list').append( '<p align="center" class="search_empty_msg"><i>No shortcodes match search term !</i></p>' );
345 }
346 }else{
347 $no_scs_msg.remove();
348 }
349
350 });
351
352 $( document ).on( 'click', '.sc_note_btn', function(e){
353 $('.sc_note').slideToggle();
354 });
355
356 init();
357
358 });
359 })( jQuery );