ckeditor inline removes images - image

I am using ckeditor 4.x with inline editing.
I am inserting images in the HTML without ckeditor image module.
As soon as I initialize the inline editing, my are removed.
Here is the configuration I set:
config.extraAllowedContent = 'img!src,alt,title,width,height,style,old_style,ctype,img-prop,id{*}';
config.allowedContent = true;
Could someone help me?
Thanks

Found the solution !
When initializing the inline editing, add: "allowedContent"
example: _active_editor = CKEDITOR.inline(elm, { allowedContent: {img:{attributes:'',styles:'', classes:'*'}}...);

Related

Ckeditor plugin configuration not working

I have tried to add justify plugin to be able to align text right, left or centre. But after following the instructions in the documentation (http://apostrophecms.org/docs/tutorials/howtos/ckeditor.html), I wonder if the plugin should be located in a specific folder (mine is at public/modules/apostrophe-areas/js/ckeditorPlugins/justify/), as it disappears when the site is loaded, but if I include it in some other folder such as public/plugins/justify still doesn't work.
This is my code just in case: (located at lib/modules/apostrophe-areas/public/js/user.js)
apos.define('apostrophe-areas', {
construct: function(self, options) {
// Use the super pattern - don't forget to call the original method
var superEnableCkeditor = self.enableCkeditor;
self.enableCkeditor = function() {
superEnableCkeditor();
// Now do as we please
CKEDITOR.plugins.addExternal('justify', '/modules/apostrophe-areas/js/ckeditorPlugins/justify/', 'plugin.js');
};
}
});
Also, it would be nice to know how the plugin should be called at the Toolbar settings for editable widgets.
Thanks!
The URL you need is:
/modules/my-apostrophe-areas/js/ckeditorPlugins/justify/
The my- prefix is automatically prepended so that the public folders of both the original apostrophe-areas module and your project-level extension of it can have a distinct URL. Otherwise there would be no way for both to access their user.js, for instance.
I'll add this note to the HOWTO in question, which currently handwaves the issue by stubbing in a made-up URL.
As for how the plugin should be called, use the toolbar control name exported by that plugin — that part is a ckeditor question, not really an Apostrophe one. But looking at the source code of that plugin they are probably JustifyLeft, JustifyCenter, JustifyRight and JustifyBlock.
It turns out that it's not enough to simply call CKEDITOR.plugins.addExternal inside apostophe-areas. You also need to override self.beforeCkeditorInline of the apostrophe-rich-text-widgets-editor module and explicitly call self.config.extraPlugins = 'your_plugin_name';.
Here's what I ended up with:
In lib/modules/apostrophe-areas/public/js/user.js:
apos.define('apostrophe-areas', {
construct: function(self, options) {
// Use the super pattern - don't forget to call the original method
var superEnableCkeditor = self.enableCkeditor;
self.enableCkeditor = function() {
superEnableCkeditor();
// Now do as we please
CKEDITOR.plugins.addExternal('justify', '/modules/my-apostrophe-areas/js/ckeditorPlugins/justify/', 'plugin.js');
};
}
});
then in in lib/modules/apostrophe-rich-text-widgets/public/js/editor.js:
apos.define('apostrophe-rich-text-widgets-editor', {
construct: function(self, options) {
self.beforeCkeditorInline = function() {
self.config.extraPlugins = 'justify';
};
}
});
For some reason doing CKEDITOR.config.extraPlugins = 'justify' inside apostrophe-areas does not work, probably due to the way how CKEDITOR is initialized;
One more thing: this particular plug-in (justify, that is) does not seem to follow the button definition logic. It has button icons defined as images, whereas CKEditor 4.6 used in Apostrophe CMS 2.3 uses font-awesome to display icons. It means that the icons that ship with the justify module won't be displayed and you'll have to write your own css for each button individually.
There is another issue which you'll probably face when you finally enable the justify buttons. The built-in html sanitizer will be strip off the styles justify adds to align the content.
Apostrophe CMS seems to be using sanitize-html to sanitize the input, so changing CKEditor settings won't have any effect. To solve the issue, add the following to your app.js:
'apostrophe-rich-text-widgets': {
// The standard list copied from the module, plus sup and sub
sanitizeHtml: {
allowedAttributes: {
a: ['href', 'name', 'target'],
img: ['src'],
'*': ['style'] //this will make sure the style attribute is not stripped off
}
}
}
Thank you both for your help. After following both approaches of: locating the plugin at my-apostrophe-areas folder as well as editing editor.js on the apostrophe-rich-text widget (the sanitize.html file was already using that configuration), I got the plugin working. However, I was still having the issue with the icons.
I fixed that adding the Font Awesome icons that correspond to align-justify, align-right, align-left and align-center at the end of public/modules/apostrophe-areas/js/vendor/ckeditor/skins/apostrophe/editor.less

copy from webpages or word to ckeditor all tags and style intact

I 'm doing to copy web pages or Word documents to CKEditor.
but with the config below some tags, for example span dispear.
How to make all tags and attributes and styles intact?
I use CKEditor 4.
Here's the config.
config.forcePasteAsPlainText = false;
config.pasteFromWordRemoveFontStyles = false;
config.pasteFromWordRemoveStyles = false;
config.allowedContent = true;
You might also check config.pasteFromWordCleanupFile, which defaults to <plugin path> + 'filter/default.js'. If you have modified the default.js file, or are pointing to another cleanup filter file, that might cause your issues.

Hide toolbar and show colors

I have a problem. I'd like to show CKEditor without toolbar, and still keep colors on it. This is my code.
$(document).ready(function() {
var textAreaName = 'description';
CKEDITOR.replace( textAreaName, {
removePlugins: 'toolbar,elementspath',
readOnly: true
} ) ;
var oCKeditor = CKEDITOR.instances[textAreaName];
});
The problem is text color doesn't show. It seems that CKEditor disable color as well.
Assuming (because it's still unclear) that you want to keep text color in editor's contents (BTW. editor's contents is not rendered using textarea - it is only used for easier data submitting) this is a solution:
config.extraAllowedContent = 'span{!color}';
This will allow span elements with color style. Read more about Advanced Content Filter.
use this config.uiColor = '#AADC6E';
Where config is object of that component.

Adding Fontawesome to ckeditor

I am using Fontawesome in my website and have my own CMS to edit the website pages. What I would like to develop is a dialog for the user where he can pick an fontawesome icon but for now it is OK to add them in the codeview of ckeditor.
Icons added to the content are not shown in ckeditor designview. I have changed ckeditor config file so that the editor accepts i tags (*). I added the fontawesome CSS file as an #import rule to contents.css but still no fontawesome icon visible in the editor area.
(*)config.js
config.allowedContent = true;
config.ProtectedTags = 'i' ;
config.protectedSource.push( /<i[\s\S]*?\>/g ); //allows beginning <i> tag
config.protectedSource.push( /<\/i[\s\S]*?\>/g ); //allows ending </i> tag
What can I do to make this work?
config.protectedSource.push( /<i class[\s\S]*?\>/g );
config.protectedSource.push( /<\/i>/g );
What you have will interfere with img tags.
AND OR, after all of config:
CKEDITOR.dtd.$removeEmpty['i'] = false;
Both work well. Just be sure you have cleared cache completely when making changes.
*EDIT
One works while messing something else up. A no go solution.
I stopped using this bulky editor. Created my own.
However, to solve the solution, use EM or SPAN instead of I tags for this.
When you add something to the protectedSource setting, you're hiding it from the editor, that content is converted into a HTML comment to protect it and avoid that it can be modified by the user, but being a comment it's obviously hidden.
I'm using 4.11.4 and this solution not working correctly
This solution correctly work on 4.11.4
config.protectedSource.push( /<i class[\s\S]*?\><\/i>/g ); // Font Awesome fix
Goodluck
Instead of:
config.protectedSource.push(/<i class[\s\S]*?\><\/i>/g );
use more stronger and best way:
config.protectedSource.push(/<i class="fa[s|r|l|b] [A-Za-z0-9\-]+"><\/i>/g);
Because when user pasting content from another source, CKEDITOR.dtd should remove empty < i >, or convert < i > to semantic < em >, but only fontawesome icons with class="fas/far/fal/fab *" should be preserved.
(Naming in fontawesome: https://fontawesome.com/how-to-use/on-the-web/setup/getting-started)
Take a look at this: ckeditor fontawesome addon.
Basically, you should download the fontawesome addon in zip format, and extract to "ckeditor/plugins/", with the name "fontawesome".
Then, open "ckeditor/config.js" and signal the usage of the new addon:
config.extraPlugins = 'fontawesome';
config.contentsCss = 'path/to/your/font-awesome.css';
config.allowedContent = true;
The next thing is to edit your HTML's section:
<script>CKEDITOR.dtd.$removeEmpty['span'] = false;</script>
The final step is to use the toolbargroupname: "FontAwesome" in your toolbar:
config.toolbar = [
{ name: 'insert', items: [ 'FontAwesome', 'Source' ] }
];
Here is a demo.
This also applies for glyphicons, in the same way the fontawesome is used.
Cheers

How to make full CKEditor re-initialization?

Please help me - I need to make full re-initialization of CKeditor. I don't want to make re-initialization of instances of CKeditor, but I want fully reload it. Is there any way to implement it?
I tried to made next:
delete window.CKEDITOR;
and then:
//clear for old sources
$('script[src*="/includes/contentEditor/ckeditor/"]').each(function() {
$(this).remove();
});
$('link[href*="/includes/contentEditor/ckeditor/"]').each(function() {
$(this).remove();
});
//load CKeditor again
contentEditor.loadjscssfile('/includes/contentEditor/ckeditor/ckeditor.js', 'js');
contentEditor.loadjscssfile('/includes/contentEditor/ckeditor/adapters/jquery.js', 'js');
My method loads editor but some plugins does not work after reloading. Thanks for any help!
I have plugins and I don't need to fully reinitialize CKEditor either, just instances, are you doing it properly?
To remove my instance (my textarea is referenced by ID txt_postMsg):
$('#btn_cancelPost').click(function(){
CKEDITOR.remove(CKEDITOR.instances.txt_postMsg);
$('#txt_postMsg').remove();
$('#cke_txt_postMsg').remove();
});
Then I re-create the textarea, and after a 50ms timeout I call the constructor with the textarea again, plugins reload fine. We have some pretty complex plugins for flash/image editing so maybe there's an issue with your plugin?
My version:
$$("textarea._cke").each(function(Z) {
if (typeof(CKEDITOR.instances[Z.id]) == 'undefined') {
CKEDITOR.replace(Z.id, { customConfig : "yourconfig.js"});
} else {
CKEDITOR.instances[Z.id].destroy(true);
CKEDITOR.replace(Z.id, { customConfig : "yourconfig.js"});
}
});
try something like
for(var instanceName in CKEDITOR.instances)
CKEDITOR.remove(CKEDITOR.instances[instanceName]);
CKEDITOR.replaceAll();
AlfonsoML
I use CKeditor for dynamically edit different part of site. When I click on some area of the site it shows popup with CKeditor with content of this area above this area. When I save it I destroy instance of this editor, but if while editing I use link plugin CKeditor can't show editor without page refreshing. Chrome says - Uncaught TypeError: Cannot call method 'split' of undefined, Mozilla - x.config.skin is undefined(I try to set config.skin and it show another error - z is undefined).
I hope the full re-init can help.
P.S. Sorry I can find how to answer on your comment...
I've been looking for a way to re-initialize the editor and the only solution that I end up is to delete the instance and create a new ID.
Here's my code.
var editor = 'myeditor'
var instance = CKEDITOR.instances[editor];
if(typeof instance != 'undefined')
{
instance.destroy();
$(".cke_editor_" + editor).remove();
//make a new id
editor = (Math.random().toString(36).substr(2, 10););
}
CKEDITOR.replace(editor,
{
}
It's not perfect but it works.
Hope this helps.
This is my solution:
var editor = CKEDITOR.instances[your_ckeditor_id];
editor.mode = 'source';
editor.setMode('wysiwyg');
OR
var editor = CKEDITOR.instances[your_ckeditor_id];
editor.setData(editor.getData());

Resources