Skip to content

Instantly share code, notes, and snippets.

@aziz-blr
Last active September 6, 2020 15:50
Show Gist options
  • Save aziz-blr/37c94c6b96dcf87f8d3fe0d726d8c083 to your computer and use it in GitHub Desktop.
Save aziz-blr/37c94c6b96dcf87f8d3fe0d726d8c083 to your computer and use it in GitHub Desktop.
/**
* @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
*/
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here.
// For complete reference see:
// http://docs.ckeditor.com/#!/api/CKEDITOR.config
// config.filebrowserBrowseUrl = '././kcfinder/browse.php?type=files';
// config.filebrowserImageBrowseUrl = '././kcfinder/browse.php?type=images';
// config.filebrowserFlashBrowseUrl = '././kcfinder/browse.php?type=flash';
// config.filebrowserUploadUrl = '/kcfinder/upload.php?type=files';
// config.filebrowserImageUploadUrl = '/kcfinder/upload.php?type=images';
// config.filebrowserFlashUploadUrl = '/kcfinder/upload.php?type=flash';
// config.extraPlugins = 'wordcount';
// config.entities = false;
// config.enterMode = CKEDITOR.ENTER_BR;
// The toolbar groups arrangement, optimized for two toolbar rows.
config.toolbarGroups = [
{ name: 'clipboard', groups: [ 'clipboard', 'undo' ] },
{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ] },
// { name: 'links' },
// { name: 'insert' },
// { name: 'forms' },
// { name: 'tools' },
// { name: 'document', groups: [ 'mode', 'document', 'doctools' ] },
// { name: 'others' },
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ] },
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align' ] },
'/',
{ name: 'styles' },
{ name: 'colors' },
// { name: 'about' }
];
// Remove some buttons provided by the standard plugins, which are
// not needed in the Standard(s) toolbar.
config.removeButtons = 'Underline,Subscript,Superscript';
// Set the most common block elements.
config.format_tags = 'p;h1;h2;h3;pre';
config.colorButton_enableAutomatic = true;
// Simplify the dialog windows.
config.removeDialogTabs = 'image:advanced;link:advanced';
};
CKEDITOR.on('instanceReady', function (e) {
var instance = e.editor;
instance.on("change", function (evt) {
onCKEditorChange(evt.editor);
});
//key event handler is a hack, cause change event doesn't handle interaction with these keys
instance.on('key', function (evt) {
var backSpaceKeyCode = 8;
var deleteKeyCode = 46;
if (evt.data.keyCode == backSpaceKeyCode || evt.data.keyCode == deleteKeyCode) {
//timeout needed cause editor data will update after this event was fired
setTimeout(function() {
onCKEditorChange(evt.editor);
}, 100);
}
});
instance.on('mode', function () {
if (this.mode == 'source') {
var editable = instance.editable();
editable.attachListener(editable, 'input', function (evt) {
onCKEditorChange(instance);
});
}
});
});
function onCKEditorChange(intance) {
intance.updateElement();
triggerElementChangeAndJqueryValidation($(intance.element.$));
}
function triggerElementChangeAndJqueryValidation(element) {
element.trigger('keyup');
}
// Put this code in config.js file & then use jquery validation plugin with CkEditor
CKEDITOR.on('instanceReady', function (e) {
var instance = e.editor;
instance.on("change", function (evt) {
onCKEditorChange(evt.editor);
});
//key event handler is a hack, cause change event doesn't handle interaction with these keys
instance.on('key', function (evt) {
var backSpaceKeyCode = 8;
var deleteKeyCode = 46;
if (evt.data.keyCode == backSpaceKeyCode || evt.data.keyCode == deleteKeyCode) {
//timeout needed cause editor data will update after this event was fired
setTimeout(function() {
onCKEditorChange(evt.editor);
}, 100);
}
});
instance.on('mode', function () {
if (this.mode == 'source') {
var editable = instance.editable();
editable.attachListener(editable, 'input', function (evt) {
onCKEditorChange(instance);
});
}
});
});
function onCKEditorChange(intance) {
intance.updateElement();
triggerElementChangeAndJqueryValidation($(intance.element.$));
}
function triggerElementChangeAndJqueryValidation(element) {
element.trigger('keyup');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment