[英]CKEditor5 Custom Modal Plugin
我遵循了最初的插件教程,并使“图像插入”正常工作,但是我想显示一个具有两个输入字段的自定义模式,而不是提示您设置更多属性。 我如何最好地实现这一点?
我知道如何在普通的JS / CSS中实现普通模态,但是对于将HTML模态显示在按钮单击上的位置,我有些困惑。
class Test extends Plugin {
init() {
editor = this.editor
editor.ui.componentFactory.add('SampleView', (locale) => {
const view = new ButtonView(locale)
view.set({
label: 'test',
icon: imageIcon,
tooltip: true
})
view.on('execute', () => {
//here I would like to open the modal instead of the prompt
})
})
}
}
例如,您可以尝试使用SweetAlert2 ,它是零依赖性纯JavaScript替代默认弹出窗口。
import swal from 'sweetalert2';
...
view.on( 'execute', () => {
swal( {
input: 'text',
inputPlaceholder: 'Your image URL'
} )
.then ( result => {
editor.model.change( writer => {
const imageElement = writer.createElement( 'image', {
src: result.value
} );
editor.model.insertContent( imageElement, editor.model.document.selection );
} );
} )
} );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.