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