How to insert text to editor programmatically in Joomla?

950 views Asked by At

I am using Joomla 1.7 and I am made a custom button (editor-xtd plugin) that I want to insert some string into the current editor content.

Like in the Readmore button. I have searched through the Readmore code and found :

$js = "
    function insertReadmore(editor) {
        var content = $getContent
        if (content.match(/<hr\s+id=(\"|')system-readmore(\"|')\s*\/*>/i)) {
            alert('$present');
            return false;
        } else {
            jInsertEditorText('<hr id=\"system-readmore\" />', editor);
        }
    }
";

Now when I try to call jInsertEditorText, I seem to get an error that it's missing.

Some forum suggested I import mootools.js, but that didn't seem to do the trick.

Where can I find it or is there some other approach?

2

There are 2 answers

1
Ric Z On

jInsertEditorText is defined by the editor, not in mootools. Try using TinyMCE editor or JCE, both support it fully.

0
mavrosxristoforos On

I know that this answer comes in very very late for this question, but it appears on the first page of Google and remains unanswered, so here it is:

Things have changed since 2012 and editors now must implement the following two functions:

// Set value
if (typeof Joomla.editors.instances["jform_editor_name"] !== "undefined") {
  Joomla.editors.instances["jform_editor_name"].setValue(ourHTML);
}

// Get value
var text = Joomla.editors.instances["jform_editor_name"].getValue();