-
-
Notifications
You must be signed in to change notification settings - Fork 555
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
XWIKI-22495: Missing text content in the resource picker dropdown #3612
base: master
Are you sure you want to change the base?
Conversation
* Added a translated title/content to the dropdown toggle * Updated the style to allow for the use of .sr-only in this specific context (overriding CKEditor CSS reset)
@@ -35,7 +36,9 @@ define('resourcePicker', [ | |||
'<button type="button" class="resourceType btn btn-default">' + | |||
'<span class="icon">' + | |||
'</button>' + | |||
'<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">' + | |||
'<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" ' + | |||
'title="' + translations.get('dropdown.toggle.title') + '">' + |
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.
is the result of translation.get
html safe or does it needs an xml escaping?
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.
https://github.com/search?q=repo%3Axwiki%2Fxwiki-platform%20translations.get(&type=code
There's no other use where we just use it as plain HTML. I'm pretty sure using it in Element.text
escapes it.
From what I can see at
Lines 52 to 63 in 76b6530
var getTranslation = function(key) { | |
var translation = this[key]; | |
if (typeof translation === 'string') { | |
// Naive implementation for message parameter substitution that suits our current needs. | |
for (var i = 1; i < arguments.length; i++) { | |
translation = translation.replace(new RegExp('\\{' + (i - 1) + '\\}', 'g'), arguments[i]); | |
} | |
} else { | |
translation = key; | |
} | |
return translation; | |
}; |
the translation function doesn't care about escaping (which is correct as far as I know).
I couldn't find a proper way to escape things directly in here (except implementing a barebones HTML escaper ^^').
I decided to fill up the template with the translations using jquery methods. These methods escape their inputs so it's safe.
See edc6d87
Here is what a quick test of the updated PR gave me (I didn't properly move the translations to my instance - which is why it's somewhat broken in the screenshot.):
@@ -19,6 +19,18 @@ | |||
*/ | |||
#template('colorThemeInit.vm') | |||
|
|||
/* We need to redefine this class to have better priority than the CKEditor CSS reset. */ |
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'd be interested to have an explanation of why this class is needed.
What happens when this CSS is not defined?
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.
If this CSS is not defined, we cannot use the XWiki defined class .sr-only
to hide visually elements that are only useful for screen readers.
This is an issue because it's a class we should be able to rely on in all our codebase.
The CKEditor reset takes precedence over our definition of .sr-only
and decides the style of this element:
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.
Updated the comment to provide more detail in 5c7dfef 👍
* Escaped the two translations added.
* Updated CSS comment
/* We need to redefine this class to have better priority than the CKEditor CSS reset. | ||
Without this higher priority redefinition, the elements with this class are still shown. */ |
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 is not exactly clear to what is redefined, and why exactly this redefinition is needed.
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 updated the comment in 3fe586f to be more explicit. Let me know if there's still something unclear.
For maintainability, I avoided providing links in the comment.
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.
lgtm, maybe a quick check from @mflorea as well?
* Updated CSS comment
* Updated CSS comment
overflow: hidden; | ||
clip: rect(0, 0, 0, 0); | ||
border: 0; | ||
} |
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.
If any other sr-only elements are needed in our CKEditor UI, we might want to write a style rule for all of them with .cke_reset_all .sr-only.
I think I prefer the generic rule because there's a high chance we'll need this on other parts of CKEditor UI. Maybe put this in CKEditor.EditSheet
.
'<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">' + | ||
'<span class="sr-only"></span>' + |
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.
Would be nice to keep the indentation.
resourcePicker.find('button.dropdown-toggle').first().attr('title', translations.get('dropdown.toggle.title')); | ||
resourcePicker.find('button.dropdown-toggle .sr-only').first().text(translations.get('dropdown.toggle.title')); |
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.
resourcePicker.find('button.dropdown-toggle').first().attr('title', translations.get('dropdown.toggle.title')); | |
resourcePicker.find('button.dropdown-toggle .sr-only').first().text(translations.get('dropdown.toggle.title')); | |
resourcePicker.find('button.dropdown-toggle').attr('title', translations.get('dropdown.toggle.title')); | |
resourcePicker.find('button.dropdown-toggle .sr-only').text(translations.get('dropdown.toggle.title')); |
No need to limit the collection to the first item.
Jira URL
https://jira.xwiki.org/browse/XWIKI-22495
Changes
Description
Clarifications
.cke_reset_all *
. Pretty much anything more specific than.sr-only
is enough to take priority over it. I decided to go with a local definition (only useful for this specific element). If any other sr-only elements are needed in our CKEditor UI, we might want to write a style rule for all of them with.cke_reset_all .sr-only
.Screenshots & Video
No visual changes in between before and after the PR, except for the title tooltip appearing when hovering the button.
Here is what the UI would look like after the changes proposed in this PR:
Executed Tests
Manual tests on a local instance, see screenshot above.
As far as I can see, integration-tests should not be impacted by this change.
Expected merging strategy