wordcount.js 959 B

123456789101112131415161718192021222324252627282930313233
  1. ///import core
  2. ///commands 字数统计
  3. ///commandsName WordCount,wordCount
  4. ///commandsTitle 字数统计
  5. /*
  6. * Created by JetBrains WebStorm.
  7. * User: taoqili
  8. * Date: 11-9-7
  9. * Time: 下午8:18
  10. * To change this template use File | Settings | File Templates.
  11. */
  12. UE.plugins['wordcount'] = function(){
  13. var me = this;
  14. me.setOpt('wordCount',true);
  15. me.addListener('contentchange',function(){
  16. me.fireEvent('wordcount');
  17. });
  18. var timer;
  19. me.addListener('ready',function(){
  20. var me = this;
  21. domUtils.on(me.body,"keyup",function(evt){
  22. var code = evt.keyCode||evt.which,
  23. //忽略的按键,ctr,alt,shift,方向键
  24. ignores = {"16":1,"18":1,"20":1,"37":1,"38":1,"39":1,"40":1};
  25. if(code in ignores) return;
  26. clearTimeout(timer);
  27. timer = setTimeout(function(){
  28. me.fireEvent('wordcount');
  29. },200)
  30. })
  31. });
  32. };