2011-09-30 71 views
1

从此后面的:TinyMCE editor fixed size with no scrollers?tinyMCE:删除最后插入的代码

如何删除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 
      } 
}); 

}, 

所以,如果身高是156或更高,它应该删除你刚输入的内容(代码)。

我怎样才能做到这一点?

+0

+1很好的问题 – Thariama

回答

0

我做了一些测试,这就是我想出了:

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'); 
     } 
    }); 
}, 
+0

这个工程初步!谢谢..只有如果出现这样的情况:如果你写到极限(它通常扩展的地方),那么滚动条会出现在限制之前,所以你可以看到滚动条。但是它没关系,我可以忍受它。再一次感谢你!我确定还有其他人也会为此感谢你的关于这个滚轮: – Karem

+0

我唯一想到的就是设置“overflow-y:scroll;”在编辑器body元素上(使用content_css设置来实现这一点)。这将显示卷轴永远不会刺激用户。 – Thariama