From 25c55e3c1ef7bdece4baf1e6d367181c30391373 Mon Sep 17 00:00:00 2001 From: hooroomoo <hooroomoo@3688872.no-reply.drupal.org> Date: Tue, 12 Oct 2021 19:17:13 +0000 Subject: [PATCH] Issue #3239132 by hooroomoo, larowlan, nod_, bnjmnm: Refactor (if feasible) uses of the jQuery trim function to use vanillaJS --- core/.eslintrc.jquery.json | 2 +- core/misc/ajax.es6.js | 4 ++-- core/misc/ajax.js | 4 ++-- core/misc/autocomplete.es6.js | 2 +- core/misc/autocomplete.js | 2 +- core/misc/details-summarized-content.es6.js | 2 +- core/misc/details-summarized-content.js | 2 +- core/misc/form.es6.js | 2 +- core/misc/form.js | 2 +- .../js/ckeditor.stylescombo.admin.es6.js | 16 ++++++++-------- .../ckeditor/js/ckeditor.stylescombo.admin.js | 8 ++++---- core/modules/menu_ui/menu_ui.admin.es6.js | 2 +- core/modules/menu_ui/menu_ui.admin.js | 2 +- core/modules/node/node.es6.js | 2 +- core/modules/node/node.js | 2 +- .../quickedit/js/editors/plainTextEditor.es6.js | 4 ++-- .../quickedit/js/editors/plainTextEditor.js | 4 ++-- core/modules/views_ui/js/views-admin.es6.js | 2 +- core/modules/views_ui/js/views-admin.js | 2 +- 19 files changed, 33 insertions(+), 33 deletions(-) diff --git a/core/.eslintrc.jquery.json b/core/.eslintrc.jquery.json index c68d0141da6d..b1d27ef159c8 100644 --- a/core/.eslintrc.jquery.json +++ b/core/.eslintrc.jquery.json @@ -48,7 +48,7 @@ "jquery/no-text": 0, "jquery/no-toggle": 0, "jquery/no-trigger": 0, - "jquery/no-trim": 0, + "jquery/no-trim": 2, "jquery/no-val": 0, "jquery/no-when": 0, "jquery/no-wrap": 0 diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js index 4603b8195413..df7a0d5b0c6b 100644 --- a/core/misc/ajax.es6.js +++ b/core/misc/ajax.es6.js @@ -120,7 +120,7 @@ // exception here. try { statusText = `\n${Drupal.t('StatusText: !statusText', { - '!statusText': $.trim(xmlhttp.statusText), + '!statusText': xmlhttp.statusText.trim(), })}`; } catch (e) { // Empty. @@ -131,7 +131,7 @@ // xmlhttp.responseText is going to throw an exception. So we'll catch it. try { responseText = `\n${Drupal.t('ResponseText: !responseText', { - '!responseText': $.trim(xmlhttp.responseText), + '!responseText': xmlhttp.responseText.trim(), })}`; } catch (e) { // Empty. diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 621866e7c4a7..cbfd1a79a9cd 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -83,7 +83,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len try { statusText = "\n".concat(Drupal.t('StatusText: !statusText', { - '!statusText': $.trim(xmlhttp.statusText) + '!statusText': xmlhttp.statusText.trim() })); } catch (e) {} @@ -91,7 +91,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len try { responseText = "\n".concat(Drupal.t('ResponseText: !responseText', { - '!responseText': $.trim(xmlhttp.responseText) + '!responseText': xmlhttp.responseText.trim() })); } catch (e) {} diff --git a/core/misc/autocomplete.es6.js b/core/misc/autocomplete.es6.js index bdfd774aa907..56565bf58a39 100644 --- a/core/misc/autocomplete.es6.js +++ b/core/misc/autocomplete.es6.js @@ -38,7 +38,7 @@ } } if (value.length > 0) { - result.push($.trim(current)); + result.push(current.trim()); } return result; diff --git a/core/misc/autocomplete.js b/core/misc/autocomplete.js index 8b083683837d..3b4a4a24251d 100644 --- a/core/misc/autocomplete.js +++ b/core/misc/autocomplete.js @@ -30,7 +30,7 @@ } if (value.length > 0) { - result.push($.trim(current)); + result.push(current.trim()); } return result; diff --git a/core/misc/details-summarized-content.es6.js b/core/misc/details-summarized-content.es6.js index 30b67af8b445..79f87cf321eb 100644 --- a/core/misc/details-summarized-content.es6.js +++ b/core/misc/details-summarized-content.es6.js @@ -54,7 +54,7 @@ * Update summary. */ onSummaryUpdated() { - const text = $.trim(this.$node.drupalGetSummary()); + const text = this.$node.drupalGetSummary(); this.$detailsSummarizedContentWrapper.html( Drupal.theme('detailsSummarizedContentText', text), ); diff --git a/core/misc/details-summarized-content.js b/core/misc/details-summarized-content.js index 1080d7d6e074..d1b2d8d694ce 100644 --- a/core/misc/details-summarized-content.js +++ b/core/misc/details-summarized-content.js @@ -20,7 +20,7 @@ this.$node.on('summaryUpdated', $.proxy(this.onSummaryUpdated, this)).trigger('summaryUpdated').find('> summary').append(this.$detailsSummarizedContentWrapper); }, onSummaryUpdated: function onSummaryUpdated() { - var text = $.trim(this.$node.drupalGetSummary()); + var text = this.$node.drupalGetSummary(); this.$detailsSummarizedContentWrapper.html(Drupal.theme('detailsSummarizedContentText', text)); } }); diff --git a/core/misc/form.es6.js b/core/misc/form.es6.js index 78eeccafccba..ad02ee6dac41 100644 --- a/core/misc/form.es6.js +++ b/core/misc/form.es6.js @@ -31,7 +31,7 @@ */ $.fn.drupalGetSummary = function () { const callback = this.data('summaryCallback'); - return this[0] && callback ? $.trim(callback(this[0])) : ''; + return this[0] && callback ? callback(this[0]).trim() : ''; }; /** diff --git a/core/misc/form.js b/core/misc/form.js index 4064c1ddf6bb..bc6f0524b1d1 100644 --- a/core/misc/form.js +++ b/core/misc/form.js @@ -8,7 +8,7 @@ (function ($, Drupal, debounce) { $.fn.drupalGetSummary = function () { var callback = this.data('summaryCallback'); - return this[0] && callback ? $.trim(callback(this[0])) : ''; + return this[0] && callback ? callback(this[0]).trim() : ''; }; $.fn.drupalSetSummary = function (callback) { diff --git a/core/modules/ckeditor/js/ckeditor.stylescombo.admin.es6.js b/core/modules/ckeditor/js/ckeditor.stylescombo.admin.es6.js index 37ce549ae88d..26a377bbc1d6 100644 --- a/core/modules/ckeditor/js/ckeditor.stylescombo.admin.es6.js +++ b/core/modules/ckeditor/js/ckeditor.stylescombo.admin.es6.js @@ -36,7 +36,7 @@ $context .find('[name="editor[settings][plugins][stylescombo][styles]"]') .on('blur.ckeditorStylesComboSettings', function () { - const styles = $.trim($(this).val()); + const styles = $(this).val().trim(); const stylesSet = that._generateStylesSetSetting(styles); if (!_.isEqual(previousStylesSet, stylesSet)) { previousStylesSet = stylesSet; @@ -68,7 +68,7 @@ styles = styles.replace(/\r/g, '\n'); const lines = styles.split('\n'); for (let i = 0; i < lines.length; i++) { - const style = $.trim(lines[i]); + const style = lines[i].trim(); // Ignore empty lines in between non-empty lines. if (style.length === 0) { @@ -116,16 +116,16 @@ attach() { $('[data-ckeditor-plugin-id="stylescombo"]').drupalSetSummary( (context) => { - const styles = $.trim( - $( - '[data-drupal-selector="edit-editor-settings-plugins-stylescombo-styles"]', - ).val(), - ); + const styles = $( + '[data-drupal-selector="edit-editor-settings-plugins-stylescombo-styles"]', + ) + .val() + .trim(); if (styles.length === 0) { return Drupal.t('No styles configured'); } - const count = $.trim(styles).split('\n').length; + const count = styles.split('\n').length; return Drupal.t('@count styles configured', { '@count': count }); }, ); diff --git a/core/modules/ckeditor/js/ckeditor.stylescombo.admin.js b/core/modules/ckeditor/js/ckeditor.stylescombo.admin.js index 5e29f33f7522..164d16bc1bbd 100644 --- a/core/modules/ckeditor/js/ckeditor.stylescombo.admin.js +++ b/core/modules/ckeditor/js/ckeditor.stylescombo.admin.js @@ -13,7 +13,7 @@ var previousStylesSet = drupalSettings.ckeditor.hiddenCKEditorConfig.stylesSet; var that = this; $context.find('[name="editor[settings][plugins][stylescombo][styles]"]').on('blur.ckeditorStylesComboSettings', function () { - var styles = $.trim($(this).val()); + var styles = $(this).val().trim(); var stylesSet = that._generateStylesSetSetting(styles); @@ -31,7 +31,7 @@ var lines = styles.split('\n'); for (var i = 0; i < lines.length; i++) { - var style = $.trim(lines[i]); + var style = lines[i].trim(); if (style.length === 0) { continue; @@ -61,13 +61,13 @@ Drupal.behaviors.ckeditorStylesComboSettingsSummary = { attach: function attach() { $('[data-ckeditor-plugin-id="stylescombo"]').drupalSetSummary(function (context) { - var styles = $.trim($('[data-drupal-selector="edit-editor-settings-plugins-stylescombo-styles"]').val()); + var styles = $('[data-drupal-selector="edit-editor-settings-plugins-stylescombo-styles"]').val().trim(); if (styles.length === 0) { return Drupal.t('No styles configured'); } - var count = $.trim(styles).split('\n').length; + var count = styles.split('\n').length; return Drupal.t('@count styles configured', { '@count': count }); diff --git a/core/modules/menu_ui/menu_ui.admin.es6.js b/core/modules/menu_ui/menu_ui.admin.es6.js index d2e4dd46bd37..69b0d6843e3a 100644 --- a/core/modules/menu_ui/menu_ui.admin.es6.js +++ b/core/modules/menu_ui/menu_ui.admin.es6.js @@ -32,7 +32,7 @@ $menu.find('input:checked').each(function () { // Get the names of all checked menus. - values.push(Drupal.checkPlain($.trim($(this).val()))); + values.push(Drupal.checkPlain($(this).val())); }); $.ajax({ diff --git a/core/modules/menu_ui/menu_ui.admin.js b/core/modules/menu_ui/menu_ui.admin.js index 26d9716bca65..62442f0b2e43 100644 --- a/core/modules/menu_ui/menu_ui.admin.js +++ b/core/modules/menu_ui/menu_ui.admin.js @@ -22,7 +22,7 @@ var $menu = $('#edit-menu'); var values = []; $menu.find('input:checked').each(function () { - values.push(Drupal.checkPlain($.trim($(this).val()))); + values.push(Drupal.checkPlain($(this).val())); }); $.ajax({ url: "".concat(window.location.protocol, "//").concat(window.location.host).concat(Drupal.url('admin/structure/menu/parents')), diff --git a/core/modules/node/node.es6.js b/core/modules/node/node.es6.js index 004bd0658d0d..45a670241727 100644 --- a/core/modules/node/node.es6.js +++ b/core/modules/node/node.es6.js @@ -44,7 +44,7 @@ .find('input:checked') .next('label') .each(function () { - vals.push(Drupal.checkPlain($.trim($(this).text()))); + vals.push(Drupal.checkPlain($(this).text().trim())); }); return vals.join(', '); } diff --git a/core/modules/node/node.js b/core/modules/node/node.js index ebca1208a7f0..52e221e9acde 100644 --- a/core/modules/node/node.js +++ b/core/modules/node/node.js @@ -39,7 +39,7 @@ if ($optionsContext.find('input').is(':checked')) { $optionsContext.find('input:checked').next('label').each(function () { - vals.push(Drupal.checkPlain($.trim($(this).text()))); + vals.push(Drupal.checkPlain($(this).text().trim())); }); return vals.join(', '); } diff --git a/core/modules/quickedit/js/editors/plainTextEditor.es6.js b/core/modules/quickedit/js/editors/plainTextEditor.es6.js index df0293e26868..a7d99f90d8b0 100644 --- a/core/modules/quickedit/js/editors/plainTextEditor.es6.js +++ b/core/modules/quickedit/js/editors/plainTextEditor.es6.js @@ -30,12 +30,12 @@ const $fieldItems = this.$el.find('.quickedit-field'); const $textElement = $fieldItems.length ? $fieldItems.eq(0) : this.$el; this.$textElement = $textElement; - editorModel.set('originalValue', $.trim(this.$textElement.text())); + editorModel.set('originalValue', this.$textElement.text().trim()); // Sets the state to 'changed' whenever the value changes. let previousText = editorModel.get('originalValue'); $textElement.on('keyup paste', (event) => { - const currentText = $.trim($textElement.text()); + const currentText = $textElement.text().trim(); if (previousText !== currentText) { previousText = currentText; editorModel.set('currentValue', currentText); diff --git a/core/modules/quickedit/js/editors/plainTextEditor.js b/core/modules/quickedit/js/editors/plainTextEditor.js index 44a7f8e4d06e..6021bd6ab152 100644 --- a/core/modules/quickedit/js/editors/plainTextEditor.js +++ b/core/modules/quickedit/js/editors/plainTextEditor.js @@ -15,10 +15,10 @@ var $fieldItems = this.$el.find('.quickedit-field'); var $textElement = $fieldItems.length ? $fieldItems.eq(0) : this.$el; this.$textElement = $textElement; - editorModel.set('originalValue', $.trim(this.$textElement.text())); + editorModel.set('originalValue', this.$textElement.text().trim()); var previousText = editorModel.get('originalValue'); $textElement.on('keyup paste', function (event) { - var currentText = $.trim($textElement.text()); + var currentText = $textElement.text().trim(); if (previousText !== currentText) { previousText = currentText; diff --git a/core/modules/views_ui/js/views-admin.es6.js b/core/modules/views_ui/js/views-admin.es6.js index e27b39971904..3af166d7c7a2 100644 --- a/core/modules/views_ui/js/views-admin.es6.js +++ b/core/modules/views_ui/js/views-admin.es6.js @@ -312,7 +312,7 @@ */ Drupal.viewsUi.AddItemForm.prototype.handleCheck = function (event) { const $target = $(event.target); - const label = $.trim($target.closest('td').next().html()); + const label = $target.closest('td').next().html().trim(); // Add/remove the checked item to the list. if ($target.is(':checked')) { this.$selected_div.show().css('display', 'block'); diff --git a/core/modules/views_ui/js/views-admin.js b/core/modules/views_ui/js/views-admin.js index e6dd88e82435..a0568d6a4e5a 100644 --- a/core/modules/views_ui/js/views-admin.js +++ b/core/modules/views_ui/js/views-admin.js @@ -129,7 +129,7 @@ Drupal.viewsUi.AddItemForm.prototype.handleCheck = function (event) { var $target = $(event.target); - var label = $.trim($target.closest('td').next().html()); + var label = $target.closest('td').next().html().trim(); if ($target.is(':checked')) { this.$selected_div.show().css('display', 'block'); -- GitLab