Skip to content
Snippets Groups Projects
Unverified Commit 122c48f0 authored by Lauri Timmanee's avatar Lauri Timmanee
Browse files

Issue #3265230 by bnjmnm, Wim Leers: Refactor ie11.filter.warnings.es6.js to...

Issue #3265230 by bnjmnm, Wim Leers: Refactor ie11.filter.warnings.es6.js to simpler structure & other improvements
parent ce3899e8
No related branches found
No related tags found
38 merge requests!7471uncessary 5 files are moved from media-library folder to misc folder,!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!4868Issue #1428520: Improve menu parent link selection,!4289Issue #1344552 by marcingy, Niklas Fiekas, Ravi.J, aleevas, Eduardo Morales...,!4114Issue #2707291: Disable body-level scrolling when a dialog is open as a modal,!3630Issue #2815301 by Chi, DanielVeza, kostyashupenko, smustgrave: Allow to create...,!3291Issue #3336463: Rewrite rules for gzipped CSS and JavaScript aggregates never match,!3143Issue #3313342: [PHP 8.1] Deprecated function: strpos(): Passing null to parameter #1 LayoutBuilderUiCacheContext.php on line 28,!3102Issue #3164428 by DonAtt, longwave, sahil.goyal, Anchal_gupta, alexpott: Use...,!2853#3274419 Makes BaseFieldOverride inherit the internal property from the base field.,!2719Issue #3110137: Remove Classy from core.,!2437Issue #3238257 by hooroomoo, Wim Leers: Fragment link pointing to <textarea>...,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2074Issue #2707689: NodeForm::actions() checks for delete access on new entities,!2062Issue #3246454: Add weekly granularity to views date sort,!1974Issue #3036862 demonstration,!1591Issue #3199697: Add JSON:API Translation experimental module,!1484Exposed filters get values from URL when Ajax is on,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1254Issue #3238915: Refactor (if feasible) uses of the jQuery ready function to use VanillaJS,!1162Issue #3100350: Unable to save '/' root path alias,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!957Added throwing of InvalidPluginDefinitionException from getDefinition().,!925Issue #2339235: Remove taxonomy hard dependency on node module,!877Issue #2708101: Default value for link text is not saved,!873Issue #2875228: Site install not using batch API service,!872Draft: Issue #3221319: Race condition when creating menu links and editing content deletes menu links,!844Resolve #3036010 "Updaters",!712Issue #2909128: Autocomplete intermittent on Chrome Android,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.,!30Issue #3182188: Updates composer usage to point at ./vendor/bin/composer
......@@ -292,8 +292,11 @@ function _update_ckeditor5_html_filter(array $form, FormStateInterface $form_sta
}
// If switching to CKEditor 5 from another editor and there are errors in that
// switch, add an error class to the editor select, otherwise remove.
$response->addCommand(new InvokeCommand('[data-drupal-selector="edit-editor-editor"]', !$form_state->get('ckeditor5_is_active') && $form_state->get('ckeditor5_is_selected') && !empty($form_state->getErrors()) ? 'addClass' : 'removeClass', ['error']));
// switch, add an error class and attribute to the editor select, otherwise
// remove.
$ckeditor5_selected_but_errors = !$form_state->get('ckeditor5_is_active') && $form_state->get('ckeditor5_is_selected') && !empty($form_state->getErrors());
$response->addCommand(new InvokeCommand('[data-drupal-selector="edit-editor-editor"]', $ckeditor5_selected_but_errors ? 'addClass' : 'removeClass', ['error']));
$response->addCommand(new InvokeCommand('[data-drupal-selector="edit-editor-editor"]', $ckeditor5_selected_but_errors ? 'attr' : 'removeAttr', ['data-error-switching-to-ckeditor5', TRUE]));
if (!function_exists('_add_attachments_to_editor_update_response')) {
......
......@@ -15,10 +15,8 @@
'(-ms-high-contrast: active), (-ms-high-contrast: none)',
);
const editorSelect = once(
'editor-select',
document.querySelector(
'#filter-format-edit-form #edit-editor-editor, #filter-format-add-form #edit-editor-editor',
),
'editor-ie11-warning',
'[data-drupal-selector="filter-format-edit-form"] [data-drupal-selector="edit-editor-editor"], [data-drupal-selector="filter-format-add-form"] [data-drupal-selector="edit-editor-editor"]',
);
if (typeof editorSelect[0] !== 'undefined') {
......@@ -33,15 +31,16 @@
);
/**
* Adds an IE11 compatibility warning to the message container.
* Adds IE11 compatibility warnings to the message container.
*/
const ck5Warning = () => {
const addIE11Warning = () => {
selectMessages.add(
Drupal.t(
'CKEditor 5 is not compatible with Internet Explorer. Text fields using CKEditor 5 will fall back to plain HTML editing without CKEditor for users of Internet Explorer.',
),
{
type: 'warning',
id: 'ie_11_warning',
},
);
if (isIE11) {
......@@ -56,6 +55,7 @@
),
{
type: 'error',
id: 'ie_11_error',
},
);
editorSettings.hidden = true;
......@@ -63,68 +63,60 @@
};
/**
* Adds a warning if the selected editor is ckeditor5, otherwise clears
* the message container.
* Adds a warning if the selected editor is CKEditor 5, otherwise clears
* any existing IE11 warnings.
*/
const updateWarningStatus = () => {
if (
select.value === 'ckeditor5' &&
!select.classList.contains('error')
!select.hasAttribute('data-error-switching-to-ckeditor5')
) {
ck5Warning();
addIE11Warning();
} else {
editorSettings.hidden = false;
selectMessages.clear();
if (selectMessages.select('ie_11_warning')) {
selectMessages.remove('ie_11_warning');
}
if (selectMessages.select('ie_11_error')) {
selectMessages.remove('ie_11_error');
}
}
};
const selectChangeHandler = () => {
// Declare the observer first so the observer callback can access it.
let editorSelectObserver = null;
updateWarningStatus();
/**
* MutationObserver callback for the editor select.
*
* This listens for the removal 'disabled' attribute on the <select>,
* which means the AJAX callback has completed and the form is in a
* state suitable for seeing if the IE11 warning is needed.
*
* @param {Array} mutations
* The element's mutations.
*/
function whenSelectAttributeChanges(mutations) {
for (let i = 0; i < mutations.length; i++) {
// When the select input is no longer disabled, the AJAX request
// is complete and the UI is in a state where it can be determined
// if the IE11 warning is needed.
if (
mutations[i].type === 'attributes' &&
mutations[i].attributeName === 'disabled' &&
!select.disabled
) {
updateWarningStatus();
editorSelectObserver.disconnect();
}
// This observer listens for two different attribute changes that, when
// they occur, may require adding or removing the IE11 warnings.
// - If the disabled attribute was removed, which is potentially due to
// an AJAX update having completed.
// - If the data-error-switching-to-ckeditor5 attribute was removed,
// which means a switch to CKEditor 5 that was previously blocked due
// to validation errors has resumed and completed.
const editorSelectObserver = new MutationObserver((mutations) => {
for (let i = 0; i < mutations.length; i++) {
// When the select input is no longer disabled, the AJAX request
// is complete and the UI is in a state where it can be determined
// if the ckeditor_stylesheets warning is needed.
const switchToCKEditor5Complete =
mutations[i].type === 'attributes' &&
mutations[i].attributeName === 'disabled' &&
!select.disabled;
const fixedErrorsPreventingSwitchToCKEditor5 =
mutations[i].type === 'attributes' &&
mutations[i].attributeName ===
'data-error-switching-to-ckeditor5' &&
!select.hasAttribute('data-error-switching-to-ckeditor5');
if (
switchToCKEditor5Complete ||
fixedErrorsPreventingSwitchToCKEditor5
) {
updateWarningStatus();
}
}
});
// An observer is used because during the select change event, it is
// not yet known if validation prevented the switch to CKEditor 5.
// The IE11 warning should only appear if the switch wasn't prevented
// by validation.
editorSelectObserver = new MutationObserver(
whenSelectAttributeChanges,
);
editorSelectObserver.observe(select, {
attributes: true,
attributeOldValue: true,
});
};
updateWarningStatus();
// Listen to text format selection changes.
select.addEventListener('change', selectChangeHandler);
editorSelectObserver.observe(select, {
attributes: true,
});
}
},
};
......
......@@ -9,7 +9,7 @@
Drupal.behaviors.ckEditor5warn = {
attach: function attach() {
const isIE11 = Modernizr.mq('(-ms-high-contrast: active), (-ms-high-contrast: none)');
const editorSelect = once('editor-select', document.querySelector('#filter-format-edit-form #edit-editor-editor, #filter-format-add-form #edit-editor-editor'));
const editorSelect = once('editor-ie11-warning', '[data-drupal-selector="filter-format-edit-form"] [data-drupal-selector="edit-editor-editor"], [data-drupal-selector="filter-format-add-form"] [data-drupal-selector="edit-editor-editor"]');
if (typeof editorSelect[0] !== 'undefined') {
const select = editorSelect[0];
......@@ -18,51 +18,51 @@
const selectMessages = new Drupal.Message(selectMessageContainer);
const editorSettings = document.querySelector('#editor-settings-wrapper');
const ck5Warning = () => {
const addIE11Warning = () => {
selectMessages.add(Drupal.t('CKEditor 5 is not compatible with Internet Explorer. Text fields using CKEditor 5 will fall back to plain HTML editing without CKEditor for users of Internet Explorer.'), {
type: 'warning'
type: 'warning',
id: 'ie_11_warning'
});
if (isIE11) {
selectMessages.add(Drupal.t('Text editor toolbar settings are not available in Internet Explorer. They will be available in other <a href="@supported-browsers">supported browsers</a>.', {
'@supported-browsers': 'https://www.drupal.org/docs/system-requirements/browser-requirements'
}), {
type: 'error'
type: 'error',
id: 'ie_11_error'
});
editorSettings.hidden = true;
}
};
const updateWarningStatus = () => {
if (select.value === 'ckeditor5' && !select.classList.contains('error')) {
ck5Warning();
if (select.value === 'ckeditor5' && !select.hasAttribute('data-error-switching-to-ckeditor5')) {
addIE11Warning();
} else {
editorSettings.hidden = false;
selectMessages.clear();
}
};
const selectChangeHandler = () => {
let editorSelectObserver = null;
if (selectMessages.select('ie_11_warning')) {
selectMessages.remove('ie_11_warning');
}
function whenSelectAttributeChanges(mutations) {
for (let i = 0; i < mutations.length; i++) {
if (mutations[i].type === 'attributes' && mutations[i].attributeName === 'disabled' && !select.disabled) {
updateWarningStatus();
editorSelectObserver.disconnect();
}
if (selectMessages.select('ie_11_error')) {
selectMessages.remove('ie_11_error');
}
}
editorSelectObserver = new MutationObserver(whenSelectAttributeChanges);
editorSelectObserver.observe(select, {
attributes: true,
attributeOldValue: true
});
};
updateWarningStatus();
select.addEventListener('change', selectChangeHandler);
const editorSelectObserver = new MutationObserver(mutations => {
for (let i = 0; i < mutations.length; i++) {
const switchToCKEditor5Complete = mutations[i].type === 'attributes' && mutations[i].attributeName === 'disabled' && !select.disabled;
const fixedErrorsPreventingSwitchToCKEditor5 = mutations[i].type === 'attributes' && mutations[i].attributeName === 'data-error-switching-to-ckeditor5' && !select.hasAttribute('data-error-switching-to-ckeditor5');
if (switchToCKEditor5Complete || fixedErrorsPreventingSwitchToCKEditor5) {
updateWarningStatus();
}
}
});
editorSelectObserver.observe(select, {
attributes: true
});
}
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment