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