1/* 2 Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.md or http://ckeditor.com/license 4 */ 5var editorCKE; 6jQuery(document).ready(function () { 7 ckeditorSettings.configuration['on'] = { 8 configLoaded : function ( evt ) { 9 if (typeof(ckeditorSettings.externalPlugins) != 'undefined') { 10 var externals=new Array(); 11 for (var x in ckeditorSettings.externalPlugins) { 12 CKEDITOR.plugins.addExternal(x, ckeditorSettings.externalPlugins[x]); 13 externals.push(x); 14 } 15 } 16 evt.editor.config.extraPlugins += (evt.editor.config.extraPlugins ? ','+externals.join(',') : externals.join(',')); 17 if (evt.editor.config.toolbar && evt.editor.config[evt.editor.config.toolbar +'_removeButtons']); 18 evt.editor.config.removeButtons = evt.editor.config[evt.editor.config.toolbar +'_removeButtons']; 19 CKEDITOR.addCss(evt.editor.config.extraCss); 20 } 21 }; 22 CKEDITOR.on( 'instanceReady', function( ev ) 23 { 24 var dtd = CKEDITOR.dtd; 25 for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) 26 { 27 ev.editor.dataProcessor.writer.setRules( e, ckeditorSettings.outputFormat); 28 } 29 ev.editor.dataProcessor.writer.setRules( 'br', 30 { 31 breakAfterOpen : true 32 }); 33 ev.editor.dataProcessor.writer.setRules( 'pre', 34 { 35 indent: false 36 }); 37 editorCKE = CKEDITOR.instances['content']; 38 }); 39 40 if (ckeditorSettings.textarea_id != 'comment'){ 41 edInsertContentOld = function () { 42 return ; 43 }; 44 if(typeof(window.edInsertContent) != 'undefined'){ 45 edInsertContentOld = window.edInsertContent; 46 } 47 window.edInsertContent = function (myField, myValue) { 48 if(typeof(CKEDITOR) != 'undefined' && typeof(editorCKE) != 'undefined'){ 49 editorCKE.insertHtml(myValue); 50 } else { 51 edInsertContentOld(myField, myValue); 52 } 53 }; 54 var autosaveOld = function () { 55 return ; 56 }; 57 if(typeof(window.autosave) != 'undefined'){ 58 autosaveOld = window.autosave; 59 } 60 61 if(typeof(window.switchEditors) != 'undefined') { 62 window.switchEditors.go = function(id, mode) { 63 if ('tinymce' == mode || 'tmce' == mode) { 64 jQuery('#'+id).closest('.html-active').removeClass('html-active').addClass('tmce-active'); 65 ckeditorOn(id); 66 } else { 67 jQuery('#'+id).closest('.tmce-active').removeClass('tmce-active').addClass('html-active'); 68 ckeditorOff(id); 69 jQuery('.js .theEditor').attr('style', 'color: black;'); 70 } 71 }; 72 window.switchEditors.switchto = function(elm) { 73 var id = jQuery('#'+elm.id).closest('.wp-editor-wrap').find('textarea').attr('id'); 74 return window.switchEditors.go(id, elm.id.replace('content-', '')); 75 } 76 } 77 } 78 //if qTranslate plugin enabled 79 if ( ckeditorSettings.qtransEnabled ){ 80 //custom version of switchEditors function when qTranslate plugin is enabled 81 if(typeof(window.switchEditors) != 'undefined') { 82 window.switchEditors.go = function(id, lang) { 83 84 id = id || 'content'; 85 lang = lang || 'toggle'; 86 87 if ( 'toggle' == lang ) { 88 if ( ed && !ed.isHidden() ) 89 lang = 'html'; 90 else 91 lang = 'tmce'; 92 } else if( 'tinymce' == lang ) 93 lang = 'tmce'; 94 95 var inst = tinyMCE.get('qtrans_textarea_' + id); 96 var vta = document.getElementById('qtrans_textarea_' + id); 97 var ta = document.getElementById(id); 98 var wrap_id = 'wp-'+id+'-wrap'; 99 100 // update merged content 101 if(inst && ! inst.isHidden()) { 102 tinyMCE.triggerSave(); 103 } else { 104 qtrans_save(vta.value); 105 } 106 // check if language is already active 107 if(lang!='tmce' && lang!='html' && document.getElementById('qtrans_select_'+lang).className=='wp-switch-editor switch-tmce switch-html') { 108 return; 109 } 110 111 if(lang!='tmce' && lang!='html') { 112 document.getElementById('qtrans_select_'+qtrans_get_active_language()).className='wp-switch-editor'; 113 document.getElementById('qtrans_select_'+lang).className='wp-switch-editor switch-tmce switch-html'; 114 } 115 if(lang=='html') { 116 if ( inst && inst.isHidden() ) 117 return false; 118 if ( inst ) { 119 vta.style.height = inst.getContentAreaContainer().offsetHeight + 20 + 'px'; 120 inst.hide(); 121 } 122 jQuery("#"+wrap_id).removeClass('tmce-active'); 123 jQuery("#"+wrap_id).addClass('html-active'); 124 setUserSetting( 'editor', 'html' ); 125 } else if(lang=='tmce') { 126 if(inst && ! inst.isHidden()) 127 return false;
128 if ( tinyMCEPreInit.mceInit[id] && tinyMCEPreInit.mceInit[id].wpautop ) 129 vta.value = this.wpautop(qtrans_use(qtrans_get_active_language(),ta.value)); 130 if (inst) { 131 inst.show(); 132 } else { 133 qtrans_hook_on_tinyMCE(id); 134 } 135 jQuery("#"+wrap_id).removeClass('html-active'); 136 jQuery("#"+wrap_id).addClass('tmce-active'); 137 setUserSetting('editor', 'tinymce'); 138 } else { 139 // switch content 140 qtrans_assign('qtrans_textarea_'+id,qtrans_use(lang,ta.value)); 141 } 142 } 143 window.switchEditors.switchto = function(elm) { 144 var id = jQuery('#'+elm.id).closest('.wp-editor-wrap').find('textarea').attr('id'); 145 return window.switchEditors.go(id, elm.id.replace('content-', '')); 146 } 147 } 148 jQuery('#edButtonHTML').addClass('active'); 149 jQuery('#edButtonPreview').removeClass('active'); 150 if(ckeditorSettings.textarea_id != 'comment'){ 151 152 ckeditorSettings.textarea_id = 'qtrans_textarea_content'; 153 ckeditorSettings.configuration['on'].getData = function (evt) { 154 evt.data.dataValue = evt.data.dataValue.replace(/(^<\/p>)|(<p>$)/g, ''); 155 evt.data.dataValue = evt.data.dataValue.replace(/^<p>(\s|\n|\r)*<p>/g, '<p>'); 156 evt.data.dataValue = evt.data.dataValue.replace(/<\/p>(\s|\n|\r)*<\/p>(\s|\n|\r)*$/g, '<\/p>'); 157 qtrans_save(evt.data.dataValue); 158 }; 159 if ( jQuery('#'+ckeditorSettings.textarea_id).length && typeof CKEDITOR.instances[ckeditorSettings.textarea_id] == 'undefined' ) { 160 CKEDITOR.replace(ckeditorSettings.textarea_id, ckeditorSettings.configuration); 161 editorCKE = CKEDITOR.instances[ckeditorSettings.textarea_id]; 162 //add afterCommandExec exect to last created CKEditor instance 163 editorCKE.on( 'afterCommandExec', function(ev) { 164 afterCommandEvent(ev); 165 }); 166 } 167 168 window.tinyMCE = tinymce = getTinyMCEObject(); 169 } 170 }else { 171 if(ckeditorSettings.autostart && (typeof getUserSetting == 'undefined' || getUserSetting('editor') === '' || getUserSetting('editor') == 'tinymce')){ 172 ckeditorOn(); 173 } 174 } 175 jQuery("#update-gallery").click(function(){ 176 updateCkeGallery(); 177 }); 178 179 if (ckeditorSettings.excerpt_state && jQuery("textarea#excerpt").length > 0 && jQuery("#postexcerpt-hide").attr('checked') == 'checked') { 180 //ckeditorOn('excerpt'); 181 CKEDITOR.replace('excerpt', ckeditorSettings.configuration); 182 } 183 if (typeof window.tinyMCE != 'undefined') { 184 if (typeof QTags != 'undefined') { 185 jQuery(".row-actions span.reply a").on('click', function(){ 186 if (typeof CKEDITOR.instances['replycontent'] != 'undefined') { 187 ckeditorOff('replycontent'); 188 } 189 CKEDITOR.replace('replycontent', {'basicEntities' : false, 'entities': false,'toolbar_Comments' : [{ name: 'basicstyles', items : [ 'Bold','Italic','Underline'] }, { name: 'links', items : [ 'Link','Unlink' ] },{ name: 'paragraph', items : [ 'NumberedList','BulletedList'] }, { name: 'insert', items : [ 'Image' ] } ], 'toolbar' : 'Comments'}); 190 }); 191 jQuery("#replyrow a.save").unbind('click').on('click', function(){ 192 var data = null; 193 if (typeof CKEDITOR.instances['replycontent'] != 'undefined') { 194 data = CKEDITOR.instances['replycontent'].getData(); 195 } 196 if (data != null && data.length > 0 ) { 197 jQuery('textarea#replycontent').html(data); 198 ckeditorOff('replycontent'); 199 } 200 commentReply.send(); 201 return; 202 }); 203 jQuery("#replyrow a.cancel").unbind('click').on('click', function(){ 204 commentReply.revert() 205 ckeditorOff('replycontent'); 206 return; 207 }); 208 QTags.getInstance = function (editor_id) { 209 return window.tinyMCE; 210 } 211 } 212 } 213}); 214function ckeditorOn(id) { 215 var instance; 216 if (typeof(id) != 'undefined' && typeof(CKEDITOR.instances[id]) == 'undefined' ) 217 { 218 setUserSetting( 'editor', 'tinymce' ); 219 jQuery('#quicktags').hide(); 220 jQuery('#edButtonPreview').addClass('active'); 221 jQuery('#edButtonHTML').removeClass('active'); 222 instance = CKEDITOR.replace(id, ckeditorSettings.configuration); 223 } 224 if ( jQuery('textarea#'+ckeditorSettings.textarea_id).length && (typeof(CKEDITOR.instances) == 'undefined' || typeof(CKEDITOR.instances[ckeditorSettings.textarea_id]) == 'undefined' ) && jQuery("#"+ckeditorSettings.textarea_id).parent().parent().attr('id') != 'quick-press') { 225 instance = CKEDITOR.replace(ckeditorSettings.textarea_id, ckeditorSettings.configuration); 226 if(ckeditorSettings.textarea_id == 'content') { 227 setUserSetting( 'editor', 'tinymce' ); 228 jQuery('#quicktags').hide(); 229 jQuery('#edButtonPreview').addClass('active'); 230 jQuery('#edButtonHTML').removeClass('active'); 231 } 232 else if(ckeditorSettings.textarea_id == 'comment') { 233 var labelObj = jQuery('#'+ckeditorSettings.textarea_id).prev('label'); 234 if (labelObj){ 235 labelObj.hide(); 236 } 237 } 238 } 239 if (typeof(instance) != 'undefined') { 240 //add afterCommandExec exect to last created CKEditor instance 241 instance.on( 'afterCommandExec', function(ev) { 242 afterCommandEvent(ev); 243 }); 244 } 245} 246 247function ckeditorOff(id) { 248 if (typeof(id) != 'undefined' && typeof(CKEDITOR.instances[id]) != 'undefined') 249 { 250 editorCKE = CKEDITOR.instances[id]; 251 }else 252 { 253 editorCKE = CKEDITOR.instances[ckeditorSettings.textarea_id]; 254 } 255 if(typeof(editorCKE) != 'undefined'){ 256 editorCKE.destroy(); 257 if(ckeditorSettings.textarea_id == 'content') { 258 setUserSetting( 'editor', 'html' ); 259 jQuery('#quicktags').show(); 260 jQuery('#edButtonHTML').addClass('active'); 261 jQuery('#edButtonPreview').removeClass('active'); 262 } 263 } 264} 265 266if ( !ckeditorSettings.qtransEnabled ){ 267 var tinymce = window.tinyMCE = getTinyMCEObject(); 268} 269function getTinyMCEObject() 270{ 271 var tinymce = window.tinyMCE = (function () { 272 var tinyMCE = { 273 isOpera : function() { 274 return CKEDITOR.env.opera; 275 }, 276 onAddEditor : { add : function() { 277 // this function did nothing else apart from resizing TinyMCE 278 } }, 279 get : function (id) { 280 var instant = { 281 isHidden : function (){ 282 editor = CKEDITOR.instances[id]; 283 if (typeof editorCKE == 'undefined') editorCKE = editor; 284 if(typeof(editor) != 'undefined') 285 { 286 return false;
287 }else{ 288 return true; 289 } 290 }, 291 isDirty : function (){ 292 return false; 293 }, 294 execCommand : function (command, integer, val) { 295 if(command == 'mceSetContent') { 296 editorCKE.setData(val); 297 } 298 if (command == 'mceInsertContent') 299 { 300 editorCKE.insertHtml(val); 301 } 302 }, 303 onSaveContent : { 304 add : function (func) { 305 window.tinymceosc = func; 306 } 307 }, 308 on : function(action, callback){ 309 return callback(); 310 }, 311 getContentAreaContainer : function () { 312 return { 313 offsetHeight : editorCKE.config.height 314 }; 315 }, 316 hide : function () { 317 ckeditorOff(id); 318 }, 319 show : function () { 320 ckeditorOn(id); 321 }, 322 save : function(){ 323 return; 324 }, 325 focus : function(){ 326 return; 327 }, 328 plugins: {} 329 }; 330 331 return instant; 332 }, 333 execCommand : function (command, integer, val) { 334 if(command == 'mceAddControl'){ 335 ckeditorSettings.textarea_id = val; 336 if(ckeditorSettings.autostart) { 337 ckeditorOn(); 338 } else { 339 document.getElementById('qtrans_textarea_content').removeAttribute('style'); 340 } 341 } 342 }, 343 triggerSave : function(param) { 344 if(typeof(CKEDITOR) != 'undefined' && typeof(editorCKE) != 'undefined') 345 editorCKE.updateElement(); 346 }, 347 activeEditor : { 348 isHidden : function (){ 349 return false; 350 }, 351 isDirty : function (){ 352 return false; 353 }, 354 focus : function (){ 355 return; 356 }, 357 plugins : {}, 358 execCommand : function(command, state, text) 359 { 360 if (command == "mceInsertContent") 361 { 362 //test if image has caption and make necessary text format 363 pattern = /\[caption(.*)\]<.*>(.*)\[\/caption\]/i; 364 if (pattern.test(text)) { 365 replace_match = pattern.exec(text); 366 text = text.replace(/<img (.*) \/>/g, function( match, cont ) 367 { 368 cont = cont.replace(/class="(.*)"/g, function( match, cont ){ 369 tmp = 'class="' + cont + ' wp-caption"'; 370 return tmp; 371 }); 372 tmp = '<img ' + cont + ' data-cke-caption=\'' + replace_match[1] + '\' data-cke-caption-text=\'' + replace_match[2] + '\' />' ; 373 return tmp; 374 }); 375 } 376 //setTimeout is required in IE8 when inserting Image gallery from an external modal dialog 377 if (typeof editorCKE == 'undefined') editorCKE = CKEDITOR.instances[ckeditorSettings.textarea_id]; 378 setTimeout(function(){ 379 editorCKE.insertHtml(text); 380 }, 0); 381 } 382 }, 383 selection : { 384 getBookmark : function(name) { 385 return ''; 386 } 387 }, 388 windowManager : { 389 bookmark: {} 390 } 391 }, 392 EditorManager :{ 393 activeEditor: { 394 selection : { 395 getNode : function(){ 396 var obj = jQuery(editorCKE.document.getBody().getHtml()); 397 var index = 0; 398 jQuery.each(obj,function(i, val){ 399 var images = jQuery("img",jQuery(val)); 400 jQuery.each(images, function(key, value){ 401 if (jQuery(value).hasClass('wpGallery, cke_wpgallery')) 402 { 403 index = i; 404 return; 405 } 406 }); 407 }); 408 if (obj.length === 0) 409 { 410 obj = document.createElement("p"); 411 return obj; 412 } 413 return obj[index]; 414 }, 415 getBookmark : function(name) { 416 return ; 417 } 418 }, 419 dom :{ 420 select : function(selector) { 421 422 //get CKEditor content 423 var obj = editorCKE.document.getBody().getHtml(); 424 images = editorCKE.document.getElementsByTag('img'); 425 if ( typeof images.$ == 'undefined' || images.$.length == 0) return []; 426 for (var i in images.$) 427 { 428 if ( typeof images.$[i] != 'undefined' && ((CKEDITOR.env.ie && images.$[i].className == 'wpGallery, cke_wpgallery') || images.$[i].classList == 'wpGallery, cke_wpgallery')) 429 { 430 var element = new CKEDITOR.dom.element(images.$[i]); 431 index = i; 432 break; 433 } 434 } 435 var results =[]; 436 437 if (typeof element != 'undefined') 438 { 439 results[0] = images.$[index]; 440 return results; 441 442 }else 443 { 444 return []; 445 } 446 }, 447 getAttrib : function(el, selector) 448 { 449 return jQuery(el).attr(selector); 450 }, 451 //function to set new gallery attributes 452 setAttrib : function(el, selector, value) 453 { 454 //get CKEditor content 455 var obj = editorCKE.document.getBody().getHtml(); 456 images = editorCKE.document.getElementsByTag('img'); 457 for (var i in images.$) 458 { 459 if ( typeof images.$[i] != 'undefined' && ((CKEDITOR.env.ie && images.$[i].className == 'wpGallery, cke_wpgallery') || images.$[i].classList == 'wpGallery, cke_wpgallery')) 460 { 461 var element = new CKEDITOR.dom.element(images.$[i]); 462 element.setAttribute('title', value); 463 element.setAttribute('data-gallery', '['+value+']'); 464 } 465 } 466 }, 467 decode : function(text) { 468 return text; 469 }, 470 hasClass : function(element, name) 471 { 472 var hasClass = jQuery(element).attr('class'); 473 var pattern = /wpGallery/; 474 return pattern.test(hasClass); 475 } 476 } 477 }, 478 get : function(id) {return;} 479 }, 480 DOM :{ 481 removeClass : function(id, className) {return;}, 482 addClass : function(id, className) {return;} 483 }, 484 addI18n : function(language, param){ 485 return ; 486 }, 487 $ : function () { 488 return { 489 on: function (name, callback) { 490 return; 491 } 492 } 493 } 494 }; 495 return tinyMCE; 496})(); 497 return tinymce; 498} 499var tinyMCEPreInit = { 500 mceInit : function(){ 501 language : 'en'; 502 } 503}; 504 505var tinyMCEPopup = { 506 onInit : { 507 add : function() {return ;} 508 }, 509 editor : { 510 windowManager : { 511 createInstance : function(id) {return; } 512 } 513 } 514}; 515/*
516 * Function to move cursor after fake gallery image. Turn on frame show 517 */ 518function updateCkeGallery() 519{ 520 jQuery("#add_image").unbind('click'); 521 jQuery("#add_image").bind('click',function(){ 522 return true; 523 }); 524} 525function afterCommandEvent(ev) 526{ 527 if (ev.data.name != 'maximize') { return; } 528 //if maximize button was clicked hide/show WP admin bar - prevention of hiding buttton under WP admin bar 529 if (ev.data.command.state == CKEDITOR.TRISTATE_ON) { jQuery("#wpadminbar").hide() } else { jQuery("#wpadminbar").show() } 530}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.