PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.3.4
Shortcoder — Create Shortcodes for Anything v5.3.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.js
shortcoder / admin / js Last commit date
blocks 5 years ago tinymce 5 years ago script-insert.js 5 years ago script-tools.js 5 years ago script.js 5 years ago
script.js
253 lines
1 (function($){
2 $(document).ready(function(){
3
4 var init = function(){
5
6 if(window.SC_EDITOR == 'code'){
7
8 if(typeof window.CodeMirror === 'function' && typeof CodeMirror.fromTextArea === 'function'){
9 load_cm_sc_mode();
10
11 window.sc_cm = CodeMirror.fromTextArea(document.getElementById('sc_content'), {
12 lineNumbers: true,
13 mode: 'sc_mode',
14 indentWithTabs: false,
15 lineWrapping: true,
16 styleActiveLine: true,
17 htmlMode: true
18 });
19 sc_cm.setSize( null, 500 );
20 sc_cm.on('change', function(){
21 sc_cm.save();
22 });
23 }else{
24 $('.sc_editor_toolbar').append('<p>Unable to load code editor. Please check console for errors or try deactivating other plugin/themes.</p>');
25 }
26
27 $('.sc_editor_toolbar').appendTo('.sc_cm_menu');
28
29 }else{
30 $('.sc_editor_toolbar').appendTo('.wp-media-buttons');
31 }
32
33 if(typeof window.SC_VARS !== 'undefined'){
34
35 if(SC_VARS['screen']['base'] == 'edit'){
36 var version = '<small>v' + SC_VARS['sc_version'] + '</small>';
37 $('.wp-heading-inline').append(version);
38 add_top_import_export_btn();
39 }
40
41 if(SC_VARS['screen']['base'] == 'post'){
42 var $cfe_button = $('.cfe_bottom');
43 if($cfe_button.length > 0){
44 $cfe_button.appendTo('#normal-sortables');
45 }
46 }
47
48 add_top_coffee_btn();
49 }
50
51 $('.sc_params_list').appendTo('body');
52
53 }
54
55 var set_sc_preview_text = function(name){
56 $('.sc_preview_text').text('[sc name="' + name + '"]');
57 }
58
59 var insert_in_editor = function(data){
60 console.log(data);
61 if(window.SC_EDITOR == 'code'){
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 copy_to_clipboard = function(str){
70 var el = document.createElement('textarea');
71 el.value = str;
72 el.setAttribute('readonly', '');
73 el.style.position = 'absolute';
74 el.style.left = '-9999px';
75 document.body.appendChild(el);
76 el.select();
77 document.execCommand('copy');
78 document.body.removeChild(el);
79 };
80
81 var load_cm_sc_mode = function(){
82
83 if(typeof CodeMirror.overlayMode === 'undefined'){
84 return false;
85 }
86
87 CodeMirror.defineMode('sc_mode', function(config, parserConfig){
88 var mustacheOverlay = {
89 token: function(stream, state){
90 if(stream.match(/\$\$[a-z0-9A-Z:_]+\$\$/)){
91 return 'number sc_param';
92 }
93 if(stream.match(/%%.*?%%/)){
94 return 'atom sc_param';
95 }
96 if(stream.match(/\[(.+?)?\](?:(.+?)?\[\/\])?/)){
97 return 'string sc_param';
98 }
99 stream.next();
100 }
101 };
102 return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || 'htmlmixed'), mustacheOverlay);
103 });
104 }
105
106 var close_params_list = function(){
107 $('.sc_params_list').hide();
108 }
109
110 var add_top_coffee_btn = function(){
111
112 $('#screen-meta-links').prepend('<div class="screen-meta-toggle cfe_top_link"><a class="show-settings button" href="https://www.paypal.me/vaakash/" target="_blank">Buy me a Coffee</a></div>');
113
114 }
115
116 var add_top_import_export_btn = function(){
117
118 $('#screen-meta-links').prepend('<div class="screen-meta-toggle ie_top_link hide-if-no-js"><button aria-controls="import-export-tab" aria-expanded="false" class="show-settings button">Import / Export</button></div>');
119
120 $('#screen-meta').append('<div id="import-export-tab" class="hidden"></div>');
121
122 $('#ie_content > div').appendTo('#import-export-tab');
123
124 }
125
126 $('#post_name').on('change keyup', function(){
127 set_sc_preview_text($(this).val());
128 });
129
130 $('.sc_editor').on('focus', function(){
131 window.sc_old_editor = $(this).val();
132 }).on('change', function(e){
133
134 new_editor = $(this).val();
135 response = confirm(SC_VARS.text_editor_switch_notice);
136
137 if(!response){
138 e.preventDefault();
139 $(this).val(window.sc_old_editor);
140 return false;
141 }
142
143 window.location = window.location + '&editor=' + $(this).val();
144
145 });
146
147 $('.sc_insert_param').on('click', function(e){
148
149 e.preventDefault();
150
151 var offset = $(this).offset();
152 var mtop = offset.top + $(this).outerHeight();
153
154 $('.sc_params_list').css({
155 top: mtop,
156 left: offset.left
157 }).toggle();
158
159 });
160
161 $('.sc_wp_params li').on('click', function(){
162 insert_in_editor('$$' + $(this).data('id') + '$$');
163 close_params_list();
164 });
165
166 $('.sc_cp_btn').on('click', function(){
167
168 var $cp_box = $('.sc_cp_box');
169 var $cp_default = $('.sc_cp_default');
170 var $cp_info = $('.sc_cp_info');
171 var param_val = $cp_box.val().trim();
172 var default_val = $cp_default.val().trim();
173
174 if( param_val != '' && $cp_box[0].checkValidity() ){
175
176 var the_code = '';
177 if(default_val == ''){
178 the_code = '%%' + param_val + '%%';
179 }else{
180 the_code = '%%' + param_val + ':' + default_val + '%%';
181 }
182
183 insert_in_editor(the_code);
184 $cp_info.removeClass('red');
185 close_params_list();
186 }else{
187 $cp_info.addClass('red');
188 }
189
190 });
191
192 $('.sc_cf_btn').on('click', function(){
193
194 var $cf_box = $('.sc_cf_box');
195 var $cf_info = $('.sc_cf_info');
196 var param_val = $cf_box.val().trim();
197
198 if( param_val != '' && $cf_box[0].checkValidity() ){
199 insert_in_editor('$$custom_field:' + param_val + '$$');
200 $cf_info.removeClass('red');
201 close_params_list();
202 }else{
203 $cf_info.addClass('red');
204 }
205
206 });
207
208 $('.sc_copy').on('click', function(){
209 copy_to_clipboard($('.sc_preview_text').text());
210 $this = $(this);
211 $this.addClass('copied');
212 setTimeout(function() {
213 $this.removeClass('copied');
214 }, 3000);
215 })
216
217 $('.sc_changelog .dismiss_btn').on('click', function(){
218 var url = SC_VARS.ajax_url + '?action=sc_admin_ajax&do=close_changelog';
219 $.get(url, function( data ){
220 if(data.search( /done/g ) == -1){
221 $( '.sc_changelog article' ).html('Failed to close window. <a href="' + url + '" target="_blank">Please click here to close</a>');
222 }else{
223 $( '.sc_changelog' ).fadeOut();
224 }
225 });
226 });
227
228 $('.cfe_amt').on('click', function(){
229 var $btn = $(this).closest('.cfe_form').find('.cfe_btn');
230 $btn.attr('href', $btn.data('link') + $(this).val());
231 });
232
233 $('.subscribe_btn').click(function(e){
234 e.preventDefault();
235 var action = $(this).parent().data('action');
236 $.ajax({
237 type: 'get',
238 url: action,
239 cache: false,
240 dataType: 'jsonp',
241 data: {
242 'EMAIL': $('.subscribe_email_box').val()
243 },
244 success : function(data) {
245 }
246 });
247 $('.subscribe_confirm').show();
248 });
249
250 init();
251
252 });
253 })( jQuery );