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 thepublic
folders of both the originalapostrophe-areas
module and your project-level extension of it can have a distinct URL. Otherwise there would be no way for both to access theiruser.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
andJustifyBlock
.Thank you both for your help. After following both approaches of: locating the plugin at
my-apostrophe-areas
folder as well as editingeditor.js
on theapostrophe-rich-text
widget (thesanitize.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
andalign-center
at the end ofpublic/modules/apostrophe-areas/js/vendor/ckeditor/skins/apostrophe/editor.less
It turns out that it's not enough to simply call
CKEDITOR.plugins.addExternal
insideapostophe-areas
. You also need to overrideself.beforeCkeditorInline
of theapostrophe-rich-text-widgets-editor
module and explicitly callself.config.extraPlugins = 'your_plugin_name';
.Here's what I ended up with:
In
lib/modules/apostrophe-areas/public/js/user.js
:then in
in lib/modules/apostrophe-rich-text-widgets/public/js/editor.js
:For some reason doing
CKEDITOR.config.extraPlugins = 'justify'
insideapostrophe-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: