grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

[RePost] Add command on dropping block from blockmanager

Open blackbirdzzz opened this issue 9 years ago • 4 comments

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
 },
});

blackbirdzzz avatar Sep 07 '17 13:09 blackbirdzzz

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();
}

artf avatar Sep 08 '17 20:09 artf

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 avatar May 18 '18 05:05 selwynshen

@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();

artf avatar May 23 '18 20:05 artf

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.

lock[bot] avatar Sep 17 '19 15:09 lock[bot]