limiter.js 717 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. (function($)
  2. {
  3. $.Redactor.prototype.limiter = function()
  4. {
  5. return {
  6. init: function()
  7. {
  8. if (!this.opts.limiter) return;
  9. this.$editor.on('keydown.redactor-limiter', $.proxy(function(e)
  10. {
  11. var key = e.which;
  12. var ctrl = e.ctrlKey || e.metaKey;
  13. if (key == this.keyCode.BACKSPACE
  14. || key == this.keyCode.DELETE
  15. || key == this.keyCode.ESC
  16. || key == this.keyCode.SHIFT
  17. || (ctrl && key == 65)
  18. || (ctrl && key == 82)
  19. || (ctrl && key == 116)
  20. )
  21. {
  22. return;
  23. }
  24. var count = this.$editor.text().length;
  25. if (count >= this.opts.limiter)
  26. {
  27. return false;
  28. }
  29. }, this));
  30. }
  31. };
  32. };
  33. })(jQuery);