PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 4.4
Shortcoder — Create Shortcodes for Anything v4.4
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-insert.js
shortcoder / admin / js Last commit date
tinymce 7 years ago script-insert.js 7 years ago script.js 7 years ago
script-insert.js
160 lines
1 (function($){
2
3 $(document).ready(function(){
4
5 var last_sort = 'desc';
6
7 var send_editor = function( content ){
8 if( typeof parent.send_to_editor === 'function' ){
9 parent.send_to_editor( content );
10 }else{
11 alert( 'Editor does not exist. Cannot insert shortcode !' );
12 }
13 }
14
15 var close_window = function(){
16 if( typeof parent.tb_remove === 'function' ){
17 parent.tb_remove();
18 }
19 }
20
21 var sort = function( ele, orderby ){
22 var total = ele.length;
23 while( total ){
24 ele.each(function(){
25 var $cur = $(this);
26 var $next = $cur.next();
27 if( $next.length ){
28 var cur_name = $cur.attr( 'data-name' ).toLowerCase();
29 var nxt_name = $next.attr( 'data-name' ).toLowerCase();
30 if( ( orderby == 'asc' && cur_name > nxt_name ) || ( orderby == 'desc' && cur_name < nxt_name ) ){
31 $next.after( $cur );
32 }
33 }
34 });
35 total--;
36 }
37 }
38
39 $('.sc_shortcode_name').append('<span class="sc_toggle"></span>');
40
41 $( document ).on( 'click', '.sc_insert', function(){
42
43 var params = '';
44 var scname = $(this).closest( '.sc_shortcode' ).attr( 'data-name' );
45 var sc = '';
46
47 $(this).parent().children().find('input[type="text"]').each(function(){
48 if($(this).val() != ''){
49 attr = $(this).attr('data-param');
50 val = $(this).val().replace( /\"/g, '' );
51 params += attr + '="' + val + '" ';
52 }
53 });
54
55 sc = '[sc name="' + scname + '" ' + params + ']';
56
57 if( $(this).hasClass( 'has_enclosed_sc' ) ){
58 sc += '[/sc]';
59 }
60
61 send_editor( sc );
62 close_window();
63
64 });
65
66 $( document ).on( 'click', '.sc_quick_insert', function(){
67
68 var scname = $(this).closest( '.sc_shortcode' ).attr( 'data-name' );
69 var sc = '[sc name="' + scname + '"]';
70
71 send_editor( sc );
72 close_window();
73
74 });
75
76 $( document ).on( 'click', '.sc_shortcode_name', function(e){
77 $('.sc_params').slideUp();
78 if($(this).next('.sc_params').is(':visible')){
79 $(this).next('.sc_params').slideUp();
80 }else{
81 $(this).next('.sc_params').slideDown();
82 }
83 });
84
85 $( document ).on( 'change', '.coffee_amt', function(){
86 var btn = $( '.buy_coffee_btn' );
87 btn.attr( 'href', btn.data( 'link' ) + $(this).val() );
88 });
89
90 $( document ).on( 'click', '.sort_btn', function(){
91 last_sort = ( last_sort == 'asc' ) ? 'desc' : 'asc';
92 sort( $( '.sc_shortcode' ), last_sort );
93 });
94
95 $( document ).on( 'keyup', '.search_box', function(){
96 var re = new RegExp($(this).val(), 'gi');
97 $('.sc_wrap .sc_shortcode').each(function(){
98 var name = $(this).attr('data-name');
99 if( name.match(re) === null ){
100 $(this).hide();
101 }else{
102 $(this).show();
103 }
104 });
105
106 var visible = $('.sc_wrap .sc_shortcode:visible').length;
107 var $no_scs_msg = $('.sc_wrap').find('p');
108 if( visible == 0 ){
109 if( $no_scs_msg.length == 0 ){
110 $('.sc_wrap').append( '<p align="center"><i>No shortcodes match search term !</i></p>' );
111 }
112 }else{
113 $no_scs_msg.remove();
114 }
115 });
116
117 $( document ).on( 'click', '.tags_filter_btn', function(){
118 $( '.sc_tags' ).slideToggle();
119 });
120
121 $( document ).on( 'click', '.sc_tags li', function(){
122
123 $(this).toggleClass( 'active' );
124 var tags_sel = [];
125
126 $('.sc_tags li.active').each(function(){
127 var tag = $(this).attr('data-value');
128 tags_sel.push(tag);
129 });
130
131 if(tags_sel.length == 0){
132 $('.sc_wrap .sc_shortcode').show();
133 return true;
134 }
135
136 $('.sc_wrap .sc_shortcode').each(function(){
137 var tags = $(this).attr('data-tags');
138 var tags_split = $.map(tags.split(','), $.trim);
139 var has_tag = false;
140
141 $.each(tags_sel, function(i, tag){
142 if(tags_split.includes(tag)){
143 has_tag = true;
144 return true;
145 }
146 });
147
148 if(has_tag){
149 $(this).show();
150 }else{
151 $(this).hide();
152 }
153
154 });
155
156 });
157
158 });
159
160 })( jQuery );