Skip to content

Instantly share code, notes, and snippets.

@Krato
Created August 10, 2016 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Krato/646d67995855b99739e94a9af67613e5 to your computer and use it in GitHub Desktop.
Save Krato/646d67995855b99739e94a9af67613e5 to your computer and use it in GitHub Desktop.
/*
Redactor 10.2.3
License: http://imperavi.com/redactor/license/
Updated: August 8, 2016
Modded by Eric Lagarda https://github.com/Krato
*/
(function($)
{
$.Redactor.prototype.limiter = function()
{
return {
init: function()
{
if (!this.opts.limiter)
{
return;
}
console.log(this);
this.$editor.on('keydown.redactor-plugin-limiter', $.proxy(function(e)
{
var key = e.which;
var ctrl = e.ctrlKey || e.metaKey;
if (key === this.keyCode.BACKSPACE
|| key === this.keyCode.DELETE
|| key === this.keyCode.ESC
|| key === this.keyCode.SHIFT
|| (ctrl && key === 65)
|| (ctrl && key === 82)
|| (ctrl && key === 116)
)
{
return;
}
var text = this.$editor.text();
text = text.replace(/\u200B/g, '');
var count = text.length;
if (count >= this.opts.limiter)
{
return false;
}
}, this));
}
};
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment