Merge pull request #201 from codex-team/add-update

Add content.clear and content.load methods
This commit is contained in:
George Berezhnoy 2017-08-30 14:29:47 +03:00 committed by GitHub
commit 30464668b9
4 changed files with 61 additions and 4 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -741,6 +741,63 @@ module.exports = (function (content) {
};
/**
* Clear editors content
*
* @param {Boolean} all if true, delete all article data (content, id, etc.)
*/
content.clear = function (all) {
editor.nodes.redactor.innerHTML = '';
editor.content.sync();
editor.ui.saveInputs();
if (all) {
editor.state.blocks = null;
} else if (editor.state.blocks) {
editor.state.blocks.items = [];
}
editor.content.currentNode = null;
};
/**
*
* Load new data to editor
* If editor is not empty, just append articleData.items
*
* @param articleData.items
*/
content.load = function (articleData) {
var currentContent = editor.state.blocks ? Object.assign({}, editor.state.blocks) : null;
editor.content.clear();
if (!currentContent) {
editor.state.blocks = articleData;
} else if (!currentContent.items) {
currentContent.items = articleData.items;
editor.state.blocks = currentContent;
} else {
currentContent.items = currentContent.items.concat(articleData.items);
editor.state.blocks = currentContent;
}
editor.renderer.makeBlocksFromData();
};
return content;
})({});

View file

@ -1,6 +1,6 @@
{
"name": "codex.editor",
"version": "1.7.5",
"version": "1.7.6",
"description": "Codex Editor. Native JS, based on API and Open Source",
"main": "index.js",
"scripts": {