PluginProbe ʕ •ᴥ•ʔ
Shortcoder — Create Shortcodes for Anything / 5.0
Shortcoder — Create Shortcodes for Anything v5.0
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
195 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 CodeMirror.defineMode('sc_mode', function(config, parserConfig){
72 var mustacheOverlay = {
73 token: function(stream, state){
74 if(stream.match(/\$\$[a-z0-9A-Z:_]+\$\$/)){
75 return 'number sc_param';
76 }
77 if(stream.match(/%%[a-z0-9A-Z_]+%%/)){
78 return 'atom sc_param';
79 }
80 stream.next();
81 }
82 };
83 return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || 'htmlmixed'), mustacheOverlay);
84 });
85 }
86
87 var close_params_list = function(){
88 $('.sc_params_list').hide();
89 }
90
91 var add_top_coffee_btn = function(){
92 $('#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>');
93 }
94
95 $('#post_name').on('change keyup', function(){
96 set_sc_preview_text($(this).val());
97 });
98
99 $('.sc_editor').on('focus', function(){
100 window.sc_old_editor = $(this).val();
101 }).on('change', function(e){
102
103 new_editor = $(this).val();
104 response = confirm(SC_VARS.text_editor_switch_notice);
105
106 if(!response){
107 e.preventDefault();
108 $(this).val(window.sc_old_editor);
109 return false;
110 }
111
112 window.location = window.location + '&editor=' + $(this).val();
113
114 });
115
116 $('.sc_insert_param').on('click', function(e){
117
118 e.preventDefault();
119
120 var offset = $(this).offset();
121 var mtop = offset.top + $(this).outerHeight();
122
123 $('.sc_params_list').css({
124 top: mtop,
125 left: offset.left
126 }).toggle();
127
128 });
129
130 $('.sc_wp_params li').on('click', function(){
131 insert_in_editor('$$' + $(this).data('id') + '$$');
132 close_params_list();
133 });
134
135 $('.sc_cp_btn').on('click', function(){
136
137 var $cp_box = $('.sc_cp_box');
138 var $cp_info = $('.sc_cp_info');
139 var param_val = $cp_box.val().trim();
140
141 if( param_val != '' && $cp_box[0].checkValidity() ){
142 insert_in_editor('%%' + param_val + '%%');
143 $cp_info.removeClass('red');
144 close_params_list();
145 }else{
146 $cp_info.addClass('red');
147 }
148
149 });
150
151 $('.sc_cf_btn').on('click', function(){
152
153 var $cf_box = $('.sc_cf_box');
154 var $cf_info = $('.sc_cf_info');
155 var param_val = $cf_box.val().trim();
156
157 if( param_val != '' && $cf_box[0].checkValidity() ){
158 insert_in_editor('$$custom_field:' + param_val + '$$');
159 $cf_info.removeClass('red');
160 close_params_list();
161 }else{
162 $cf_info.addClass('red');
163 }
164
165 });
166
167 $('.sc_copy').on('click', function(){
168 copy_to_clipboard($('.sc_preview_text').text());
169 $this = $(this);
170 $this.addClass('copied');
171 setTimeout(function() {
172 $this.removeClass('copied');
173 }, 3000);
174 })
175
176 $('.sc_changelog .dismiss_btn').on('click', function(){
177 var url = SC_VARS.ajax_url + '?action=sc_admin_ajax&do=close_changelog';
178 $.get(url, function( data ){
179 if(data.search( /done/g ) == -1){
180 $( '.sc_changelog article' ).html('Failed to close window. <a href="' + url + '" target="_blank">Please click here to close</a>');
181 }else{
182 $( '.sc_changelog' ).fadeOut();
183 }
184 });
185 });
186
187 $('.cfe_amt').on('click', function(){
188 var $btn = $(this).closest('.cfe_form').find('.cfe_btn');
189 $btn.attr('href', $btn.data('link') + $(this).val());
190 });
191
192 init();
193
194 });
195 })( jQuery );