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-21782: Incentivize use of header rows for the WYSIWYG editor tables #3310

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -20,7 +20,7 @@
(function() {
'use strict';
CKEDITOR.plugins.add('xwiki-table', {
requires: 'table',
requires: 'table,xwiki-localization',
init: function(editor) {
// The table plugin is using the deprecated align attribute for various reasons. See
// https://dev.ckeditor.com/ticket/3762 . We could overwrite the table dialog to use the margin:auto style but it
Expand Down Expand Up @@ -69,6 +69,18 @@
['txtBorder', 'txtWidth', 'txtCellSpace', 'txtCellPad'].forEach(function(fieldId) {
delete infoTab.get(fieldId)['default'];
});
// Set a new default for the Headers value.
infoTab.get( 'selHeaders' )[ 'default' ] = 'row';
// Create a warning message for the accessibility without headers.
const warningMessage = document.createElement('span');
warningMessage.classList.add('box', 'warningmessage');
warningMessage.textContent = CKEDITOR.tools.htmlEncode(
Copy link
Member

Choose a reason for hiding this comment

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

There's no need to escape HTML when you set the textContent. If you want to use CKEDITOR.tools.htmlEncode() then you can keep your previous code and just call CKEDITOR.tools.htmlEncode() on the translation value. So either use directly the DOM API (textContent) as I suggested, or use string concatenation but with HTML escaping.

editor.localization.get('xwiki-table.header.accessibilityWarning'));
// We navigate the structure of the tab to insert this message exactly next to the header.
infoTab.elements[0].children[0].children.splice(4, 0, {
type : 'html',
html : warningMessage.outerHTML
});
};

//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ void table()
// Write some text
textArea.sendKeys(TEST_TEXT);

assertSourceEquals("|" + TEST_TEXT + "| \n| | \n| | \n\n ");
assertSourceEquals("|=" + TEST_TEXT + "|= \n| | \n| | \n\n ");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,25 @@ td.cke_dialog_contents_body {
overflow-y: auto;
}

/**
* Handle the layout and display of the warning message for headerless tables.
* This message is added by the xwiki-table plugin.
* Some of the default styles are just overridden by the CKEditor reset.
*/
.cke_dialog_container span.box.warningmessage {
.alert-warning;
/* Default warning boxes are not meant to be used in a strict layout like the one of this table dialog.
* We need an extra customization to avoid breaking this layout. */
white-space: break-spaces;
mflorea marked this conversation as resolved.
Show resolved Hide resolved
/* By default, the warning is not shown. */
display: none;
}

/* When the value of the previous field is the one we want to avoid, we show the warning. */
.cke_dialog_container tr:has(select [value=""]:checked) + tr span.box.warningmessage {
display: unset;
}

/**
* Link Options Toggle
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ ckeditor.plugin.save.leaveConfirmationMessage=There are unsaved changes. Do you
ckeditor.plugin.save.failed=The content cannot be saved because of a CKEditor internal error. You should try to copy your important changes and reload the editor.
ckeditor.plugin.source.conversionFailed=Failed to perform the conversion.

ckeditor.plugin.table.header.accessibilityWarning=Using headers will make your table easier to understand.

ckeditor.plugin.toolbar.basicStyles=Basic Styles
ckeditor.plugin.toolbar.lists=Lists
ckeditor.plugin.toolbar.bulletedlist=Bulleted List
Expand Down
Loading