CKEditor Custom Plugins Button - ckeditor

I've written a custom plugin for CKEditor--successful on all fronts, save one currently: I can't, for the life of me, figure out how to customize the image on the button in the toolbar of the editor. As I'm a new user, you'll have to click through to see attached image; the highlighted square in the top left should have a pretty picture (like most of the other toolbar items).

I have written a complete tutorial covering every aspect of CKeditor plugin development, including buttons, context menus, dialogs and more.

The answer is to set the icon property of the button settings like so:
editor.ui.addButton('your-plugin', {
label: 'Your Plugin Label',
command: 'YourPlugin',
icon: this.path + 'images/your-plugin.jpg'
});
Your plugin directory should have an "images" subdirectory where your button should go. In the above snippet, replace "your-plugin.jpg' with the JPG, GIF or PNG image for your button.
This answer, of course, assumes that you know how to create a button image using some image editor like Gimp, Photoshop, etc.

Some info for others try to write plugins for CKEditor 3.0.
I've started by copying the source from plugins/flash and have now got a button with a youtube logo.... this is an extract from plugins/youtube/plugin.js
editor.ui.addButton( 'YouTube',
{
label : editor.lang.common.youtube,
command : 'youtube',
icon: this.path + 'images/youtube.gif'
});
Also you'll need to edit you language file.... e.g. lang/en.js
Add your plugin name to the "common" section (this appears as a tooltip when you hover over the button) and add a whole block for your plugin, with all your strings, like this....
// YouTube Dialog
youtube :
{
properties : 'YouTube Properties',
propertiesTab : 'Properties',
title : 'YouTube Properties',
chkPlay : 'Auto Play',
chkLoop : 'Loop',
chkMenu : 'Enable YouTube Menu',
chkFull : 'Allow Fullscreen',
scale : 'Scale',
scaleAll : 'Show all',
scaleNoBorder : 'No Border',
scaleFit : 'Exact Fit',
access : 'Script Access',
accessAlways : 'Always',
accessSameDomain : 'Same domain',
accessNever : 'Never',
align : 'Align',
alignLeft : 'Left',
alignAbsBottom: 'Abs Bottom',
alignAbsMiddle: 'Abs Middle',
alignBaseline : 'Baseline',
alignBottom : 'Bottom',
alignMiddle : 'Middle',
alignRight : 'Right',
alignTextTop : 'Text Top',
alignTop : 'Top',
quality : 'Quality',
qualityBest : 'Best',
qualityHigh : 'High',
qualityAutoHigh : 'Auto High',
qualityMedium : 'Medium',
qualityAutoLow : 'Auto Low',
qualityLow : 'Low',
windowModeWindow : 'Window',
windowModeOpaque : 'Opaque',
windowModeTransparent : 'Transparent',
windowMode : 'Window mode',
flashvars : 'Variables for YouTube',
bgcolor : 'Background color',
width : 'Width',
height : 'Height',
hSpace : 'HSpace',
vSpace : 'VSpace',
validateSrc : 'URL must not be empty.',
validateWidth : 'Width must be a number.',
validateHeight : 'Height must be a number.',
validateHSpace : 'HSpace must be a number.',
validateVSpace : 'VSpace must be a number.'
}

these are some plugins for CKEditor 3.x
CKEditor Plugins
Highslide JS Plugin,
LrcShow Plugin,
FileIcon Plugin,
InsertHtml Plugin,
SyntaxHighlighter Plugin
Download: CKEditor 3.x Plugins

There is a pretty exhaustive tutorial on CKEditor Documentation Website, see: CKEditor Plugin SDK - Introduction
At this moment it covers:
Creating an Editor Command
Creating the Toolbar Button with an icon
Explanation on how to register the plugin in CKEditor
Creating Plugin Dialog Window with Two tabs
Adding Context Menu
Advanced Content Filter (ACF) integration (on a separate page)
If you are interested in creating your own widgets, check also Widgets SDK Tutorial

