Issue #818Opened January 29, 2018by JulyanoF0 reactions

[QUESTION] Open different Panel's view on click text element

Question

How can I make "click" event on texts open different panel's view than StyleManager? I'm trying this:

var domComps = editor.DomComponents;
var textType = editor.DomComponents.getType('text');
  domComps.addType('text', {
    model: textType.model,
    view: textType.view.extend({
      events: {
        'click': function(){
            editor.Panels.getButton('views', 'editor').set('active', true)
        }
      },
    }),
  });
editor.Panels.addButton('views',{ 
    id: 'editorCK', 
    className: 'fa fa-bars',
    command: 'abrirEditor',
    attributes: { title: 'Some title'},
});

Answers (3)

artfJanuary 30, 20180 reactions

different panel's view than StyleManager

Probably you're talking about the behavior in the demo, implemented by the webpage preset here https://github.com/artf/grapesjs-preset-webpage/blob/master/src/panels/index.js#L106 So in your case, it'd be something like this:

editor.on('component:selected', () => {
	const selected = editor.getSelected();

	if (selected && selected.is('text')) {
		// do stuff
	}
});
JulyanoFJanuary 31, 20180 reactions

@artf so, I tried it and didn't work, it isn't setting active my panel button with id "editorCK"

editor.on('component:selected', () => {
	const selected = editor.getSelected();
    const openLayersBtn = editor.Panels.getButton('views', 'editorCK');
	if (selected && selected.is('text')) {
        if(!openLayersBtn || !openLayersBtn.get('active') && selected){
            const openSmBtn = editor.Panels.getButton('views', 'editorCK');
            openSmBtn && openSmBtn.set('active', 1);
        }
	}
});

image

artfJanuary 31, 20180 reactions

Did you create the abrirEditor command?

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.