admin管理员组文章数量:1327967
I use inline Ckeditor
to edit content. By default, the inline editor is activated by double click a div
with contenteditable="true"
. I want to activate this inline editor when I click a button, and hide it when I click another button.
Here is an example of html code:
<html>
<head>
<script src="ckeditor/ckeditor.js"></script>
</head>
<body>
<div id="first" contenteditable="true">first</div>
<div id="second" contenteditable="true">second</div>
<input type="button" value="show inline editor">
<input type="button" value="hide inline editor">
</body>
</html>
Jsfiddle shows the default behavior and what i want to have /
I use inline Ckeditor
to edit content. By default, the inline editor is activated by double click a div
with contenteditable="true"
. I want to activate this inline editor when I click a button, and hide it when I click another button.
Here is an example of html code:
<html>
<head>
<script src="ckeditor/ckeditor.js"></script>
</head>
<body>
<div id="first" contenteditable="true">first</div>
<div id="second" contenteditable="true">second</div>
<input type="button" value="show inline editor">
<input type="button" value="hide inline editor">
</body>
</html>
Jsfiddle shows the default behavior and what i want to have http://jsfiddle/vdRYL/
Share Improve this question edited Dec 8, 2013 at 0:56 user2265529 asked Dec 8, 2013 at 0:28 user2265529user2265529 4791 gold badge8 silver badges19 bronze badges 2- It will be easy for us to solve this issue if you could create a jsfiddle(jsfiddle) showing the default behaviour of Ckeditor. – Nagendra Rao Commented Dec 8, 2013 at 0:39
- Thank you for your reply and for editing. Here is the jsfiddle: jsfiddle/vdRYL – user2265529 Commented Dec 8, 2013 at 0:54
4 Answers
Reset to default 2We can hide and show toolbar. I have achieved this functionality using following way:
Open ckeditor.js
file. And paste below code at the end of the file
$(document).ready(function () {
CKEDITOR.on('instanceReady', function (ev) {
document.getElementById(ev.editor.id + '_top').style.display = 'none';
ev.editor.on('focus', function (e) {
document.getElementById(ev.editor.id + '_top').style.display = 'block';
});
ev.editor.on('blur', function (e) {
document.getElementById(ev.editor.id + '_top').style.display = 'none';
});
});
});
The CKeditor seems to be activating the editor-window on focus
of contenteditable
element and not on double-click
.
You can do something like this to get your buttons to work,
http://jsfiddle/nagendra_rao/vdRYL/1/
You can use focusManager.blur(true)
in order to hide the toolbar.
http://jsfiddle/vdRYL/24/
var cke = CKEDITOR.inline('target');
var btnClose = document.getElementById('btnClose');
btnClose.addEventListener('click', function(event){
cke.focusManager.blur(true);
});
More info on focusManager here: http://docs.ckeditor./#!/api/CKEDITOR.focusManager-method-blur
For Angular
The toolbar element has class "ck-editor__top", so i used below code to hide / display it:
ponent.html
added to 'ckeditor' tag below 3 listeners:
<ckeditor
(ready)="changeEditorToolbar('none')"
(focus)="changeEditorToolbar('block')"
(blur)="changeEditorToolbar('none')"
>
</ckeditor>
ponent.ts
changeEditorToolbar(displayValue)
{
let elements = Array.from(document.getElementsByClassName('ck-editor__top') as HTMLCollectionOf<HTMLElement>);
elements[0].style.display = displayValue;
}
Note:
Pay attention, if you have multiple ck editors in the same ponent, you should not use [0] to get the first one
本文标签: javascriptCkeditor show and hide inline toolbar on demandStack Overflow
版权声明:本文标题:javascript - Ckeditor: show and hide inline toolbar on demand - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742224093a2435689.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论