I have a custom PlugIn that adds a button to the tool bar and on the click of that I want to add a button in my ckeditor5 Content, that on clicking will give me an alert.
I tried creating the element of button, but it get sanitized, I have tried using General HTML support to avoid sanitization, but the button comes in the span of General Html Support and is for preview only, I am working in angular 17. Help is appreicated!
Here is my Custom PlugIn
editor.ui.componentFactory.add(‘dropdownButton’, locale => {
const view = new ButtonView(locale);
view.set({
label: 'Click me',
tooltip: true,
class: 'custom-button' // Assigning class custom-button to the button
});
// Handle click event
view.on('execute', () => {
const buttonHtml = '<button class="responsive-button">Test</button>';
const button = new ButtonView();
button.set( {
label : 'Test',
tooltip: true,
class: 'responsive-button'
} );
//Insert HTML directly into the editor
editor.model.change(writer => {
const viewFragment = editor.data.processor.toView(buttonHtml);
const modelFragment = editor.data.toModel(viewFragment);
// Insert the button at the current selection position
editor.model.insertContent(modelFragment, editor.model.document.selection);
});
});
return view;
});
Walli CureMD is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.