Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{v4] jInsertEditorText not available #30247

Closed
jschmi102 opened this issue Jul 31, 2020 · 7 comments
Closed

{v4] jInsertEditorText not available #30247

jschmi102 opened this issue Jul 31, 2020 · 7 comments

Comments

@jschmi102
Copy link

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

@dgrammatiko
Copy link
Contributor

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

@jschmi102
Copy link
Author

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.

@dgrammatiko
Copy link
Contributor

// 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')

@ReLater
Copy link
Contributor

ReLater commented Aug 1, 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);
}

@dgrammatiko
Copy link
Contributor

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

@ReLater
Copy link
Contributor

ReLater commented Aug 1, 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 ...

@dgrammatiko
Copy link
Contributor

@ReLater no worries I was trolling myself 😎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants