Skip to content

Commit

Permalink
separate editor initialization from finding track tags, needed for re…
Browse files Browse the repository at this point in the history
…altime collaborative environments, see #90
  • Loading branch information
johanneswilm committed Dec 4, 2013
1 parent 9e8ff56 commit 61801e2
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/ice.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@

this.initializeEnvironment();
this.initializeEditor();
this.findTrackTags();
this.initializeRange();

this.pluginsManager.fireEnabled(this.element);
Expand Down Expand Up @@ -172,25 +173,32 @@
},

/**
* Initializes the content in the editor - cleans non-block nodes found between blocks and
* initializes the editor with any tracking tags found in the editing element.
* Initializes the content in the editor - cleans non-block nodes found between blocks.
*/
initializeEditor: function () {
// Clean the element html body - add an empty block if there is no body, or remove any
// content between elements.
var self = this,
body = this.env.document.createElement('div');
var body = this.env.document.createElement('div');
if (this.element.childNodes.length) {
body.innerHTML = this.element.innerHTML;
ice.dom.removeWhitespace(body);
if (body.innerHTML === '') body.appendChild(ice.dom.create('<' + this.blockEl + ' ><br/></' + this.blockEl + '>'));
} else {
body.appendChild(ice.dom.create('<' + this.blockEl + ' ><br/></' + this.blockEl + '>'));
}
this.element.innerHTML = body.innerHTML;
if (this.element.innerHTML != body.innerHTML) {
this.element.innerHTML = body.innerHTML;
}

},

/*
* Updates the list of changes to include all track tags found inside the element.
*/
findTrackTags: function () {

// Grab class for each changeType
var changeTypeClasses = [];
var self = this, changeTypeClasses = [];
for (var changeType in this.changeTypes) {
changeTypeClasses.push(this._getIceNodeClass(changeType));
}
Expand Down

0 comments on commit 61801e2

Please sign in to comment.