tinyMCE: Remove last inserted code
Foll开发者_如何学JAVAowing from this: TinyMCE editor fixed size with no scrollers?
How can I remove the last inserted code in tinyMCE?
setup : function(ed){
ed.onKeyDown.add(function (ed, evt) {
var currentfr=document.getElementById(ed.id + '_ifr');
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight + 26;
}
else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
}
if( currentfr.height >= 156 ){
// Remove last inserted code here
}
});
},
So if the height is 156 or more, it should remove what you just typed (code).
How can i do this?
I made a few tests and this is what i came up with:
setup : function(ed){
ed.onKeyDown.add(function (ed, evt) {
var currentfr=document.getElementById(ed.id + '_ifr');
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight + 26;
}
else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
}
if (evt.keyCode != 8 && evt.keyCode != 46 && currentfr.height < 156){
ed.bookmark = ed.selection.getBookmark(2,true);
ed.latest_content = ed.getContent({format:'raw'});
}
});
ed.onKeyUp.add(function (ed, evt) {
var currentfr=document.getElementById(ed.id + '_ifr');
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) { //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight + 26;
}
else if (currentfr.Document && currentfr.Document.body.scrollHeight) { //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
}
if( currentfr.height >= 156 && evt.keyCode != 8 && evt.keyCode != 46){
// Remove last inserted code here
// save and reset the caret using a bookmark
ed.setContent(ed.latest_content);
ed.selection.moveToBookmark(ed.bookmark);
ed.execCommand('mceCleanup');
}
});
},
精彩评论