XF 2.0 Extending editor / xfBbCodeBox

DragonByte Tech

Well-known member
TL;DR: How can I add a new element handler to the editor similar to user-mentioner?

---
I want to add a new mention-like feature to the editor (just initialised by another character), and I'm stuck trying to figure out how I would apply the handler.

In editor.js I see this code:
JavaScript:
                function getBbCodeBox()
                {
                    var $oel = ed.$oel;

                    var $bbCodeBox = $oel.data('xfBbCodeBox');
                    if (!$bbCodeBox)
                    {
                        var borderAdjust = parseInt(ed.$wp.css('border-bottom-width'), 10)
                            + parseInt(ed.$wp.css('border-top-width'), 10);

                        $bbCodeBox = $('<textarea class="input" style="display: none" />');
                        $bbCodeBox.css({
                            minHeight: ed.opts.heightMin ? (ed.opts.heightMin + borderAdjust) + 'px' : null,
                            maxHeight: ed.opts.heightMax ? ed.opts.heightMax + 'px' : null,
                            height: ed.opts.height ? (ed.opts.height + borderAdjust) + 'px' : null,
                            padding: ed.$el.css('padding')
                        });
                        $bbCodeBox.attr('name', $oel.data('original-name'));
                        $oel.data('xfBbCodeBox', $bbCodeBox);
                        ed.$wp.after($bbCodeBox);

                        XF.Element.applyHandler($bbCodeBox, 'textarea-handler');
                        XF.Element.applyHandler($bbCodeBox, 'user-mentioner');
                    }

                    return $bbCodeBox;
                }

Ideally I would want my code to run after XF.Element.applyHandler($bbCodeBox, 'user-mentioner'); in order to apply my own handler.

I see the XF.extend system but it only seems to apply to classes like XF.EditorDialog that have added explicit support for extensions.

Any advice would be greatly appreciated :)


Fillip
 
So I've discovered I don't need to do anything special to support custom auto-complete in the editor while it's in HTML mode. The problem is when the editor is in BBCode mode.

I seemingly can't extend getBbCodeBox inside $.FE.PLUGINS.bbCode since it's not a part of the return value array, and the rest of the BBCode plugin is part of a local scope that I seemingly can't access.

I don't want to have to replace the entire BBCode plugin as that would not be very compatible with other addons.

Is there a way to solve this to add custom auto-complete while the editor is in BBCode mode?


Fillip
 
I've gotten it working by copying the entire $.FE.PLUGINS.bbCode into my custom editor:first-start extension and adding the one line I wanted to add.

If there's another way of doing this then please do let me know.

If there's no other way, I'll go post in the suggestions forum for it to be made extendable in the future.


Fillip
 
Top Bottom