By default, CKEditor's enter key behavior is adding a <p> tag and starting a new paragraph. But that behavior can be modified in the configuration with a .EnterMode parameter.
I'm wondering if there is a way to change Enter key behavior in the runtime, by putting a button into its tool bar, to switch between <p> and <br> (single line vs double line), just like as in Word.
Any ideas on how to do this?
Save the following to editor_dir/plugins/entermode/plugin.js:
'use strict';
(function() {
CKEDITOR.plugins.add( 'entermode', {
icons: 'entermode',
init: function( editor ) {
var enterP = new enterModeCommand( editor, CKEDITOR.ENTER_P );
var enterBR = new enterModeCommand( editor, CKEDITOR.ENTER_BR );
editor.addCommand( 'entermodep', enterP );
editor.addCommand( 'entermodebr', enterBR );
if ( editor.ui.addButton ) {
editor.ui.addButton( 'EnterP', {
label: 'Enter mode P',
command: 'entermodep',
toolbar: 'paragraph,10'
});
editor.ui.addButton( 'EnterBR', {
label: 'Enter mode BR',
command: 'entermodebr',
toolbar: 'paragraph,20'
});
}
editor.on( 'dataReady', function() {
refreshButtons( editor );
});
}
});
function refreshButtons( editor ) {
editor.getCommand( 'entermodep' ).setState(
editor.config.enterMode == CKEDITOR.ENTER_P ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
editor.getCommand( 'entermodebr' ).setState(
editor.config.enterMode == CKEDITOR.ENTER_BR ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
}
function enterModeCommand( editor, mode ) {
this.mode = mode;
}
enterModeCommand.prototype = {
exec: function( editor ) {
editor.config.enterMode = this.mode;
refreshButtons( editor );
},
refresh: function( editor, path ) {
refreshButtons( editor );
}
};
})();
Now add the following to toolbar.css in your skin file:
.cke_button__enterp_icon, .cke_button__enterbr_icon { display: none !important; }
.cke_button__enterp_label, .cke_button__enterbr_label { display: inline !important; }
...or paint some icons, if you want.
Enable the plugin when running the editor:
CKEDITOR.replace( 'id', { extraPlugins: 'entermode' } );
Now you can control config.enterMode from the toolbar.
Related
I want to have a keystroke to (de)activate the list styles (ul and ol).
In general I know how to customize keystrokes via plugin to activate i.e. H1 or P or PRE,...
Unfortunately that does nothing when using with UL or OL OR LI
( function() {
CKEDITOR.plugins.add( 'keystrokes2', {
init: function( editor ) {
editor.addCommand( 'ulist', {
exec: function( editor ) {
var format = { element: 'h1' };
var style = new CKEDITOR.style(format);
style.apply(editor.document);
}
} );
editor.setKeystroke( CKEDITOR.CTRL + CKEDITOR.ALT + 76 , 'ulist' );
}
});
} )();
In my application, I've a huge map on the dashboard and there I'm placing markers when ajax content is loaded. Each marker has specifically designed infobox where I've a link that has two clases:
tooltip
fancybox
On mouseover, I expect the tooltip opened and on mouseout I expect it to be closed and on click I expect three things:
the infobox to be closed
the fancybox to be opened
the tooltip to be closed
The problem is that on mouseover and mouseout, the tooltip acts as expected but when I click on the link, the infobox closes, the fancybox opens but the tooltip doesn't close and it looses the parent connection and never closes.
Here are my codes:
var infowindow_options = {
content: '...<a class="bind_tooltip">...</a>...',
disableAutoPan: false,
maxWidth: 0,
alignBottom: true,
pixelOffset: new google.maps.Size( 10, 10 ),
zIndex: null,
boxClass: 'info_window',
closeBoxMargin: '10px 10px 0 0',
closeBoxURL: 'http://www.google.com/intl/en_us/mapfiles/close.gif',
pane: 'floatPane',
enableEventPropagation: true,
infoBoxClearance: '10px',
position: mrkr.position
};
google.maps.event.addListener( mrkr, 'click', function() {
infowindow ? infowindow.close() : '';
infowindow = new InfoBox( infowindow_options );
infowindow.open( map );
return false;
} );
google.maps.event.addListener( map, 'click', function() {
if( infowindow ) {
infowindow.close();
$( '.bind_tooltip' ).tooltip( 'close' );
}
return false;
} );
$( document ).tooltip( {
items: '.bind_tooltip',
content: function() {
return $( this ).parent().find( '.tooltip' ).html();
},
position: {my: 'left top+10', at: 'center center'}
} );
Also I get this error:
Error: cannot call methods on tooltip prior to initialization; attempted to call method 'close'
Initialize the tooltip before using it anywhere else in the script. You better do it at the beginning of script.
var infowindow_options = {
content: '...<a class="bind_tooltip">...</a>...',
disableAutoPan: false,
maxWidth: 0,
alignBottom: true,
pixelOffset: new google.maps.Size( 10, 10 ),
zIndex: null,
boxClass: 'info_window',
closeBoxMargin: '10px 10px 0 0',
closeBoxURL: 'http://www.google.com/intl/en_us/mapfiles/close.gif',
pane: 'floatPane',
enableEventPropagation: true,
infoBoxClearance: '10px',
position: mrkr.position
};
google.maps.event.addListener( mrkr, 'click', function() {
infowindow ? infowindow.close() : '';
infowindow = new InfoBox( infowindow_options );
infowindow.open( map );
return false;
} );
$( document ).tooltip( {
items: '.bind_tooltip',
content: function() {
return $( this ).parent().find( '.tooltip' ).html();
},
position: {my: 'left top+10', at: 'center center'}
} );
google.maps.event.addListener( map, 'click', function() {
if( infowindow ) {
infowindow.close();
$( '.bind_tooltip' ).tooltip( 'close' );
}
return false;
} );
Initializing tooltip at the beginning didn't solve my problem. So I've solved the problem this way. I've added earlier a block of code that when click on map the infowinfow should close. That's why I was loosing my infowinfow reference. So removing the auto close solved my problem.
I have created plugins before but i must be missing something simple.
I have gone back to the tutorial and trying to add a very simple plugin. code below:
I do not get an error on the console and i do not see the icon in the editor
Any help would be greatly appreciated
In my PHP i have
CKEDITOR.replace( 'editor1',
{
toolbar : 'MyToolbar',
customConfig : '/admin/ckeditor/my_config.js?v=5.1',
height : '400px',
});
my_config.js looks like ::
CKEDITOR.editorConfig = function( config ){
config.enterMode = CKEDITOR.ENTER_BR;
fullPage : true;
extraPlugins : 'pdf';
config.toolbar = 'MyToolbar';
config.toolbar_MyToolbar =
[
{ name: 'document', items : [ 'Source' ] },
{ name: 'tools', items : [ 'Maximize', 'ShowBlocks','-','About','Pdf' ] }
];
};
and the dir structure in the plugins dir is:
ckeditor
-->plugins
------>pdf
--------->images
------------>pdf.png
--------->plugin.js
and plugin.js looks like:
CKEDITOR.plugins.add( 'pdf',
{
init: function( editor )
{
editor.addCommand( 'insertPdf',
{
exec : function( editor )
{
var timestamp = new Date();
editor.insertHtml( 'The current date and time is: <em>' + timestamp.toString() + '</em>' );
}
});
editor.ui.addButton( 'Pdf',
{
label: 'Insert PDF',
command: 'insertPdf',
icon: this.path + 'images/pdf.png'
} );
}
} );
found the problem.
in the my_config.js i had
extraPlugins : 'pdf';
instead of
config.extraPlugins = 'pdfs';
I want to add a button in toolbar of CKEditor but button is not appearing.This is code for creation of plugin saved in _source/plugins/footnote/
CKEDITOR.plugins.add('footnote',
{
init: function(editor)
{
var pluginName = 'footnote';
CKEDITOR.dialog.add(pluginName, this.path + 'dialogs/footnote.js');
editor.addCommand(pluginName, new CKEDITOR.dialogCommand(pluginName));
editor.ui.addButton('Footnote',
{
label: 'Footnote or Citation',
command: pluginName
});
}
});
And this is code of config.js
CKEDITOR.editorConfig = function( config )
{
config.toolbar = 'MyToolbar';
config.extraPlugins = 'footnote';
config.toolbar_MyToolbar =
[
['Bold','Footnote','Italic']
];
};
Just bold and italic are appearing in toolbar.But footnote button is not appearing.
Thanks for your help.
You are not providing an icon:
CKEDITOR.plugins.add('footnote',
{
icons: 'myfootnote',
init: function (editor) {
var pluginName = 'footnote';
CKEDITOR.dialog.add(pluginName, this.path + 'dialogs/footnote.js');
editor.addCommand(pluginName, new CKEDITOR.dialogCommand(pluginName));
editor.ui.addButton('Footnote',
{
label: 'Footnote or Citation',
icon: 'myfootnote',
command: pluginName
});
}
});
Be sure to create an icon at /plugins/footnote/icons/myfootnote.png.
Only PNGs are accepted.
The button must have the same name (case sensitive).
Thus replace editor.ui.addButton('Footnote', by editor.ui.addButton('footnote',
I want to override the image plugin in CKeditor. When I right click on an image I want to open my own dialog. Can anyone point me in the right direction. I've done a basic plugin which I copied from the CKeditor site - How do I swap this to replace the image editor.
CKEDITOR.plugins.add('myplugin',
{
init: function (editor) {
editor.addCommand('mydialog', new CKEDITOR.dialogCommand('mydialog'));
if (editor.contextMenu) {
editor.addMenuGroup('mygroup', 10);
editor.addMenuItem('My Dialog',
{
label: 'Open dialog',
command: 'mydialog',
group: 'mygroup'
});
editor.contextMenu.addListener(function (element) {
return { 'My Dialog': CKEDITOR.TRISTATE_OFF };
});
}
CKEDITOR.dialog.add('mydialog', function (api) {
// CKEDITOR.dialog.definition
var dialogDefinition =
{
title: 'Sample dialog',
minWidth: 390,
minHeight: 130,
contents: [
{
id: 'tab1',
label: 'Label',
title: 'Title',
expand: true,
padding: 0,
elements:
[
{
type: 'html',
html: '<p>This is some sample HTML content.</p>'
},
{
type: 'textarea',
id: 'textareaId',
rows: 4,
cols: 40
}
]
}
],
buttons: [CKEDITOR.dialog.okButton, CKEDITOR.dialog.cancelButton],
onOk: function () {
// "this" is now a CKEDITOR.dialog object.
// Accessing dialog elements:
var textareaObj = this.getContentElement('tab1', 'textareaId');
alert("You have entered: " + textareaObj.getValue());
}
};
return dialogDefinition;
});
}
});
Hi the reason I wanted to do this was that we have our image editor control which for "usability" reasons we need to carry on using. It gets used in different bits of the site and two dialogs would confuse people. In summary what I did was
Remove the image plugin CKEDITOR.config.removePlugins = 'image, forms, div,flash,iframe,table';
Add extra plugins extraPlugins: 'tinsertimage,teditimage,teditlink,tinsertlink,teditimagelink' on creating the CKEditor
In the plugin run some JS which intercept the right click on the image
CKEDITOR.plugins.add('teditimage',
{
init: function (editor) {
editor.addCommand('tEditImage',
{
exec: function (editor) {
//This opens the custom editor
ZWSInlineEditor.openImageProperties(editor, false);
}
});
if (editor.addMenuItem) {
// A group menu is required
// order, as second parameter, is not required
editor.addMenuGroup('gImage');
// Create a manu item
editor.addMenuItem('gEditImageItem', {
label: 'Edit Image Properties',
command: 'tEditImage',
group: 'gImage'
});
}
if (editor.contextMenu) {
editor.contextMenu.addListener(function (element, selection) {
// Get elements parent, strong parent first
var parents = element.getParents("img");
// Check if it's strong
if (parents[0].getName() != "img")
return null; // No item
return { gEditImageItem: CKEDITOR.TRISTATE_ON };
});
}
}
});
I don't understand what's the point in what you're doing (or please explain us). Maybe you should rather customize dialogs than do things from scratch?