django-wysiwyg icon indicating copy to clipboard operation
django-wysiwyg copied to clipboard

[Limiter plugin] "Uncaught TypeError: this.core.editor is not a function"

Open Alphare opened this issue 9 years ago • 3 comments

I was trying to use the limiter plugin and got a "Uncaught TypeError: this.core.editor is not a function" in the chrome console. I figured the plugin was not up to date, and surely enough, the function "editor()" does not exist anymore and has been replaced by "getEditor()". Fixing this allows the plugin to work.

At the time of writing this, the code is :

(function($)
{
    $.Redactor.prototype.limiter = function()
    {
        return {
            init: function()
            {
                if (!this.opts.limiter)
                {
                    return;
                }

                this.core.getEditor().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.core.getEditor().text();
                    text = text.replace(/\u200B/g, '');

                    var count = text.length;
                    if (count >= this.opts.limiter)
                    {
                        return false;
                    }


                }, this));

            }
        };
    };
})(jQuery);

Alphare avatar Nov 16 '15 14:11 Alphare

Hi @Alphare, would you like to submit a pull request for this fix and get full credit?

pydanny avatar Nov 16 '15 15:11 pydanny

Hi @pydanny : I have never sumbitted a pull request before, but surely I'd like to if it is possible. How can I do that?
Is the plugin part of this repository?

Alphare avatar Nov 16 '15 15:11 Alphare

This looks like a plugin for the Redactor editor itself - this repo merely provides convenience for integrating the editor w/ Django

caffodian avatar Nov 17 '15 23:11 caffodian