?
avatar jschmi102
jschmi102
31 Jul 2020

jInsertEditorText javascript used with editor-xtd plugin is not available

Expected result

Should replace / insert text when editing article

Actual result

javascript error as code is unavailable

System information (as much as possible)

with joomla 3.x code was in /media/editors/... -> directories gone in V4 (migrated to???)

Additional comments

avatar jschmi102 jschmi102 - open - 31 Jul 2020
avatar joomla-cms-bot joomla-cms-bot - change - 31 Jul 2020
Labels Added: ?
avatar joomla-cms-bot joomla-cms-bot - labeled - 31 Jul 2020
avatar dgrammatiko
dgrammatiko - comment - 31 Jul 2020

It's already 4 years since this was deprecate. Here #12561 you'll find all the info you need to fix whatever is broken

avatar jschmi102
jschmi102 - comment - 1 Aug 2020

don't agree to comment. "jInsertEditorText" javascript is available with latest stable joomla version (3.9.20). The issue comes with version 3.10 and version 4. (#12561 describes a totally different problem).
So: will there be a replacecment for "jInsertEditorText", a solution or documentation for this or not? Some developer will (at least) need some info if code is deleted and cannot be used anymore.

avatar dgrammatiko
dgrammatiko - comment - 1 Aug 2020
// An object to hold each editor instance on page, only define if not defined.
Joomla.editors.instances = Joomla.editors.instances || {
        /**
         * Editors MUST register, per instance, the following:
         *
         * getValue         Type  Function
         *          Should return the complete data from the editor
         *          Example: function () { return this.element.value; }
         * setValue         Type  Function
         *          Should replace the complete data of the editor
         *          Example: function (text) { return this.element.value = text; }
         * replaceSelection  Type  Function
         *          Should replace the selected text of the editor
         *          If nothing selected, will insert the data at the cursor
         *          Example: function (text) { return insertAtCursor(this.element, text); }
         *
         * USAGE (jform_articletext is the editor id)
         * getValue:
         *      Joomla.editors.instances['jform_articletext'].getValue();
         * setValue:
         *      Joomla.editors.instances['jform_articletext'].setValue('Joomla! rocks');
         * replaceSelection:
         *      Joomla.editors.instances['jform_articletext'].replaceSelection('Joomla! rocks')
         *
         * *********************************************************
         * ANY INTERACTION WITH THE EDITORS SHOULD USE THE ABOVE API
         * *********************************************************
         */
    };

You should use the new API: Joomla.editors.instances['editor_id'].replaceSelection('Joomla! rocks')

avatar ReLater
ReLater - comment - 1 Aug 2020

I'm using this half-assed, paranoid(?) code in all of my xtd-plugins (select/enter something in a pop-up and insert via button). From a time when first 4-dev "releases" came up and I tested my dinosaur J3 xtd-plugins with some editors on both platforms:

/** Use the API, if editor supports it **/
if (window.parent.Joomla && window.parent.Joomla.editors && window.parent.Joomla.editors.instances && window.parent.Joomla.editors.instances.hasOwnProperty(editor))
{
	window.parent.Joomla.editors.instances[editor].replaceSelection(tag);
}
else
{
	window.parent.jInsertEditorText(tag, editor);
}
avatar dgrammatiko
dgrammatiko - comment - 1 Aug 2020

@ReLater im wondering who could ever wrote that paranoid code, oh wait: #14935 (comment)

avatar ReLater
ReLater - comment - 1 Aug 2020

Ah, f'ing auto correction of my keyboard. I wanted to type "paramount" not "paranoid" ;-)

For me it looked like one of my own paranoia what-the-hell-is-really-needed IF structures reassembled from diverse code snippets found on stackexchange ;-)

if (good && !bad)

No harm meant. It's brilliant code... because it works ...

avatar dgrammatiko
dgrammatiko - comment - 1 Aug 2020

@ReLater no worries I was trolling myself 😎

avatar jschmi102 jschmi102 - change - 13 Aug 2020
Status New Closed
Closed_Date 0000-00-00 00:00:00 2020-08-13 09:06:01
Closed_By jschmi102
avatar jschmi102 jschmi102 - close - 13 Aug 2020

Add a Comment

Login with GitHub to post a comment