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 7 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,8 @@

#macro(displayAnnotationProperty $annotatedDocument $annotationObject $annotationProperty $mode)
#if ($mode == 'edit' || $mode == 'create')
## This startupFocus parameter is used by the CKEditor WYSIWYG editor.
#set ($startupFocus = true)
Copy link
Member

Choose a reason for hiding this comment

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

I'm wondering if we shouldn't make his a bit more generic / extensible to prepare the ground for other configuration parameters we may need in the future:

Suggested change
#set ($startupFocus = true)
#set ($wysiwygEditorConfig = {
'startupFocus': true
})

This will make the configuration more explicit, and it will reduce the risk of naming conflicts with other entries from the script context. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good 👍
I added changes related to this in 359f650

Note that using the standard XWiki config for intellij idea, it auto formatted the two xmls into a wrong style. I had to deactivate the feature and fix it by hand in b7d3008 .

## 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.
Sereza7 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -218,9 +218,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: startupFocus,
Sereza7 marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -206,6 +206,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($startupFocus)
Sereza7 marked this conversation as resolved.
Show resolved Hide resolved
#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 ($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,8 @@

<label for="$name">$services.localization.render('core.viewers.comments.add.comment.label')</label>
#initRequiredSkinExtensions()
## This startupFocus parameter is used by the CKEditor WYSIWYG editor.
#set ($startupFocus = true)
Sereza7 marked this conversation as resolved.
Show resolved Hide resolved
## 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