1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Trying to add an editor button that is similar to the Smilies button.

Discussion in 'XenForo Development Discussions' started by emc2, Sep 16, 2013.

  1. emc2

    emc2 Active Member

    Hi Guys,

    I'm trying to create a new button in the editor which will be similar to the Smilie button. I've managed to add the button correctly but the callback just doesn't seem to be firing. Everything else seems to work as it should..

    !function($, window, document, _undefined)
        XenForo.customEditorForMyAddon = function($textarea) { this.__construct($textarea); };
        XenForo.customEditorForMyAddon.prototype =
            __construct: function($textarea)
                var redactorOptions = $textarea.data('options'),            /*Get the current data options from the textarea element*/
                myButtons = this.createCustomButtons(),                    /*Get your custom buttons - see below function*/
                myOptions = {                                /*Bake your custom Editor Options */
                    buttons: myButtons                            //Redactor buttons
                if(typeof RedactorPlugins == 'undefined')                /*If your plugins are not loaded before the framework this line should avoid to break the code*/
                    RedactorPlugins = {};
                $textarea.data('options', $.extend(redactorOptions, myOptions));    /*Merge your custom Editor Options with the current ones*/
            createCustomButtons: function()
                    Some functions should be static, ie: wrapSelectionInHtml
                    wrapSelectionInHtml should have an option to allow to set BbCode Options or Content
                return {
                    myCustomButton_1: {
                        title: 'Symbols',                /*This is the button description*/
                        callback: function()
                            alert('symbols called successfully.');
                    },                            /*You can instead of the "tag" key use the "exec" key to execute an execCommand*/
                    myCustomButton_2: {
                        title: 'Latex',
                        tag: 'LATEX'
        XenForo.register('textarea.BbCodeWysiwygEditor', 'XenForo.customEditorForMyAddon');    /*target all textareas with Redactor loaded*/
    }(jQuery, this, document);
    I've got the basic understanding from a thread (http://xenforo.com/community/threads/initialize-redactor-plugins.53092/) which @r1pe and @cclaerhout seem to know alot about.. Hopeone someone knows what is preventing this callback from firing.

Share This Page