Created
October 28, 2019 07:02
-
-
Save anish2690/408b808d1574bc1096e82038b12d3d20 to your computer and use it in GitHub Desktop.
save grapesjs data as json and load data as json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var editor = grapesjs.init | |
({ | |
height: '100%', | |
fromElement: 1, | |
clearOnRender: true, | |
container : '#gjs', | |
plugins: ['gjs-preset-newsletter'], | |
storageManager: { | |
autosave: false, | |
setStepsBeforeSave: 1, | |
type: 'remote', | |
urlStore: 'http://cimailer.dev/templates/template', | |
urlLoad: 'http://cimailer.dev/templates/template', | |
contentTypeJson: true, | |
}, | |
}); | |
editor.Panels.addButton | |
('options', | |
[{ | |
id: 'save-db', | |
className: 'fa fa-floppy-o', | |
command: 'save-db', | |
attributes: {title: 'Save DB'} | |
}] | |
); | |
// Add the command | |
editor.Commands.add | |
('save-db', { | |
run: function(editor, sender) | |
{ | |
sender && sender.set('active'); // turn off the button | |
editor.store(); // extract data | |
} | |
}); | |
// to load data inital | |
editor.setComponents(JSON.parse(value.components)); | |
editor.setStyle(JSON.parse(value.styles)); | |
editor.on('storage:load', function(e) { console.log('Loaded ', e);}); | |
editor.on('storage:store', function(e) { console.log('Stored ', e);}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment