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

XWIKI-17664: When adding an annotation the focus should be inside WYSIWYG by default #3694

Merged
merged 12 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@

#macro(displayAnnotationProperty $annotatedDocument $annotationObject $annotationProperty $mode)
#if ($mode == 'edit' || $mode == 'create')
## This startupFocus parameter is used by the CKEditor WYSIWYG editor.
#set ($wysiwygEditorConfig = {
'startupFocus': true
})
## We use displayEdit and not display('edit') because we want the input field name to be just the property name
## (without the "DocumentReference_objectNumber_" prefix).
$annotatedDocument.displayEdit($annotationProperty, '', $annotationObject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ XWiki.Annotation = Class.create({
if (!this.safeUpdate(this.createPanel, panelContent)) {
return;
}
// set the focus in the first element of type input
// Set the focus in the first element of type input, useful when not using the WYSIWYG editor CKEditor.
this.createPanel.select('form').first().focusFirstElement();
// and add the button observers
this.createPanel.down('input[type=submit]').observe('click', this.onAnnotationAdd.bindAsEventListener(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ define('xwiki-ckeditor', [
}

var uploadDisabled = element.hasAttribute('data-upload-disabled');
var startupFocus = element.hasAttribute('data-startup-focus');

var config = {
filebrowserUploadUrl: uploadDisabled ? '' : getUploadURL(sourceDocument, 'filebrowser'),
startupFocus,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be startupFocus: startupFocus? it's a key: value config object no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's called "shorthand property name" see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#property_definitions (syntax sugar to reduce boilerplate).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know this notation well enough to use it either ^^'
#3694 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok thanks for the information, I'm not sure I'd have changed it since IMO it's not helping much reading but that's fine :)

height: $(element).height(),
// Used to resolve and serialize relative references. Also used to make HTTP requests with the right context.
sourceDocument: sourceDocument,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@
#if ($source.restricted == 'true' && !$services.security.authorization.hasAccess('edit', $source.documentReference))
#set ($parameters.attributes.data-upload-disabled = 'true')
#end
## We use the velocity template context to convey the startupFocus parameter to CKEditor.
#if ($wysiwygEditorConfig.startupFocus)
#set ($parameters.attributes.data-startup-focus = 'true')
## We make sure to clear this context so that it doesn't interfere with CKEditors opened later.
#set ($wysiwygEditorConfig.startupFocus = false)
#end
##
<textarea
#foreach ($entry in $parameters.attributes.entrySet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@

<label for="$name">$services.localization.render('core.viewers.comments.add.comment.label')</label>
#initRequiredSkinExtensions()
## This startupFocus parameter is used by the CKEditor WYSIWYG editor.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## This startupFocus parameter is used by the CKEditor WYSIWYG editor.
## This startupFocus parameter is used by the CKEditor WYSIWYG editor.

Wrong indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed in 27ead97 👍

#set ($wysiwygEditorConfig = {
'startupFocus': true
})
## display of the comment field
$doc.displayEdit($fieldToDisplay, '', $commentObj)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,6 @@ viewers.Comments = Class.create({

require(['jquery', 'xwiki-events-bridge'], function ($) {
if ($(".commenteditor").length) {
if(typeof CKEDITOR !== 'undefined') {
CKEDITOR.config.startupFocus = true;
}
$.post(new XWiki.Document().getURL("get") + '?' + $.param({
xpage: 'xpart',
vm: 'commentfield.vm',
Expand Down