CKEditor widgets (demos)과 같은 소리입니다.
다음 예제 (JSFiddle)를 참조하십시오. 위젯을 사용하여 문제를 해결하는 기본적인 방법을 알려줍니다. this official tutorial을 따르는 경우, 위젯에 편집 가능한 부품을 구현하는 방법과 대화 상자를 사용하여 편집하는 방법을 알게 될 것입니다.
// Some CSS for the widget to make it more visible.
CKEDITOR.addCss('.tagSpecialClass { background: green; padding: 3px; color: #fff } ');
CKEDITOR.replace('editor', {
// A clean-up in the toolbar to focus on essentials.
toolbarGroups: [
{ name: 'document', groups: [ 'mode' ] },
{ name: 'basicstyles' },
{ name: 'insert' }
],
removeButtons: 'Image,Table,HorizontalRule,SpecialChar',
extraPlugins: 'widget',
on: {
pluginsLoaded: function() {
var editor = this;
// Define a new widget. This should be done in a separate plugin
// to keep things clear and maintainable.
editor.widgets.add('sampleWidget', {
// This will be inserted into the editor if the button is clicked.
template: '<span class="tagSpecialClass">23</span>',
// A rule for ACF, which permits span.tagSpecialClass in this editor.
allowedContent: 'span(tagSpecialClass)',
// When editor is initialized, this function will be called
// for every single element. If element matches, it will be
// upcasted as a "sampleWidget".
upcast: function(el) {
return el.name == 'span' && el.hasClass('tagSpecialClass');
},
// This is what happens with existing widget, when
// editor data is returned (called editor.getData() or viewing source).
downcast: function(el) {
el.setHtml('{{birthYear}}');
},
// This could be done in upcast. But let's do it here
// to show that there's init function, which, unlike
// upcast, works on real DOM elements.
init: function() {
this.element.setHtml('23');
}
});
// Just a button to show that "sampleWidget"
// becomes a command.
editor.ui.addButton && editor.ui.addButton('SampleWidget', {
label: 'Some label',
command: 'sampleWidget',
toolbar: 'insert,0'
});
}
}
});
HTML
<textarea id="editor">
<p>Some text.</p>
<p>And there's the widget <span class="tagSpecialClass">{{birthYear}}</span></p>
<p>Some text <span class="tagSpecialClass">{{birthYear}}</span>.</p>
</textarea>
코딩
해피!
기본적으로 사용자가 수행하는 플러그인이 이미 있습니다. [placeholder plugin] (http://ckeditor.com/ckeditor_4.3_beta/samples/plugins/placeholder/placeholder.html)을보십시오. 텍스트 대체는하지 않지만 태그를 만드는 기본 아이디어를 보여줍니다. – epascarello