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