mirror of https://github.com/artf/grapesjs.git
nocodeframeworkdrag-and-dropsite-buildersite-generatortemplate-builderui-builderweb-builderweb-builder-frameworkwebsite-builderno-codepage-builder
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.0 KiB
3.0 KiB
SelectorManager
Selectors in GrapesJS are used in CSS Composer inside Rules and in Components as classes. To get better this concept let's take a look at this code:
span > #send-btn.btn{
...
}
<span>
<button id="send-btn" class="btn"></button>
</span>
In this scenario we get:
span -> selector of type tag
send-btn -> selector of type id
btn -> selector of type class
So, for example, being btn the same class entity it'll be easier to refactor and track things.
Before using methods you should get first the module from the editor instance, in this way:
var selectorManager = editor.SelectorManager;
Parameters
configObject Configurations
Examples
...
{
selectors: [
{name:'myselector1'},
...
],
states: [{
name: 'hover', label: 'Hover'
},{
name: 'active', label: 'Click'
}],
statesLabel: '- Selecte State -',
}
Returns this
add
Add a new selector to collection if it's not already exists. Class type is a default one
Parameters
Examples
var selector = selectorManager.add('selectorName');
// Same as
var selector = selectorManager.add('selectorName', {
type: 1,
label: 'selectorName'
});
Returns Model
addClass
Add class selectors
Parameters
Examples
sm.addClass('class1');
sm.addClass('class1 class2');
sm.addClass(['class1', 'class2']);
// -> [SelectorObject, ...]
Returns Array Array of added selectors
get
Get the selector by its name
Parameters
Examples
var selector = selectorManager.get('selectorName');
Returns (Model | null)
getAll
Get all selectors
Returns Collection