DeviceManager

You can customize the initial state of the module from the editor initialization, by passing the following Configuration Object

const editor = grapesjs.init({
 deviceManager: {
   // options
 }
})

Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance

const deviceManager = editor.DeviceManager;

add

Add new device to the collection. URLs are supposed to be unique

Parameters

  • idString Device id
  • widthString Width of the device
  • optsObject? Custom options (optional, default {})

Examples

deviceManager.add('tablet', '900px');
deviceManager.add('tablet2', '900px', {
 height: '300px',
 // At first, GrapesJS tries to localize the name by device id.
 // In case is not found, the `name` property is used (or `id` if name is missing)
 name: 'Tablet 2',
 widthMedia: '810px', // the width that will be used for the CSS media
});

Returns Device Added device

get

Return device by name

Parameters

Examples

var device = deviceManager.get('Tablet');
console.log(JSON.stringify(device));
// {name: 'Tablet', width: '900px'}

getAll

Return all devices

Examples

var devices = deviceManager.getAll();
console.log(JSON.stringify(devices));
// [{name: 'Desktop', width: ''}, ...]

Returns Collection

Last Updated: 11/4/2019, 12:14:53 AM