PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.0.2
Shortcoder — Create Shortcodes for Anything v5.0.2
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 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.js
200 lines
1 (function($){
2 $(document).ready(function(){
3
4 var init = function(){
5
6 if(window.SC_EDITOR == 'code'){
7
8 load_cm_sc_mode();
9
10 window.sc_cm = CodeMirror.fromTextArea(document.getElementById('content'), {
11 lineNumbers: true,
12 mode: 'sc_mode',
13 indentWithTabs: false,
14 lineWrapping: true,
15 styleActiveLine: true,
16 htmlMode: true
17 });
18 sc_cm.setSize( null, 500 );
19 sc_cm.on('change', function(){
20 sc_cm.save();
21 });
22
23 $('.sc_editor_toolbar').appendTo('.sc_cm_menu');
24
25 }else{
26 $('.sc_editor_toolbar').appendTo('.wp-media-buttons');
27 }
28
29 if(typeof window.SC_VARS !== 'undefined'){
30 if(SC_VARS['screen']['base'] == 'edit'){
31
32 var version = '<small>v' + SC_VARS['sc_version'] + '</small>';
33 $('.wp-heading-inline').append(version);
34
35 add_top_coffee_btn();
36
37 }
38 }
39
40 $('.sc_params_list').appendTo('body');
41
42 }
43
44 var set_sc_preview_text = function(name){
45 $('.sc_preview_text').text('[sc name="' + name + '"]');
46 }
47
48 var insert_in_editor = function(data){
49 console.log(data);
50 if(window.SC_EDITOR == 'code'){
51 var doc = window.sc_cm.getDoc();
52 doc.replaceRange(data, doc.getCursor());
53 }else{
54 send_to_editor(data);
55 }
56 }
57
58 var copy_to_clipboard = function(str){
59 var el = document.createElement('textarea');
60 el.value = str;
61 el.setAttribute('readonly', '');
62 el.style.position = 'absolute';
63 el.style.left = '-9999px';
64 document.body.appendChild(el);
65 el.select();
66 document.execCommand('copy');
67 document.body.removeChild(el);
68 };
69
70 var load_cm_sc_mode = function(){
71
72 if(typeof CodeMirror.overlayMode === 'undefined'){
73 return false;
74 }
75
76 CodeMirror.defineMode('sc_mode', function(config, parserConfig){
77 var mustacheOverlay = {
78 token: function(stream, state){
79 if(stream.match(/\$\$[a-z0-9A-Z:_]+\$\$/)){
80 return 'number sc_param';
81 }
82 if(stream.match(/%%[a-z0-9A-Z_]+%%/)){
83 return 'atom sc_param';
84 }
85 stream.next();
86 }
87 };
88 return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || 'htmlmixed'), mustacheOverlay);
89 });
90 }
91
92 var close_params_list = function(){
93 $('.sc_params_list').hide();
94 }
95
96 var add_top_coffee_btn = function(){
97 $('#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>');
98 }
99
100 $('#post_name').on('change keyup', function(){
101 set_sc_preview_text($(this).val());
102 });
103
104 $('.sc_editor').on('focus', function(){
105 window.sc_old_editor = $(this).val();
106 }).on('change', function(e){
107
108 new_editor = $(this).val();
109 response = confirm(SC_VARS.text_editor_switch_notice);
110
111 if(!response){
112 e.preventDefault();
113 $(this).val(window.sc_old_editor);
114 return false;
115 }
116
117 window.location = window.location + '&editor=' + $(this).val();
118
119 });
120
121 $('.sc_insert_param').on('click', function(e){
122
123 e.preventDefault();
124
125 var offset = $(this).offset();
126 var mtop = offset.top + $(this).outerHeight();
127
128 $('.sc_params_list').css({
129 top: mtop,
130 left: offset.left
131 }).toggle();
132
133 });
134
135 $('.sc_wp_params li').on('click', function(){
136 insert_in_editor('$$' + $(this).data('id') + '$$');
137 close_params_list();
138 });
139
140 $('.sc_cp_btn').on('click', function(){
141
142 var $cp_box = $('.sc_cp_box');
143 var $cp_info = $('.sc_cp_info');
144 var param_val = $cp_box.val().trim();
145
146 if( param_val != '' && $cp_box[0].checkValidity() ){
147 insert_in_editor('%%' + param_val + '%%');
148 $cp_info.removeClass('red');
149 close_params_list();
150 }else{
151 $cp_info.addClass('red');
152 }
153
154 });
155
156 $('.sc_cf_btn').on('click', function(){
157
158 var $cf_box = $('.sc_cf_box');
159 var $cf_info = $('.sc_cf_info');
160 var param_val = $cf_box.val().trim();
161
162 if( param_val != '' && $cf_box[0].checkValidity() ){
163 insert_in_editor('$$custom_field:' + param_val + '$$');
164 $cf_info.removeClass('red');
165 close_params_list();
166 }else{
167 $cf_info.addClass('red');
168 }
169
170 });
171
172 $('.sc_copy').on('click', function(){
173 copy_to_clipboard($('.sc_preview_text').text());
174 $this = $(this);
175 $this.addClass('copied');
176 setTimeout(function() {
177 $this.removeClass('copied');
178 }, 3000);
179 })
180
181 $('.sc_changelog .dismiss_btn').on('click', function(){
182 var url = SC_VARS.ajax_url + '?action=sc_admin_ajax&do=close_changelog';
183 $.get(url, function( data ){
184 if(data.search( /done/g ) == -1){
185 $( '.sc_changelog article' ).html('Failed to close window. <a href="' + url + '" target="_blank">Please click here to close</a>');
186 }else{
187 $( '.sc_changelog' ).fadeOut();
188 }
189 });
190 });
191
192 $('.cfe_amt').on('click', function(){
193 var $btn = $(this).closest('.cfe_form').find('.cfe_btn');
194 $btn.attr('href', $btn.data('link') + $(this).val());
195 });
196
197 init();
198
199 });
200 })( jQuery );