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
Allow multiple (different) editors in one page #12561
Conversation
@okonomiyaki3000 can you check the changes I did in codemirror here? |
I'm not sure what this |
it's just the initiator script, this way there is no inline script at all |
I don't think there's anything wrong with inline script. The problem with this is that it seems to be part of Joomla core instead of the CodeMirror plugin and it can't be overridden like the current version can (via layouts). |
@okonomiyaki3000 not quite true, you can still use the layouts although a tiny script will be missing (the one that comes from code mirror.php). But if it breaks B/C I can revert it and redo this in J4 |
Sorry, I can't get behind putting files used by the editors in |
@okonomiyaki3000 I will revert that part, but this PR is NOT about the initialisation of the editors, it solves a very fundamentally wrong architectural concept that limits joomla to only one editor per page... |
@dgt41 Yes, I'm aware of the limitation. It limits Joomla to only one type of editor per page. You may still have multiple instances of the same type. It's quite a glaring flaw and I'm glad you're fixing it but we must first do no harm. |
@ggppdk can you test this one? |
@dgt41 will do tomorrow, thanks for the work on this one |
@okonomiyaki3000 I've restored the inline initialisation script for codemirror... |
I don't know, I'm still seeing |
Other editors also using static scripts in |
Isn't |
I see, that makes sense I guess. Does that mean that the libraries under |
@okonomiyaki3000 I guess this will manage only the joomla distributed code, I have no clue if this will be extended somehow for 3rd PD (my guess is no, 3rd PD could provide their custom code in their own directory). Or you can manipulate or override the grunt script and get whatever you want, with the added step to re-run the script every time joomla updates these assets... |
Conflicts |
@@ -28,6 +28,24 @@ | |||
label="COM_CONTENT_FIELD_ARTICLETEXT_LABEL" description="COM_CONTENT_FIELD_ARTICLETEXT_DESC" | |||
filter="JComponentHelper::filterText" buttons="true" /> | |||
|
|||
<field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dgt41 Can you look into the formatting here? The indentation seems to be broken, same for closing tag. And you have some white space at the label.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yvesh this whole section is here only for testing, will be and should be removed before merging, thus the wrong indentation
@@ -111,8 +123,9 @@ | |||
<span class="<?php echo $iconStates[$this->escape($item->state)]; ?>"></span> | |||
</td> | |||
<td> | |||
<a href="javascript:void(0);" onclick="if (window.parent) window.parent.<?php echo $this->escape($function); ?>('<?php echo $item->id; ?>', '<?php echo $this->escape(addslashes($item->title)); ?>', '<?php echo $this->escape($item->catid); ?>', null, '<?php echo $this->escape(ContentHelperRoute::getArticleRoute($item->id, $item->catid, $item->language)); ?>', '<?php echo $this->escape($lang); ?>', null);"> | |||
<?php echo $this->escape($item->title); ?></a> | |||
<a class="select-link" href="javascript:void(0)" data-function="<?php echo $this->escape($onclick); ?>" data-id="<?php echo $item->id; ?>" data-title="<?php echo $this->escape(addslashes($item->title)); ?>" data-cat-id="<?php echo $this->escape($item->catid); ?>" data-uri="<?php echo $this->escape(ContentHelperRoute::getArticleRoute($item->id, $item->catid, $item->language)); ?>" data-language="<?php echo $this->escape($lang); ?>"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any way to make this more readable and less long? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not use as many attributes or start formatting our HTML the same way our XML files are formatted (and I find THAT ugly and painful to keep up with personally).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mbabker would you prefer something like:
<?php $attribs = 'data-function="' . $this->escape($onclick) . '"'
. ' data-id="' . $item->id . '"'
. ' data-title="' . $this->escape(addslashes($item->title)) . '"'
. ' data-cat-id="' . $this->escape($item->catid) . '"'
. ' data-uri="' . $this->escape(ContentHelperRoute::getArticleRoute($item->id, $item->catid, $item->language)) . '"'
. ' data-language="' . $this->escape($lang) . '"';
?>
<a class="select-link" href="javascript:void(0)" <?php echo $attribs; ?>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, for this you could just as usually use JHtml::_('link', 'javascript:void(0)', $this->escape($item->title), $attribsArray);
and it not be unbearable. What you have works too, I'm just honestly not the biggest fan of some of our code style rules with line concatenation and splitting elements on separate lines in funny places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Until recently, I seriously thought our iframe
and link
HTML helpers were silly as all can be. But then I started thinking that they're actually pretty useful for elements where you're adding a lot of data in some form (in this case data attributes) so you can throw those elements in an array and pass them into a function which converts it to the proper string. End result is still the same; clean PHP code and clean HTML output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/**
* Write a `<a>` element
*
* @param string $url The relative URL to use for the href attribute
* @param string $text The target attribute to use
* @param array|string $attribs Attributes to be added to the `<a>` element
*
* @return string
*
* @since 1.5
*/
public static function link($url, $text, $attribs = null)
I've learned something today 😄
editor = Joomla.getOptions('xtd-contacts').editor; | ||
|
||
if (lang !== '') | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are mixing php and js code style here ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy-paste...
* Javascript to insert the link | ||
* View element calls jSelectContact when a contact is clicked | ||
* jSelectContact creates the link tag, sends it to the editor, | ||
* and closes the select frame. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it would be nice to have since tags in js too.. Any thoughts on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be a way, have to do some testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yvesh so what is the @since
supposed to be for all these scripts, because ok now they are static files but the code comes from way back?
hreflang = ' hreflang = "' + lang + '"'; | ||
} | ||
|
||
tag = '<a' + hreflang + ' href="' + link + '">' + title + '</a>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally i would prefer when you do a document.createElement('a') here etc. then hardcoding a link into a string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too fast, we do support IE8, so not possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm document.createElement should work in IE8?
// Get the elements | ||
var elements = document.querySelectorAll('.select-link'); | ||
|
||
for(var i = 0, l = elements.length; l>i; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just out of curiosity, why are you saving elements length in a variable? ;) cs btw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need for speed 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
itar in phpstorm create those...
title = (title != '') ? 'title="' + title + '"' : ''; | ||
alt = (alt != '') ? 'alt="' + alt + '"' : ''; | ||
|
||
tag = '<hr class="system-pagebreak" ' + title + ' ' + alt + '/>'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, wouldn't document.createElement be nicer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IE8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm it should work fine in IE8? Shouldn't it? We use document.createElement in a lot of other JS files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it shouldn't be any problem, just checked...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yvesh checking this again, I am not in favour as we are passing a string to the editor and I have no clue if all editors out there will be happy with an element instead of a string
content = (new Function('return ' + options.editor))(); | ||
|
||
if (content.match(/<hr\s+id=("|')system-readmore("|')\s*\/*>/i)) { | ||
alert(options.exists); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alert? :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's what was there, what else can it be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why it is there any ways, but not a fan of alerts at all ;) Maybe use Joomla.renderMessages instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess is the same story as the buttons of the toolbar, where also an alert is utilised...
Honestly I don't mind changing it to Joomla.renderMessages()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yvesh This was a great idea generator, so J4 will come with some shiny new thingy
that will cover those cases
I have tested this item ✅ successfully on 3550213 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12561. |
@ggppdk @rvbgnu @infograf768 can we have one more test here, so we can RTC this? |
So nobody for this test ? Or should I re-test it (changes since 08/01/2017)?? This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12561. |
@rvbgnu if you can re-test this, will be great |
So I've tried, but it doesn't change before or after the patch. The TinyMCe also had an update. I have to reset with repository copy and re-install I think... This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12561. |
@rvbgnu the article form doesn't have the extra editors anymore. That needs to be done by editing the xml and the view files. The initial approach had those extra editors as a way to make testing easier... |
I have tested this item ✅ successfully on 3550213 This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12561. |
RTC This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12561. |
Note to whomever might merge this: please ping to update the documentation for the editor input field, etc |
@dgt41 ping :P |
I just grabbed the latest build and run into an issue with having multiple editors on the same page. Seems like only one of them gets initialized. I have three of them in my example. The This can also be reproduced by changing some form elements of the com_content/forms/article.xml to type editor: |
That's impossible (each tinyMCE or code mirror or none has it's own instance) according to the code: https://github.com/joomla/joomla-cms/blob/staging/media/editors/tinymce/js/tinymce.js#L65-L79 |
@svenbluege actually there is a bug, but here is the fix: #14194 Thanks for testing! |
@dgt41 works for me. Thanks! |
It looks like this has broken inserting menu item urls Please look @dgt41 |
@infograf768 check #14902 |
Pull Request for Issue #12555
XTD-Buttons will NOT work if more than one (and different) editors are rendered on the page
Steps to reproduce
Make sure that the default editor is tinyMCE
Edit
administrator/components/com_content/models/forms/article.xml
and add afterthis:
Edit
administrator/components/com_content/views/article/tmpl/edit.php
and add afterthis:
Then try to use the buttons to insert some images, contacts, etc. Oops it's broken for all except the last one.
Summary of Changes
Introducing a simple API which is just some setters and some getters.
This is more informative:
Testing Instructions
Apply this patch
Go to back end and edit/create an article
On purpose there are all the editors in that page
Try the buttons in all of them. Cool eh?
Documentation Changes Required
The comment above comes from core.js but needs to be published also in the form->editor page.
TL;DR
Some images then:
Calling @Fedik @andrepereiradasilva @ggppdk @mbabker
This change is