Board Thread:Support Requests - Getting Technical/@comment-2112998-20130125015527/@comment-5209426-20130126222729

If you're happy with it only working in Source Mode then that code you pasted should be fine. The only thing you'll need to do is disable your custom controls in WYSIWYG mode since they won't work. I don't know what script you're copying but you should be able to use this code as a framework:

Edit: Re-reading your problem more closely, the code you posted isn't the relevant section. The code which calls this function needs to find,   is only used when the Visual Editor is not functioning (disabled / permission error).

You've probably got something like. Replace that with  instead and it should hopefully work.