wordcount.js 984 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 = {
  25. "16": 1,
  26. "18": 1,
  27. "20": 1,
  28. "37": 1,
  29. "38": 1,
  30. "39": 1,
  31. "40": 1
  32. };
  33. if (code in ignores) return;
  34. clearTimeout(timer);
  35. timer = setTimeout(function() {
  36. me.fireEvent("wordcount");
  37. }, 200);
  38. });
  39. });
  40. };