Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Joomla - Insert text in editor through a plugin

I am currently creating a Joomla Plugin which add a new button to any editor. When the button is clicked, a modal appears showing a table with some informations. I would like to create a button in this modal, and when it is clicked, the modal will be closed and a text ( for now any text ) will be displayed in the editor.

The modal shows up, the button is implemented as follow:

<button class="btn" type="button" onclick="window.parent.jInsertEditorText('something');window.parent.SqueezeBox.close();"><?php echo JText::_('CANCEL') ?></button>

But I have an error when clicking it:

Uncaught TypeError: Object [object Array] has no method 'execCommand' tiny_mce.js:1
 j.EditorManager.d.execInstanceCommand tiny_mce.js:1
 jInsertEditorText index.php?option=com_content&view=article&layout=edit:49
 onclick

I would enjoy any help :)

like image 428
lightalex Avatar asked Sep 12 '13 09:09

lightalex


1 Answers

The jInsertEditorText method expects the editor id as its second parameter.

The method's signature is:

function jInsertEditorText( text, editor );

And you should call it as follows:

jInsertEditorText('sometText', 'editor_id'); 

You need to inform your SqueezeBox/button which editor to target, or add a wrapper method that will target the correct editor for it.

For example, the article editor contains an editor with the id jform_articletext. A method called jSelectArticle is defined in the parent window, which takes the details of another article and adds a link to it in the editor.

function jSelectArticle(id, title, catid, object, link, lang)
{
    var hreflang = '';
    if (lang !== '')
    {
        var hreflang = ' hreflang = "' + lang + '"';
    }
    var tag = '<a' + hreflang + ' href="' + link + '">' + title + '</a>';
    jInsertEditorText(tag, 'jform_articletext');
    SqueezeBox.close();
}

When a button under the editor is clicked, a Squeezebox with a list of articles is opened. Each of the articles has a click handler that calls that function with its properties:

if (window.parent) window.parent.jSelectArticle(...);

I would prefer to provide the editor id to the SqueezeBox, as it is cleaner and more portable.

On the server-side the plugin's onDisplay method receives the form identifier. You can use it as you like.

public function onDisplay($name)
like image 138
MasterAM Avatar answered Sep 21 '22 18:09

MasterAM