Proper way to work with JEditor from javascript

For Joomla! 3.x Coding related discussions, please use:

Moderator: ooffick

Forum rules
Please use the mailing list here: rather than this forum.
Post Reply
Quark Zimmerman
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Sun May 27, 2018 7:58 pm

Proper way to work with JEditor from javascript

Post by Quark Zimmerman » Sun Jun 03, 2018 9:36 pm

Hi , I have a probelm,
The story goes like this:

- I have my own component that let user to edit stuff using Joomla built in editor and I am not working with form.

The code would be rather trivial except that I load the stuff that I want to put into the editor to start with, not when I creating page, but only when user clicked some button.
Since this editing mode is not so common to use, this save the size of the HTML data transferred , improve loading time etc.

So when user does clicks a button I execute JS function (onclick) that post request to joomla, get the results and put it in textbox assigned for the editor.
Unfortunately this does not work, of course if I fill the textbox before calling display() on the editor - it works fine, but as I said I need it a way later (the editor windows is displayed when page is build but hidden).

So the most trivial thing to do is to call setContext() on the editor , but here is the problem - set context to whom? And from javascript...

The work around solution I found on net works, but sounds fishy , I call :

Code: Select all

        var activeEditor = tinyMCE.get('content');
And it does work, however I find it "funny" that it actually works because in my Joomla config I set JCE not TinyMCE as an editor and indeed editor displayed IS JCE.
So first I find it strange that it works at all, second - let's say JCE derived somehow from tinyMCE , but what will happen if I switch to some other editor?
Personally I prefer to work with JEditor object as it more generic, but how I can access it from JS ?

The other solution I tried (and it works too) is to put the JS function in question into php as a text to generate and add it using JFactory::getDocument()->addScriptDeclaration(), there I can use JEditor::getEditor() to be generic, but all this textual js code looks really ugly :( Especially when most of the js stuff is located in .js file...
Not to mention the fact that I do need to pass parameters to this function to go as first parameter to setContext() since there are several possible places I want to edit tied to different textpoxes and buttons and I can't pass JS parameters to PHP generated coed, so I need to create several variants of this function - looks really ugly :(

So does anyone have any suggestion how to get to generic JEditor object from JS ?

And another thing while on the same topic, when generating my calls in php using JEditor::getEditor()->setContext(..) I noticed that in resulting HTML it translates to WFEditor.setContext(..)
So my question is this WFEditor a generic JEditor object I seek or it just specific for JCE ?

Post Reply

Return to “Joomla! 3.x Coding”