Issue #382Opened October 5, 2017by mekamleshk0 reactions

Store the html and inline css in Editor.Store()

Question

I am trying to store the html and inline css , can you please in how to pass it to editor.store() function. @artf

editor.Commands.add`
        ('save-db',
        {
            run: function(editor, sender)
            {
              sender && sender.set('active'); // turn off the button
              var html = editor.runCommand('gjs-get-inlined-html');
              editor.store();
              alert('Draft');
              console.log(html);

              editor.on('storage:store', function(e) {
                    console.log('Stored ', e);
              });         
            }
        });

Answers (3)

sonnylloydOctober 5, 20170 reactions

@mekamleshk editor.store() function gets the html, components, css, html and styles and passes it to storage:store event and you can access it like you have above

im sorry if i have miss understood what your asking but it looks like your trying to add a save button

the save button

editor.Panels.addButton('options', [{
               id: 'save',
                    className: 'fa fa-floppy-o icon-blank',
                    command: function (editor, sender) {
                        if (sender)
                            sender.set('active', false);
                        editor.store();
                    },
                    attributes: {title: 'save to database'}
                }]);

the store event

editor.on('storage:store', function (e) {
                console.log('STORE ', e);
                console.log('HTML', e.html);
                console.log('CSS', e.css);
            });

you can use grapejs's build in remote storage feature if you want to post these values to a backend

in the grapejs init you will want something like this

storageManager: {
                            type: 'remote',
                            urlStore: 'http://mywebsite.com/store/website',
                            contentTypeJson: true,
                        },

this will post a json string to the backend

mekamleshkOctober 5, 20170 reactions

Please recheck my code i have updated it. @sonnylloyd @artf I want to store inline html

var html = editor.runCommand('gjs-get-inlined-html');

into mysql database using editor.store() function

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.