PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.6
Shortcoder — Create Shortcodes for Anything v5.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-insert.js
shortcoder / admin / js Last commit date
blocks 4 years ago tinymce 4 years ago script-insert.js 4 years ago script-settings.js 4 years ago script-tools.js 4 years ago script.js 4 years ago
script-insert.js
195 lines
1 (function($){
2 $(document).ready(function(){
3
4 var send_editor = function(content){
5
6 if(typeof parent.sc_block_editor_content === 'function'){
7 if(parent.sc_block_editor_content(content)){
8 return true;
9 }
10 }
11
12 if(typeof parent.sc_block_inline_insert === 'function'){
13 if(parent.sc_block_inline_insert(content)){
14 return true;
15 }
16 }
17
18 if(typeof parent.send_to_editor === 'function'){
19 parent.send_to_editor(content);
20 }else{
21 alert('Editor does not exist. Cannot insert shortcode !');
22 }
23
24 }
25
26 var close_window = function(){
27 if( typeof parent.sc_close_insert === 'function' ){
28 parent.sc_close_insert();
29 }
30 }
31
32 var copy_to_clipboard = function(str){
33 var el = document.createElement('textarea');
34 el.value = str;
35 el.setAttribute('readonly', '');
36 el.style.position = 'absolute';
37 el.style.left = '-9999px';
38 document.body.appendChild(el);
39 el.select();
40 document.execCommand('copy');
41 document.body.removeChild(el);
42 };
43
44 var generate_sc = function(id){
45 var $wrap = $('.sc_wrap[data-id="' + id + '"]');
46 var name = $wrap.attr('data-name');
47 var enclosed = $wrap.attr('data-enclosed');
48 var params = '';
49
50 $wrap.find('.sc_param').each(function(){
51 if($(this).val() != ''){
52 attr = $(this).attr('data-param');
53 val = $(this).val().replace( /\"/g, '' );
54 params += attr + '="' + val + '" ';
55 }
56 });
57
58 sc = '[sc name="' + name + '" ' + params + ']';
59 sc += '[/sc]';
60
61 return sc;
62
63 }
64
65 var set_shortcode = function(shortcode){
66
67 var re_attrs_text = /\[sc ([^\]]*)+\]/g;
68 var re_attrs = /(\w+?)="(.+?)"/g;
69
70 var attributes_text_matches = re_attrs_text.exec(shortcode);
71
72 if(attributes_text_matches.length < 1){
73 return false;
74 }
75
76 var attributes_text = attributes_text_matches[1];
77 var attributes = {};
78
79 while(true){
80 var attributes_matches = re_attrs.exec(attributes_text);
81
82 if(attributes_matches !== null){
83 var name = attributes_matches[1];
84 var val = attributes_matches[2];
85 attributes[name] = val;
86 }else{
87 break;
88 }
89 }
90
91 if(!('name' in attributes)){
92 return false;
93 }
94
95 var sc_name = attributes['name'];
96 var $sc_wrap = $('.sc_wrap[data-name="' + sc_name + '"]');
97
98 if($sc_wrap.length == 0){
99 return false;
100 }
101
102 var $sc_options = $sc_wrap.find('.sc_options');
103 var $sc_head = $sc_wrap.find('.sc_head');
104
105 delete attributes['name'];
106
107 for (var attribute in attributes) {
108 if (attributes.hasOwnProperty(attribute)) {
109 var attr_val = attributes[attribute];
110 $sc_options.find('input[data-param="' + attribute + '"]').val(attr_val);
111 }
112 }
113
114 if(!$sc_wrap.hasClass('open')){
115 $sc_head.trigger('click');
116 }
117
118 $sc_wrap[0].scrollIntoView();
119
120 }
121
122 $('.sc_insert').on('click', function(){
123 var sc_id = $(this).closest('.sc_wrap').attr('data-id');
124 var sc = generate_sc(sc_id);
125
126 send_editor(sc);
127 close_window();
128 });
129
130 $('.sc_copy').on('click', function(){
131 var sc_id = $(this).closest('.sc_wrap').attr('data-id');
132 var sc = generate_sc(sc_id);
133
134 copy_to_clipboard(sc);
135 close_window();
136 });
137
138 $('.sc_head').on('click', function(){
139 $('.sc_options').slideUp();
140 $('.sc_wrap').removeClass('open');
141 if($(this).next('.sc_options').is(':visible')){
142 $(this).next().slideUp();
143 }else{
144 $(this).next().slideDown();
145 $(this).closest('.sc_wrap').addClass('open');
146 }
147 });
148
149 $('.sc_search').on('keyup search', function(){
150
151 var re = new RegExp($(this).val(), 'gi');
152
153 $('.sc_wrap').each(function(){
154 var name = $(this).find('.sc_head h3').text();
155 if(name.match(re) === null){
156 $(this).hide();
157 }else{
158 $(this).show();
159 }
160 });
161
162 var $no_scs_msg = $('.sc_search_none');
163 var visible = $('.sc_wrap:visible').length;
164
165 if( visible == 0 ){
166 $no_scs_msg.show();
167 }else{
168 $no_scs_msg.hide();
169 }
170
171 });
172
173 $('.cfe_amt').on('click', function(){
174 var $btn = $(this).closest('.cfe_form').find('.cfe_btn');
175 $btn.attr('href', $btn.data('link') + $(this).val());
176 });
177
178 $('.note').on('click', function(){
179 $(this).find('table').slideToggle();
180 });
181
182 window.addEventListener('message', function(e){
183 var key = e.message ? 'message' : 'data';
184 var data = e[key];
185
186 if(data == false){
187 return true;
188 }
189
190 set_shortcode(data);
191
192 }, false);
193
194 });
195 })( jQuery );