Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Better function to make sure we have a root note
Browse files Browse the repository at this point in the history
Conflicts:

	Source/MooEditable/MooEditable.js
  • Loading branch information
cheeaun committed Nov 15, 2009
1 parent 1a69cb2 commit fdfb1af
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Source/MooEditable/MooEditable.js
Expand Up @@ -456,19 +456,30 @@ this.MooEditable = new Class({
},

setContent: function(newContent){
if(newContent.charAt(0) != '<') newContent = '<' + this.options.rootElement + '>' + newContent + '</' + this.options.rootElement + '>';
this.doc.body.set('html', newContent);
this.doc.body.set('html', this.ensureRootElement(newContent));
return this;
},

saveContent: function(){
if (this.mode == 'iframe'){
var val = this.getContent();
if(val.charAt(0) != '<') val = '<' + this.options.rootElement + '>' + val + '</' + this.options.rootElement + '>';
this.textarea.set('value', val);
this.textarea.set('value', this.ensureRootElement(this.getContent()));
}
return this;
},

ensureRootElement: function(val){
if (this.options.rootElement && val.charAt(0) != '<'){
var end = val.length - 1;
if (val.indexOf('<div') != -1){
end = val.indexOf('<div');
}
if(val.indexOf('<p') != -1 && val.indexOf('<p') < end){
end = val.indexOf('<p');
}
val = '<' + this.options.rootElement + '>' + val.substr(0,end) + '</' + this.options.rootElement + '>' + val.substr(end);
}
return val;
},

checkStates: function(){
var element = this.selection.getNode();
Expand Down

0 comments on commit fdfb1af

Please sign in to comment.