Skip to content

Commit

Permalink
Re-use card blocks from a previous render
Browse files Browse the repository at this point in the history
  • Loading branch information
mixonic committed Jun 24, 2015
1 parent ca43198 commit 6dd5a69
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/js/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ Editor.prototype.renderBlockAt = function(index, replace) {
var dom = document.createElement('div');
dom.innerHTML = html;
var newEl = dom.firstChild;
newEl.dataset.modelIndex = index;
var sibling = this.element.children[index];
if (replace) {
this.element.replaceChild(newEl, sibling);
Expand All @@ -275,13 +276,18 @@ Editor.prototype.syncContentEditableBlocks = function() {
var blockElements = toArray(this.element.children);
var len = blockElements.length;
var updatedModel = [];
var i, blockEl;
var i, block, blockEl;
for (i = 0; i < len; i++) {
blockEl = blockElements[i];
if(blockEl.isContentEditable) {
updatedModel.push(this.compiler.parser.serializeBlockNode(blockEl));
} else {
updatedModel.push(nonTextBlocks.shift());
if (blockEl.dataset.modelIndex) {
block = this.model[blockEl.dataset.modelIndex];
updatedModel.push(block);
} else {
updatedModel.push(nonTextBlocks.shift());
}
}
}
this.model = updatedModel;
Expand Down

0 comments on commit 6dd5a69

Please sign in to comment.