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
249 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('sc_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 | |
| 31 | if(SC_VARS['screen']['base'] == 'edit'){ |
| 32 | var version = '<small>v' + SC_VARS['sc_version'] + '</small>'; |
| 33 | $('.wp-heading-inline').append(version); |
| 34 | add_top_import_export_btn(); |
| 35 | } |
| 36 | |
| 37 | if(SC_VARS['screen']['base'] == 'post'){ |
| 38 | var $cfe_button = $('.cfe_bottom'); |
| 39 | if($cfe_button.length > 0){ |
| 40 | $cfe_button.appendTo('#normal-sortables'); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | add_top_coffee_btn(); |
| 45 | } |
| 46 | |
| 47 | $('.sc_params_list').appendTo('body'); |
| 48 | |
| 49 | } |
| 50 | |
| 51 | var set_sc_preview_text = function(name){ |
| 52 | $('.sc_preview_text').text('[sc name="' + name + '"]'); |
| 53 | } |
| 54 | |
| 55 | var insert_in_editor = function(data){ |
| 56 | console.log(data); |
| 57 | if(window.SC_EDITOR == 'code'){ |
| 58 | var doc = window.sc_cm.getDoc(); |
| 59 | doc.replaceRange(data, doc.getCursor()); |
| 60 | }else{ |
| 61 | send_to_editor(data); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | var copy_to_clipboard = function(str){ |
| 66 | var el = document.createElement('textarea'); |
| 67 | el.value = str; |
| 68 | el.setAttribute('readonly', ''); |
| 69 | el.style.position = 'absolute'; |
| 70 | el.style.left = '-9999px'; |
| 71 | document.body.appendChild(el); |
| 72 | el.select(); |
| 73 | document.execCommand('copy'); |
| 74 | document.body.removeChild(el); |
| 75 | }; |
| 76 | |
| 77 | var load_cm_sc_mode = function(){ |
| 78 | |
| 79 | if(typeof CodeMirror.overlayMode === 'undefined'){ |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | CodeMirror.defineMode('sc_mode', function(config, parserConfig){ |
| 84 | var mustacheOverlay = { |
| 85 | token: function(stream, state){ |
| 86 | if(stream.match(/\$\$[a-z0-9A-Z:_]+\$\$/)){ |
| 87 | return 'number sc_param'; |
| 88 | } |
| 89 | if(stream.match(/%%.*?%%/)){ |
| 90 | return 'atom sc_param'; |
| 91 | } |
| 92 | if(stream.match(/\[(.+?)?\](?:(.+?)?\[\/\])?/)){ |
| 93 | return 'string sc_param'; |
| 94 | } |
| 95 | stream.next(); |
| 96 | } |
| 97 | }; |
| 98 | return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || 'htmlmixed'), mustacheOverlay); |
| 99 | }); |
| 100 | } |
| 101 | |
| 102 | var close_params_list = function(){ |
| 103 | $('.sc_params_list').hide(); |
| 104 | } |
| 105 | |
| 106 | var add_top_coffee_btn = function(){ |
| 107 | |
| 108 | $('#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>'); |
| 109 | |
| 110 | } |
| 111 | |
| 112 | var add_top_import_export_btn = function(){ |
| 113 | |
| 114 | $('#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>'); |
| 115 | |
| 116 | $('#screen-meta').append('<div id="import-export-tab" class="hidden"></div>'); |
| 117 | |
| 118 | $('#ie_content > div').appendTo('#import-export-tab'); |
| 119 | |
| 120 | } |
| 121 | |
| 122 | $('#post_name').on('change keyup', function(){ |
| 123 | set_sc_preview_text($(this).val()); |
| 124 | }); |
| 125 | |
| 126 | $('.sc_editor').on('focus', function(){ |
| 127 | window.sc_old_editor = $(this).val(); |
| 128 | }).on('change', function(e){ |
| 129 | |
| 130 | new_editor = $(this).val(); |
| 131 | response = confirm(SC_VARS.text_editor_switch_notice); |
| 132 | |
| 133 | if(!response){ |
| 134 | e.preventDefault(); |
| 135 | $(this).val(window.sc_old_editor); |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | window.location = window.location + '&editor=' + $(this).val(); |
| 140 | |
| 141 | }); |
| 142 | |
| 143 | $('.sc_insert_param').on('click', function(e){ |
| 144 | |
| 145 | e.preventDefault(); |
| 146 | |
| 147 | var offset = $(this).offset(); |
| 148 | var mtop = offset.top + $(this).outerHeight(); |
| 149 | |
| 150 | $('.sc_params_list').css({ |
| 151 | top: mtop, |
| 152 | left: offset.left |
| 153 | }).toggle(); |
| 154 | |
| 155 | }); |
| 156 | |
| 157 | $('.sc_wp_params li').on('click', function(){ |
| 158 | insert_in_editor('$$' + $(this).data('id') + '$$'); |
| 159 | close_params_list(); |
| 160 | }); |
| 161 | |
| 162 | $('.sc_cp_btn').on('click', function(){ |
| 163 | |
| 164 | var $cp_box = $('.sc_cp_box'); |
| 165 | var $cp_default = $('.sc_cp_default'); |
| 166 | var $cp_info = $('.sc_cp_info'); |
| 167 | var param_val = $cp_box.val().trim(); |
| 168 | var default_val = $cp_default.val().trim(); |
| 169 | |
| 170 | if( param_val != '' && $cp_box[0].checkValidity() ){ |
| 171 | |
| 172 | var the_code = ''; |
| 173 | if(default_val == ''){ |
| 174 | the_code = '%%' + param_val + '%%'; |
| 175 | }else{ |
| 176 | the_code = '%%' + param_val + ':' + default_val + '%%'; |
| 177 | } |
| 178 | |
| 179 | insert_in_editor(the_code); |
| 180 | $cp_info.removeClass('red'); |
| 181 | close_params_list(); |
| 182 | }else{ |
| 183 | $cp_info.addClass('red'); |
| 184 | } |
| 185 | |
| 186 | }); |
| 187 | |
| 188 | $('.sc_cf_btn').on('click', function(){ |
| 189 | |
| 190 | var $cf_box = $('.sc_cf_box'); |
| 191 | var $cf_info = $('.sc_cf_info'); |
| 192 | var param_val = $cf_box.val().trim(); |
| 193 | |
| 194 | if( param_val != '' && $cf_box[0].checkValidity() ){ |
| 195 | insert_in_editor('$$custom_field:' + param_val + '$$'); |
| 196 | $cf_info.removeClass('red'); |
| 197 | close_params_list(); |
| 198 | }else{ |
| 199 | $cf_info.addClass('red'); |
| 200 | } |
| 201 | |
| 202 | }); |
| 203 | |
| 204 | $('.sc_copy').on('click', function(){ |
| 205 | copy_to_clipboard($('.sc_preview_text').text()); |
| 206 | $this = $(this); |
| 207 | $this.addClass('copied'); |
| 208 | setTimeout(function() { |
| 209 | $this.removeClass('copied'); |
| 210 | }, 3000); |
| 211 | }) |
| 212 | |
| 213 | $('.sc_changelog .dismiss_btn').on('click', function(){ |
| 214 | var url = SC_VARS.ajax_url + '?action=sc_admin_ajax&do=close_changelog'; |
| 215 | $.get(url, function( data ){ |
| 216 | if(data.search( /done/g ) == -1){ |
| 217 | $( '.sc_changelog article' ).html('Failed to close window. <a href="' + url + '" target="_blank">Please click here to close</a>'); |
| 218 | }else{ |
| 219 | $( '.sc_changelog' ).fadeOut(); |
| 220 | } |
| 221 | }); |
| 222 | }); |
| 223 | |
| 224 | $('.cfe_amt').on('click', function(){ |
| 225 | var $btn = $(this).closest('.cfe_form').find('.cfe_btn'); |
| 226 | $btn.attr('href', $btn.data('link') + $(this).val()); |
| 227 | }); |
| 228 | |
| 229 | $('.subscribe_btn').click(function(e){ |
| 230 | e.preventDefault(); |
| 231 | var action = $(this).parent().data('action'); |
| 232 | $.ajax({ |
| 233 | type: 'get', |
| 234 | url: action, |
| 235 | cache: false, |
| 236 | dataType: 'jsonp', |
| 237 | data: { |
| 238 | 'EMAIL': $('.subscribe_email_box').val() |
| 239 | }, |
| 240 | success : function(data) { |
| 241 | } |
| 242 | }); |
| 243 | $('.subscribe_confirm').show(); |
| 244 | }); |
| 245 | |
| 246 | init(); |
| 247 | |
| 248 | }); |
| 249 | })( jQuery ); |