To add your custom icon you need to edit skins/moono/*.css
For the editor itself you need to add the same CSS class in the following files
editor.css
editor_gecko.css (firefox)
editor_ie.css
editor_ie7.css
editor_ie8.css
editor_iequirks.css
The format name for a CSS button class is .cke_button__myCustomIcon_icon
You can either use your own image file for the icon or edit the sprite /skins/moono/icons.png to add your's.
In your plugin.js you need to have something like
editor.ui.addButton('myplugin',
{
label: 'myplugin',
command: FCKCommand_myplugin,
icon: 'myCustomIcon'
});

Regarding font awesome, I was able to achieve this using CSS:
span.cke_button_icon.cke_button__bold_icon {
position: relative !important;
background-image: none !important;
&:after {
font-family: FontAwesome;
position: absolute;
font-size: 16px;
content: "\f032";
}
}

Related

customize toolbar position and customize ckeditor javascript file

i am using ckeditor inline , i want to customize ckeditor toolbar top and left position once toolbar is loaded at certain position. and also i want to update ckeditor.js and use in my website but when i edit ckeditor.js using beautifier , it gives error after i update and use in website.
i have tried to set custom top and left position for ckeditor toolbar but as it comes out from instanceReady event , it again reset position .
ck = CKEDITOR.inline(editableDivElement[0], {
removePlugins: 'resize, elementspath',
extraPlugins: 'ckeditor_wiris, smiley',
height: 60,
toolbar: toolbars,
toolbarLocation: 'top',
startupFocus: true,
});
ck.on("instanceReady", function (event) {
var ckeditorToolBar: any =
document.getElementsByClassName("cke");
if (ckeditorToolBar) {
ckeditorToolBar[0].style.top ="100px";
ckeditorToolBar[0].style.left="100px";
});
if there is way i can edit ckeditor.js and use in my website and also if i can set custom ckeditor toolbar position using top and left.

AlloyUI Ace-Editor Theme Change

I am not able to find a way to change the Ace-Editor that is built into the AllouUI widget. The example below is what I would like to achieve with the theme attribute.
YUI().use(
'aui-ace-autocomplete-base',
function(Y) {
var editor = new Y.AceEditor(
{
boundingBox: '#myEditor',
height: '200',
mode: 'python',
value: 'print("Hello there!!!")',
width: '700',
theme: 'chaos'
}
).render();
Sadly, there in the code there are no predefined ways I saw to change the theme.
Is there a way change the theme to ace editor for alloyui's widget?
Not sure if Y.AceEditor component exposes the required api, but you can try to get the real ace editor object, which allows to change the theme dynamically
document.getElementById('#myEditor').env.editor.setTheme("ace/theme/chtome")
You should be able to call AceEditor.getEditor().setTheme():
editor.getEditor().setTheme('ace/theme/twilight');

CKEditor config.stylesSet

I'm trying to get the dropdown styles option in CKEditor V4 configured. My test, shown below, does not work as expected. The dropdown style menu its self does display the "Green Check" option (label and the image used in the style) but its not applied to content of editor instance when used. I'm using the new inline editing feature (way cool it is too).
config.stylesSet = [
{ name: 'Green Check', element : 'ul li',
styles :
{
'background' : 'url(/images/bullets/greencheck.png) no-repeat top left;',
'list-style-type' : 'none;'
}
}
];
I specified the element element : 'ul li', because 'ul' obviously targets the ul element but when 'li' is specified, I get nothing in the dropdown menu or applied to content.
Here's more or less the complete style that I'm trying to configure...
ul.greencheck li{
list-style-type:none;
line-height:18px;
background: url(/images/bullets/greencheck.png) no-repeat center left;
padding-left:30px;
}
Any help gratefully received.
'ul li' isn't a valid element, you can use either 'ul' or 'li' but not both
You should remove also the ending semicolon in the styles 'none;' isn't valid, 'none' is the correct one
and instead of setting the inline styles it would be better to just apply a class to the UL and leave the styles to a separate css file.

Passing url dynamically to the filebrowser button in ckeditor

I am customizing the functionality of ckeditor image upload. The user sees a dropdown with different options. Depending upon the option selected from the dropdown the "Browse Server" button should take the user to corresponding url.
So basically I need to dynamically pass the browse server url (which has chosen from a drop down list) to the filebrowser of Image Upload functionality of CK Editor 3.4.1 gem.
Example:
I am having a select box in the Image Info Tab for that I have added the following code.
{
type : 'select',
id : 'url_path',
items :
[
[ 'Add photos from My Computer', '' ],
[ 'Add photos from My Album', 'http://localhost:3000/pages/'],
],
onChange:function(){
L=this.getValue();
}
Browse Button code looks like this
{
type:'button',
id:'browse',
style:'display:inline-block;',
align:'center',
label:b.lang.common.browseServer,
hidden:true,
filebrowser :
{
action : 'Browse',
url : '',
target : 'info:txtUrl'
}
}
Here the url value has to set according to the value of select box. How can I configure that ?
Regards,
Pankaj

Form fields are shown before the layout is done in FF

I'm sorry for my bad english but I hope you will understand.
What's my problem....
I wrote a code to simple show the form which contains textfields, htmleditors, comboboxes, etc. Everything goes fine but in Firefox my fields appears before the form layout is done. so it looks quite weird because form fields overlaps other components.
sample code:
positionsPanel = new Ext.FormPanel({
margins : '2 2 2 0',
frame : true,
flex : 3,
labelWidth : 220,
buttonAlign : 'right',
labelAlign : 'top',
autoScroll : true,
height : oldFormPanelHeight, //this is ok, just a value
autoShow : true,
defaults : {
enableKeyEvents : true,
anchor : '97%'
},
items : [{...etc.
Have you any idea how to fix that? Thanks a lot...
remove flex: 3
Note: this config is only used when this Component is rendered by a Container which has been configured to use a BoxLayout.
By default (in your case also) FormPanel use 'form' layout

Resources