Browse Source

Fix loading with autoload but without the storage

pull/1035/head
Artur Arseniev 8 years ago
parent
commit
3775f8fa2d
  1. 2
      src/css_composer/index.js
  2. 2
      src/editor/model/Editor.js
  3. 25
      src/storage_manager/index.js
  4. 30
      test/specs/grapesjs/index.js

2
src/css_composer/index.js

@ -138,7 +138,7 @@ module.exports = () => {
if (isArray(obj)) {
obj.length && rules.reset(obj);
} else {
} else if (obj) {
rules.reset(obj);
}

2
src/editor/model/Editor.js

@ -93,7 +93,7 @@ module.exports = Backbone.Model.extend({
clb && clb();
};
if (sm && sm.getConfig().autoload) {
if (sm && sm.canAutoload()) {
this.load(postLoad);
} else {
postLoad();

25
src/storage_manager/index.js

@ -54,6 +54,14 @@ module.exports = () => {
return this;
},
/**
* Get configuration object
* @return {Object}
* */
getConfig() {
return c;
},
/**
* Checks if autosave is enabled
* @return {Boolean}
@ -220,12 +228,21 @@ module.exports = () => {
},
/**
* Get configuration object
* @return {Object}
* Get current storage
* @return {Storage}
* */
getCurrentStorage() {
return this.get(this.getCurrent());
},
/**
* Check if autoload is possible
* @return {Boolean}
* @private
* */
getConfig() {
return c;
canAutoload() {
const storage = this.getCurrentStorage();
return storage && this.getConfig().autoload;
}
};
};

30
test/specs/grapesjs/index.js

@ -37,7 +37,7 @@ describe('GrapesJS', () => {
storageManager: {
autoload: 0,
autosave: 0,
type: ''
type: 0
}
};
obj = grapesjs;
@ -141,25 +141,19 @@ describe('GrapesJS', () => {
).toEqual('test2');
});
it.skip('Init editor from element', () => {
it('Init editor from element', () => {
config.fromElement = 1;
fixtures.innerHTML = documentEl;
var editor = obj.init(config);
var html = editor.getHtml();
var css = editor.getCss();
var protCss = editor.getConfig().protectedCss;
/*
(html ? html : '').should.equal(htmlString);
(css ? css : '').should.equal(protCss + '.test2{color:red;}');// .test3 is discarded in css
editor.getComponents().length.should.equal(2);
editor.getStyle().length.should.equal(2);
*/
expect(html ? html : '').toEqual(htmlString);
config.storageManager = { type: 0 };
fixture.innerHTML = documentEl;
const editor = obj.init(config);
const html = editor.getHtml();
const css = editor.getCss();
const protCss = editor.getConfig().protectedCss;
expect(html).toEqual(htmlString);
expect(editor.getComponents().length).toEqual(2);
// .test3 is discarded in css
expect(css ? css : '').toEqual(protCss + '.test2{color:red;}');
// bust is still here
// .test3 is discarded in CSS
expect(css).toEqual(`${protCss}.test2{color:red;}`);
// but it's still there
expect(editor.getStyle().length).toEqual(2);
});

Loading…
Cancel
Save