Commit 25c55e3c authored by hooroomoo's avatar hooroomoo Committed by larowlan
Browse files

Issue #3239132 by hooroomoo, larowlan, nod_, bnjmnm: Refactor (if feasible)...

Issue #3239132 by hooroomoo, larowlan, nod_, bnjmnm: Refactor (if feasible) uses of the jQuery trim function to use vanillaJS
parent aafc501d
......@@ -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
......
......@@ -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.
......
......@@ -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) {}
......
......@@ -38,7 +38,7 @@
}
}
if (value.length > 0) {
result.push($.trim(current));
result.push(current.trim());
}
return result;
......
......@@ -30,7 +30,7 @@
}
if (value.length > 0) {
result.push($.trim(current));
result.push(current.trim());
}
return result;
......
......@@ -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),
);
......
......@@ -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));
}
});
......
......@@ -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() : '';
};
/**
......
......@@ -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) {
......
......@@ -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 });
},
);
......
......@@ -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
});
......
......@@ -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({
......
......@@ -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')),
......
......@@ -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(', ');
}
......
......@@ -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(', ');
}
......
......@@ -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);
......
......@@ -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;
......
......@@ -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');
......
......@@ -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');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment