PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 6.3.1
Shortcoder — Create Shortcodes for Anything v6.3.1
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 2 years ago tinymce 2 years ago script-insert.js 2 years ago script-settings.js 2 years ago script-tools.js 2 years ago script.js 2 years ago
script.js
300 lines
1 (function($){
2 $(document).ready(function(){
3
4 var init = function(){
5
6 if(typeof window.SC_EDITOR !== 'undefined' && typeof window.SC_EDITOR.active !== 'undefined' && window.SC_EDITOR.active == 'code'){
7
8 var codemirror_loaded = load_codemirror();
9
10 if(!codemirror_loaded){
11 $('.sc_editor_toolbar').append('<p>Unable to load code editor. Please check browser console (press Ctrl+Shift+J) for errors or try deactivating any code editor related plugin/themes.</p>');
12 }
13
14 $('.sc_editor_toolbar').appendTo('.sc_cm_menu');
15
16 }else{
17 $('.sc_editor_toolbar').appendTo('.wp-media-buttons');
18 }
19
20 if(typeof window.SC_VARS !== 'undefined'){
21
22 if(SC_VARS['screen']['base'] == 'edit'){
23 var version = '<small>v' + SC_VARS['sc_version'] + '</small>';
24 $('.wp-heading-inline').append(version);
25 add_top_import_export_btn();
26 }
27
28 add_top_pro_btn();
29 }
30
31 $('.sc_params_list').appendTo('body');
32
33 }
34
35 var set_sc_preview_text = function(name){
36 $('.sc_preview_text').text('[sc name="' + name + '"][/sc]');
37 }
38
39 var insert_in_editor = function(data){
40 if(window.SC_EDITOR.active == 'code'){
41 var doc = window.sc_cm.getDoc();
42 doc.replaceRange(data, doc.getCursor());
43 }else{
44 send_to_editor(data);
45 }
46 }
47
48 var copy_to_clipboard = function(str){
49 var el = document.createElement('textarea');
50 el.value = str;
51 el.setAttribute('readonly', '');
52 el.style.position = 'absolute';
53 el.style.left = '-9999px';
54 document.body.appendChild(el);
55 el.select();
56 document.execCommand('copy');
57 document.body.removeChild(el);
58 };
59
60 var load_codemirror = function(){
61
62 if(typeof window.SC_CODEMIRROR === 'undefined'){
63 console.error('Shortcoder: Codemirror settings are not loaded');
64 return false;
65 }
66
67 if(typeof window.wp === 'undefined' || typeof window.wp.codeEditor === 'undefined'){
68 console.error('Shortcoder: codeEditor namespace is not available');
69 return false;
70 }
71
72 var sc_mode_loaded = load_cm_sc_mode();
73 var mode = sc_mode_loaded ? 'sc_mode' : 'htmlmixed';
74
75 wp.codeEditor.defaultSettings.codemirror['mode'] = mode;
76
77 var editor = wp.codeEditor.initialize(document.getElementById('sc_content'), window.SC_CODEMIRROR);
78
79 editor.codemirror.setSize( null, 500 );
80 editor.codemirror.on('change', function(){
81 editor.codemirror.save();
82 });
83
84 window.sc_cm = editor.codemirror;
85
86 return true;
87
88 }
89
90 var load_cm_sc_mode = function(){
91
92 if(typeof wp.CodeMirror === 'undefined'){
93 console.error('Shortcoder: CodeMirror library is not loaded/available');
94 return false;
95 }
96
97 if(typeof wp.CodeMirror.overlayMode === 'undefined'){
98 console.error('Shortcoder: CodeMirror overlay method is not available');
99 return false;
100 }
101
102 try{
103 wp.CodeMirror.defineMode('sc_mode', function(config, parserConfig){
104 var sc_overlay = {
105 token: function(stream, state){
106 if(stream.match(/\$\$[a-z0-9A-Z:_ \-]+\$\$/)){
107 return 'number sc_param';
108 }
109 if(stream.match(/%%.*?%%/)){
110 return 'atom sc_param';
111 }
112 if(stream.match(/\[(.+?)?\](?:(.+?)?\[\/\])?/)){
113 return 'string sc_param';
114 }
115 stream.next();
116 }
117 };
118 return wp.CodeMirror.overlayMode(wp.CodeMirror.getMode(config, parserConfig.backdrop || 'htmlmixed'), sc_overlay);
119 });
120 }catch(error){
121 console.error('Shortcoder: Unable to load shortcoder mode.', error);
122 return false;
123 }
124
125 return true;
126
127 }
128
129 var close_params_list = function(){
130 $('.sc_params_list').hide();
131 }
132
133 var add_top_pro_btn = function(){
134
135 $('#screen-meta-links').prepend('<div class="screen-meta-toggle pro_top_link"><a class="show-settings button" href="https://www.aakashweb.com/wordpress-plugins/shortcoder/?utm_source=admin&utm_medium=top&utm_campaign=sc-pro#pro" target="_blank">Upgrade to PRO <span class="dashicons dashicons-plus"></span></a></div>');
136
137 }
138
139 var add_top_import_export_btn = function(){
140
141 $('#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>');
142
143 $('#screen-meta').append('<div id="import-export-tab" class="hidden"></div>');
144
145 $('#ie_content > div').appendTo('#import-export-tab');
146
147 }
148
149 $('#post_name').on('change keyup', function(){
150 set_sc_preview_text($(this).val());
151 });
152
153 $('.sc_editor').on('focus', function(){
154 window.sc_old_editor = $(this).val();
155 }).on('change', function(e){
156
157 new_editor = $(this).val();
158 response = confirm(SC_VARS.text_editor_switch_notice);
159
160 if(!response){
161 e.preventDefault();
162 $(this).val(window.sc_old_editor);
163 return false;
164 }
165
166 window.location = window.location + '&editor=' + $(this).val();
167
168 });
169
170 $('.sc_insert_param').on('click', function(e){
171
172 e.preventDefault();
173
174 var offset = $(this).offset();
175 var mtop = offset.top + $(this).outerHeight();
176
177 $('.sc_params_list').css({
178 top: mtop,
179 left: offset.left
180 }).toggle();
181
182 });
183
184 $('.sc_wp_params li').on('click', function(){
185 insert_in_editor('$$' + $(this).data('id') + '$$');
186 close_params_list();
187 });
188
189 $('.sc_cp_btn').on('click', function(){
190
191 var $cp_box = $('.sc_cp_box');
192 var $cp_default = $('.sc_cp_default');
193 var $cp_info = $('.sc_cp_info');
194 var param_val = $cp_box.val().trim();
195 var default_val = $cp_default.val().trim();
196
197 if( param_val != '' && $cp_box[0].checkValidity() ){
198
199 var the_code = '';
200 if(default_val == ''){
201 the_code = '%%' + param_val + '%%';
202 }else{
203 the_code = '%%' + param_val + ':' + default_val + '%%';
204 }
205
206 insert_in_editor(the_code);
207 $cp_info.removeClass('red');
208 close_params_list();
209 }else{
210 $cp_info.addClass('red');
211 }
212
213 });
214
215 $('.sc_cf_btn').on('click', function(){
216
217 var $cf_box = $('.sc_cf_box');
218 var $cf_info = $('.sc_cf_info');
219 var default_val = $('.sc_cf_default').val().trim();
220 var param_val = $cf_box.val().trim();
221
222 if(default_val != ''){
223 default_val = ':' + default_val;
224 }
225
226 if( param_val != '' && $cf_box[0].checkValidity() ){
227 insert_in_editor('$$custom_field:' + param_val + default_val + '$$');
228 $cf_info.removeClass('red');
229 close_params_list();
230 }else{
231 $cf_info.addClass('red');
232 }
233
234 });
235
236 $('.sc_copy').on('click', function(){
237 copy_to_clipboard($('.sc_preview_text').text());
238 $this = $(this);
239 $this.addClass('copied');
240 setTimeout(function() {
241 $this.removeClass('copied');
242 }, 3000);
243 })
244
245 $('.sc_copy_list').on('click', function(e){
246 e.preventDefault();
247 var $copy_field = $(this).siblings('.sc_copy_text');
248 copy_to_clipboard($copy_field.val());
249 $copy_field.addClass('copied');
250 setTimeout(function() {
251 $copy_field.removeClass('copied');
252 }, 3000);
253 });
254
255 $('.sc_changelog .dismiss_btn').on('click', function(){
256 var url = SC_VARS.ajax_url + '?action=sc_admin_ajax&do=close_changelog&_wpnonce=' + SC_VARS.nonce;
257 $.get(url, function( data ){
258 if(data.search( /done/g ) == -1){
259 $( '.sc_changelog article' ).html('Failed to close window. <a href="' + url + '" target="_blank">Please click here to close</a>');
260 }else{
261 $( '.sc_changelog' ).fadeOut();
262 }
263 });
264 });
265
266 $('.sc_settings_link').on('click', function(e){
267 e.preventDefault();
268 $('html').animate({
269 scrollTop: $("#sc_mb_settings").offset().top
270 }, 1000, function(){
271 $('input[name="post_title"]').focus();
272 });
273 });
274
275 $('.cfe_amt').on('click', function(){
276 var $btn = $(this).closest('.cfe_form').find('.cfe_btn');
277 $btn.attr('href', $btn.data('link') + $(this).val());
278 });
279
280 $('.subscribe_btn').click(function(e){
281 e.preventDefault();
282 var action = $(this).parent().data('action');
283 $.ajax({
284 type: 'get',
285 url: action,
286 cache: false,
287 dataType: 'jsonp',
288 data: {
289 'EMAIL': $('.subscribe_email_box').val()
290 },
291 success : function(data) {
292 }
293 });
294 $('.subscribe_confirm').show();
295 });
296
297 init();
298
299 });
300 })( jQuery );