[RePost] Add command on dropping block from blockmanager
Hi , artf
You told me to see this code too add a command while dropping a block from blockmanager but i don't really understand, what i need to in the "..." that you wrote about (model) , and what i need to do after dostuff() , can you jsut give me a pice of code without ... that can help me a lot i don't understand when you place some (...).
Thanks a lot artf !!!
editor.DomComponents.addType('custom-type', {
model: {...},
view: defaultView.extend({
init() {
this.listenTo(this.model, 'active', this.doStuff); // listen for active event
},
doStuff() {...}
}),
});
blockManager.add('test-block', {
label: 'Label',
content: {
type: 'custom-type',
activeOnRender: 1, // <- this will trigger the active event
},
});
To understand what to do with the model you have to read this Components, I've just put dots because I supposed you've already read that part. About doStuff it's just up to you
doStuff() {
// Open the modal
const modal = this.em.get('Model');
modal.setTitle('Title');
modal.setContent('Your content');
modal.open();
}
Hi , artf
How can I bind event to this button. Say, I'd like to click this 'test' button to set properties on the block I've added. Could you give an example? Thanks.
doStuff() {
// Open the modal
const modal = this.em.get('Model');
modal.setTitle('Title');
modal.setContent('<div><input type="button" value="test" /></div>');
modal.open();
}
@selwynshen you can pass HTMLElements to setContent if you want
const btn = document.createElement('button');
btn.innerHTML = 'Test';
btn.onclick = () => {
alert('Do stuff');
// ...
};
editor.Modal.setTitle('Title').setContent(btn).open();
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.