Issue #3239134 by hooroomoo, bnjmnm, yogeshmpawar, nod_, Theresa.Grannum, larowlan: Refactor (if feasible) uses of the jQuery val function to use VanillaJS

merge-requests/1667/head
Lauri Eskola 2022-01-17 18:09:08 +02:00
parent 203860a3ce
commit 611b7d1c66
No known key found for this signature in database
GPG Key ID: 382FC0F5B0DF53F8
87 changed files with 458 additions and 323 deletions

View File

@ -49,7 +49,7 @@
"jquery/no-toggle": 0,
"jquery/no-trigger": 0,
"jquery/no-trim": 2,
"jquery/no-val": 0,
"jquery/no-val": 2,
"jquery/no-when": 0,
"jquery/no-wrap": 0
}

View File

@ -311,6 +311,7 @@ drupal.ajax:
- core/jquery
- core/drupal
- core/drupalSettings
- core/drupal.nodelist.foreach
- core/drupal.progress
- core/once
- core/jquery.once.bc
@ -677,6 +678,7 @@ drupal.timezone:
js:
misc/timezone.js: {}
dependencies:
- core/drupal.nodelist.foreach
- core/jquery
- core/once
- core/jquery.once.bc

View File

@ -1570,9 +1570,13 @@
* The XMLHttpRequest status.
*/
update_build_id(ajax, response, status) {
$(`input[name="form_build_id"][value="${response.old}"]`).val(
response.new,
);
document
.querySelectorAll(
`input[name="form_build_id"][value="${response.old}"]`,
)
.forEach((item) => {
item.value = response.new;
});
},
/**

View File

@ -656,7 +656,9 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
$(response.selector).find('> tbody > tr:visible, > tr:visible').removeClass('odd even').filter(':even').addClass('odd').end().filter(':odd').addClass('even');
},
update_build_id: function update_build_id(ajax, response, status) {
$("input[name=\"form_build_id\"][value=\"".concat(response.old, "\"]")).val(response.new);
document.querySelectorAll("input[name=\"form_build_id\"][value=\"".concat(response.old, "\"]")).forEach(function (item) {
item.value = response.new;
});
},
add_css: function add_css(ajax, response, status) {
$('head').prepend(response.data);

View File

@ -245,11 +245,16 @@
userInfo.forEach((info) => {
const $element = $forms.find(`[name=${info}]`);
const browserData = localStorage.getItem(`Drupal.visitor.${info}`);
const emptyOrDefault =
$element.val() === '' ||
$element.attr('data-drupal-default-value') === $element.val();
if ($element.length && emptyOrDefault && browserData) {
$element.val(browserData);
if (!$element.length) {
return;
}
const emptyValue = $element[0].value === '';
const defaultValue =
$element.attr('data-drupal-default-value') === $element[0].value;
if (browserData && (emptyValue || defaultValue)) {
$element.each(function (index, item) {
item.value = browserData;
});
}
});
}
@ -257,7 +262,7 @@
userInfo.forEach((info) => {
const $element = $forms.find(`[name=${info}]`);
if ($element.length) {
localStorage.setItem(`Drupal.visitor.${info}`, $element.val());
localStorage.setItem(`Drupal.visitor.${info}`, $element[0].value);
}
});
});

View File

@ -104,10 +104,18 @@
userInfo.forEach(function (info) {
var $element = $forms.find("[name=".concat(info, "]"));
var browserData = localStorage.getItem("Drupal.visitor.".concat(info));
var emptyOrDefault = $element.val() === '' || $element.attr('data-drupal-default-value') === $element.val();
if ($element.length && emptyOrDefault && browserData) {
$element.val(browserData);
if (!$element.length) {
return;
}
var emptyValue = $element[0].value === '';
var defaultValue = $element.attr('data-drupal-default-value') === $element[0].value;
if (browserData && (emptyValue || defaultValue)) {
$element.each(function (index, item) {
item.value = browserData;
});
}
});
}
@ -117,7 +125,7 @@
var $element = $forms.find("[name=".concat(info, "]"));
if ($element.length) {
localStorage.setItem("Drupal.visitor.".concat(info), $element.val());
localStorage.setItem("Drupal.visitor.".concat(info), $element[0].value);
}
});
});

View File

@ -55,7 +55,7 @@
function machineNameHandler(e) {
const data = e.data;
const options = data.options;
const baseValue = $(e.target).val();
const baseValue = e.target.value;
const rx = new RegExp(options.replace_pattern, 'g');
const expected = baseValue
@ -119,7 +119,7 @@
// Hide the form item container of the machine name form element.
$wrapper.addClass('visually-hidden');
// Initial machine name from the target field default value.
const machine = $target.val();
const machine = $target[0].value;
// Append the machine name preview to the source field.
const $preview = $(
`<span class="machine-name-value">${
@ -150,8 +150,8 @@
// If no initial value, determine machine name based on the
// human-readable form element value.
if (machine === '' && $source.val() !== '') {
self.transliterate($source.val(), options).done((machineName) => {
if (machine === '' && $source[0].value !== '') {
self.transliterate($source[0].value, options).done((machineName) => {
self.showMachineName(
machineName.substr(0, options.maxlength),
eventData,
@ -170,7 +170,7 @@
// Preview the machine name in realtime when the human-readable name
// changes, but only if there is no machine name yet; i.e., only upon
// initial creation, not when editing.
if ($target.val() === '') {
if ($target[0].value === '') {
$source
.on('formUpdated.machineName', eventData, machineNameHandler)
// Initialize machine name preview.
@ -188,7 +188,7 @@
// Set the machine name to the transliterated value.
if (machine !== '') {
if (machine !== settings.replace) {
data.$target.val(machine);
data.$target[0].value = machine;
data.$preview.html(
settings.field_prefix +
Drupal.checkPlain(machine) +
@ -198,7 +198,7 @@
data.$suffix.show();
} else {
data.$suffix.hide();
data.$target.val(machine);
data.$target[0].value = machine;
data.$preview.empty();
}
},

View File

@ -24,7 +24,7 @@
function machineNameHandler(e) {
var data = e.data;
var options = data.options;
var baseValue = $(e.target).val();
var baseValue = e.target.value;
var rx = new RegExp(options.replace_pattern, 'g');
var expected = baseValue.toLowerCase().replace(rx, options.replace).substr(0, options.maxlength);
@ -66,7 +66,7 @@
options.maxlength = $target.attr('maxlength');
$wrapper.addClass('visually-hidden');
var machine = $target.val();
var machine = $target[0].value;
var $preview = $("<span class=\"machine-name-value\">".concat(options.field_prefix).concat(Drupal.checkPlain(machine)).concat(options.field_suffix, "</span>"));
$suffix.empty();
@ -89,8 +89,8 @@
options: options
};
if (machine === '' && $source.val() !== '') {
self.transliterate($source.val(), options).done(function (machineName) {
if (machine === '' && $source[0].value !== '') {
self.transliterate($source[0].value, options).done(function (machineName) {
self.showMachineName(machineName.substr(0, options.maxlength), eventData);
});
}
@ -98,7 +98,7 @@
var $link = $("<span class=\"admin-link\"><button type=\"button\" class=\"link\">".concat(Drupal.t('Edit'), "</button></span>")).on('click', eventData, clickEditHandler);
$suffix.append($link);
if ($target.val() === '') {
if ($target[0].value === '') {
$source.on('formUpdated.machineName', eventData, machineNameHandler).trigger('formUpdated.machineName');
}
@ -110,14 +110,14 @@
if (machine !== '') {
if (machine !== settings.replace) {
data.$target.val(machine);
data.$target[0].value = machine;
data.$preview.html(settings.field_prefix + Drupal.checkPlain(machine) + settings.field_suffix);
}
data.$suffix.show();
} else {
data.$suffix.hide();
data.$target.val(machine);
data.$target[0].value = machine;
data.$preview.empty();
}
},

View File

@ -1137,8 +1137,11 @@
});
} else {
// Assume a numeric input field.
let weight =
parseInt($(siblings[0]).find(targetClass).val(), 10) || 0;
let weight = 0;
const $siblingTarget = $(siblings[0]).find(targetClass);
if ($siblingTarget.length) {
weight = parseInt($siblingTarget[0].value, 10) || 0;
}
$(siblings)
.find(targetClass)
.each(function () {

View File

@ -688,7 +688,13 @@ function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "functi
}
});
} else {
var weight = parseInt($(siblings[0]).find(targetClass).val(), 10) || 0;
var weight = 0;
var $siblingTarget = $(siblings[0]).find(targetClass);
if ($siblingTarget.length) {
weight = parseInt($siblingTarget[0].value, 10) || 0;
}
$(siblings).find(targetClass).each(function () {
this.value = weight;
weight++;

View File

@ -13,12 +13,13 @@
attach(context, settings) {
const timezone = once('timezone', '.timezone-detect', context);
if (timezone.length) {
const $timezone = $(timezone);
const tz = new Intl.DateTimeFormat().resolvedOptions().timeZone;
// Ensure that the timezone value returned by the browser is supported
// by the server.
if (tz && $timezone.find(`option[value="${tz}"]`).length) {
$timezone.val(tz);
if (tz && $(timezone).find(`option[value="${tz}"]`).length) {
timezone.forEach((item) => {
item.value = tz;
});
return;
}
@ -71,7 +72,9 @@
dataType: 'json',
success(data) {
if (data) {
$timezone.val(data);
document.querySelectorAll('.timezone-detect').forEach((item) => {
item.value = data;
});
}
},
});

View File

@ -11,11 +11,12 @@
var timezone = once('timezone', '.timezone-detect', context);
if (timezone.length) {
var $timezone = $(timezone);
var tz = new Intl.DateTimeFormat().resolvedOptions().timeZone;
if (tz && $timezone.find("option[value=\"".concat(tz, "\"]")).length) {
$timezone.val(tz);
if (tz && $(timezone).find("option[value=\"".concat(tz, "\"]")).length) {
timezone.forEach(function (item) {
item.value = tz;
});
return;
}
@ -48,7 +49,9 @@
dataType: 'json',
success: function success(data) {
if (data) {
$timezone.val(data);
document.querySelectorAll('.timezone-detect').forEach(function (item) {
item.value = data;
});
}
}
});

View File

@ -64,7 +64,8 @@
once('vertical-tabs', '[data-vertical-tabs-panes]', context).forEach(
(verticalTab) => {
const $this = $(verticalTab).addClass('vertical-tabs__panes');
const focusID = $this.find(':hidden.vertical-tabs__active-tab').val();
const focusID = $this.find(':hidden.vertical-tabs__active-tab')[0]
.value;
let tabFocus;
// Check if there are some details that can be converted to
@ -180,8 +181,8 @@
})
.end()
.show()
.siblings(':hidden.vertical-tabs__active-tab')
.val(this.details.attr('id'));
.siblings(':hidden.vertical-tabs__active-tab')[0].value =
this.details.attr('id');
this.item.addClass('is-selected');
// Mark the active tab for screen readers.
$('#active-vertical-tab').remove();

View File

@ -24,7 +24,7 @@
$(once('vertical-tabs-fragments', 'body')).on('formFragmentLinkClickOrHashChange.verticalTabs', handleFragmentLinkClickOrHashChange);
once('vertical-tabs', '[data-vertical-tabs-panes]', context).forEach(function (verticalTab) {
var $this = $(verticalTab).addClass('vertical-tabs__panes');
var focusID = $this.find(':hidden.vertical-tabs__active-tab').val();
var focusID = $this.find(':hidden.vertical-tabs__active-tab')[0].value;
var tabFocus;
var $details = $this.find('> details');
@ -93,7 +93,7 @@
var tab = $(this).data('verticalTab');
tab.details.hide();
tab.item.removeClass('is-selected');
}).end().show().siblings(':hidden.vertical-tabs__active-tab').val(this.details.attr('id'));
}).end().show().siblings(':hidden.vertical-tabs__active-tab')[0].value = this.details.attr('id');
this.item.addClass('is-selected');
$('#active-vertical-tab').remove();
this.link.append("<span id=\"active-vertical-tab\" class=\"visually-hidden\">".concat(Drupal.t('(active tab)'), "</span>"));

View File

@ -33,7 +33,7 @@
* The jQuery event for the keyup event that triggered the filter.
*/
function filterBlockList(e) {
const query = $(e.target).val().toLowerCase();
const query = e.target.value.toLowerCase();
/**
* Shows or hides the block entry based on the query.

View File

@ -13,7 +13,7 @@
var $filterRows;
function filterBlockList(e) {
var query = $(e.target).val().toLowerCase();
var query = e.target.value.toLowerCase();
function toggleBlockEntry(index, label) {
var $label = $(label);

View File

@ -55,7 +55,7 @@
const $pages = $(context).find(
'textarea[name="visibility[request_path][pages]"]',
);
if (!$pages.val()) {
if (!$pages.length || !$pages[0].value) {
return Drupal.t('Not restricted');
}
@ -157,13 +157,13 @@
.find(`.region-${region}-message`)
.nextUntil('.region-title')
.find('select.block-weight')
.val(
.each(function () {
// Increment the weight before assigning it to prevent using the
// absolute minimum available weight. This way we always have an
// unused upper and lower bound, which makes manually setting the
// weights easier for users who prefer to do it that way.
() => ++weight,
);
this.value = ++weight;
});
}
const table = $('#blocks');
@ -211,7 +211,7 @@
weightField
.removeClass(`block-weight-${oldRegionName}`)
.addClass(`block-weight-${regionName}`);
regionField.val(regionName);
regionField[0].value = regionName;
}
updateBlockWeights(table, regionName);

View File

@ -32,7 +32,7 @@
$('[data-drupal-selector="edit-visibility-request-path"]').drupalSetSummary(function (context) {
var $pages = $(context).find('textarea[name="visibility[request_path][pages]"]');
if (!$pages.val()) {
if (!$pages.length || !$pages[0].value) {
return Drupal.t('Not restricted');
}
@ -76,8 +76,8 @@
function updateBlockWeights(table, region) {
var weight = -Math.round(table.find('.draggable').length / 2);
table.find(".region-".concat(region, "-message")).nextUntil('.region-title').find('select.block-weight').val(function () {
return ++weight;
table.find(".region-".concat(region, "-message")).nextUntil('.region-title').find('select.block-weight').each(function () {
this.value = ++weight;
});
}
@ -106,7 +106,7 @@
var oldRegionName = weightField[0].className.replace(/([^ ]+[ ]+)*block-weight-([^ ]+)([ ]+[^ ]+)*/, '$2');
regionField.removeClass("block-region-".concat(oldRegionName)).addClass("block-region-".concat(regionName));
weightField.removeClass("block-weight-".concat(oldRegionName)).addClass("block-weight-".concat(regionName));
regionField.val(regionName);
regionField[0].value = regionName;
}
updateBlockWeights(table, regionName);

View File

@ -18,7 +18,7 @@
.find('.book-outline-form')
.drupalSetSummary((context) => {
const $select = $(context).find('.book-title-select');
const val = $select.val();
const val = $select[0].value;
if (val === '0') {
return Drupal.t('Not in book');

View File

@ -10,7 +10,7 @@
attach: function attach(context) {
$(context).find('.book-outline-form').drupalSetSummary(function (context) {
var $select = $(context).find('.book-title-select');
var val = $select.val();
var val = $select[0].value;
if (val === '0') {
return Drupal.t('Not in book');

View File

@ -41,7 +41,7 @@
// Create a configuration model.
Drupal.ckeditor.models.Model = new Drupal.ckeditor.Model({
$textarea,
activeEditorConfig: JSON.parse($textarea.val()),
activeEditorConfig: JSON.parse($textarea[0].value),
hiddenEditorConfig: drupalSettings.ckeditor.hiddenCKEditorConfig,
});

View File

@ -17,7 +17,7 @@
$configurationForm.append(drupalSettings.ckeditor.toolbarAdmin);
Drupal.ckeditor.models.Model = new Drupal.ckeditor.Model({
$textarea: $textarea,
activeEditorConfig: JSON.parse($textarea.val()),
activeEditorConfig: JSON.parse($textarea[0].value),
hiddenEditorConfig: drupalSettings.ckeditor.hiddenCKEditorConfig
});
var viewDefaults = {

View File

@ -19,17 +19,23 @@
const root =
'input[name="editor[settings][plugins][drupalimage][image_upload]';
const $status = $(`${root}[status]"]`);
const $maxFileSize = $(`${root}[max_size]"]`);
const $maxWidth = $(`${root}[max_dimensions][width]"]`);
const $maxHeight = $(`${root}[max_dimensions][height]"]`);
const maxFileSizeElement = document.querySelector(
`${root}[max_size]"]`,
);
const maxWidth = document.querySelector(
`${root}[max_dimensions][width]"]`,
);
const maxHeight = document.querySelector(
`${root}[max_dimensions][height]"]`,
);
const $scheme = $(`${root}[scheme]"]:checked`);
const maxFileSize = $maxFileSize.val()
? $maxFileSize.val()
: $maxFileSize.attr('placeholder');
const maxFileSize = maxFileSizeElement.value
? maxFileSizeElement.value
: maxFileSizeElement.getAttribute('placeholder');
const maxDimensions =
$maxWidth.val() && $maxHeight.val()
? `(${$maxWidth.val()}x${$maxHeight.val()})`
maxWidth.value && maxHeight.value
? `(${maxWidth.value}x${maxHeight.value})`
: '';
if (!$status.is(':checked')) {

View File

@ -11,12 +11,12 @@
$('[data-ckeditor-plugin-id="drupalimage"]').drupalSetSummary(function (context) {
var root = 'input[name="editor[settings][plugins][drupalimage][image_upload]';
var $status = $("".concat(root, "[status]\"]"));
var $maxFileSize = $("".concat(root, "[max_size]\"]"));
var $maxWidth = $("".concat(root, "[max_dimensions][width]\"]"));
var $maxHeight = $("".concat(root, "[max_dimensions][height]\"]"));
var maxFileSizeElement = document.querySelector("".concat(root, "[max_size]\"]"));
var maxWidth = document.querySelector("".concat(root, "[max_dimensions][width]\"]"));
var maxHeight = document.querySelector("".concat(root, "[max_dimensions][height]\"]"));
var $scheme = $("".concat(root, "[scheme]\"]:checked"));
var maxFileSize = $maxFileSize.val() ? $maxFileSize.val() : $maxFileSize.attr('placeholder');
var maxDimensions = $maxWidth.val() && $maxHeight.val() ? "(".concat($maxWidth.val(), "x").concat($maxHeight.val(), ")") : '';
var maxFileSize = maxFileSizeElement.value ? maxFileSizeElement.value : maxFileSizeElement.getAttribute('placeholder');
var maxDimensions = maxWidth.value && maxHeight.value ? "(".concat(maxWidth.value, "x").concat(maxHeight.value, ")") : '';
if (!$status.is(':checked')) {
return Drupal.t('Uploads disabled');

View File

@ -36,7 +36,7 @@
$context
.find('[name="editor[settings][plugins][stylescombo][styles]"]')
.on('blur.ckeditorStylesComboSettings', function () {
const styles = $(this).val().trim();
const styles = this.value.trim();
const stylesSet = that._generateStylesSetSetting(styles);
if (!_.isEqual(previousStylesSet, stylesSet)) {
previousStylesSet = stylesSet;
@ -116,11 +116,11 @@
attach() {
$('[data-ckeditor-plugin-id="stylescombo"]').drupalSetSummary(
(context) => {
const styles = $(
const stylesElement = document.querySelector(
'[data-drupal-selector="edit-editor-settings-plugins-stylescombo-styles"]',
)
.val()
.trim();
);
const styles = stylesElement ? stylesElement.value.trim() : '';
if (styles.length === 0) {
return Drupal.t('No styles configured');
}

View File

@ -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 = $(this).val().trim();
var styles = this.value.trim();
var stylesSet = that._generateStylesSetSetting(styles);
@ -61,7 +61,8 @@
Drupal.behaviors.ckeditorStylesComboSettingsSummary = {
attach: function attach() {
$('[data-ckeditor-plugin-id="stylescombo"]').drupalSetSummary(function (context) {
var styles = $('[data-drupal-selector="edit-editor-settings-plugins-stylescombo-styles"]').val().trim();
var stylesElement = document.querySelector('[data-drupal-selector="edit-editor-settings-plugins-stylescombo-styles"]');
var styles = stylesElement ? stylesElement.value.trim() : '';
if (styles.length === 0) {
return Drupal.t('No styles configured');

View File

@ -139,8 +139,8 @@
});
// Change input value.
if ($(input).val() && $(input).val() !== color) {
$(input).val(color);
if (input.value && input.value !== color) {
input.value = color;
// Update locked values.
if (propagate) {

View File

@ -79,8 +79,8 @@
color: farb.RGBToHSL(farb.unpack(color))[2] > 0.5 ? '#000' : '#fff'
});
if ($(input).val() && $(input).val() !== color) {
$(input).val(color);
if (input.value && input.value !== color) {
input.value = color;
if (propagate) {
i = input.i;

View File

@ -49,7 +49,7 @@
let column;
function filterFieldsList(index, field) {
return $(field).val() === column;
return field.value === column;
}
// A field that has many different translatable parts can also define one

View File

@ -32,7 +32,7 @@
var column;
function filterFieldsList(index, field) {
return $(field).val() === column;
return field.value === column;
}
Object.keys(dependentColumns || {}).forEach(function (index) {

View File

@ -109,10 +109,10 @@
* The text format change event.
*/
function onTextFormatChange(event) {
const $select = $(event.target);
const select = event.target;
const field = event.data.field;
const activeFormatID = field.getAttribute('data-editor-active-text-format');
const newFormatID = $select.val();
const newFormatID = select.value;
// Prevent double-attaching if the change event is triggered manually.
if (newFormatID === activeFormatID) {
@ -132,7 +132,7 @@
const message = Drupal.t(
'Changing the text format to %text_format will permanently remove content that is not allowed in that text format.<br><br>Save your changes before switching the text format to avoid losing data.',
{
'%text_format': $select.find('option:selected').text(),
'%text_format': $(select).find('option:selected').text(),
},
);
const confirmationDialog = Drupal.dialog(`<div>${message}</div>`, {
@ -156,7 +156,7 @@
// cannot simply call event.preventDefault() because jQuery's
// change event is only triggered after the change has already
// been accepted.
$select.val(activeFormatID);
select.value = activeFormatID;
confirmationDialog.close();
},
},
@ -214,7 +214,7 @@
}
// Store the current active format.
const activeFormatID = $this.val();
const activeFormatID = editor.value;
field.setAttribute('data-editor-active-text-format', activeFormatID);
// Directly attach this text editor, if the text format is enabled.
@ -268,7 +268,7 @@
editors.forEach((editor) => {
const $this = $(editor);
const activeFormatID = $this.val();
const activeFormatID = editor.value;
const field = findFieldForFormatSelector($this);
if (field && activeFormatID in settings.editor.formats) {
Drupal.editorDetach(

View File

@ -52,10 +52,10 @@
}
function onTextFormatChange(event) {
var $select = $(event.target);
var select = event.target;
var field = event.data.field;
var activeFormatID = field.getAttribute('data-editor-active-text-format');
var newFormatID = $select.val();
var newFormatID = select.value;
if (newFormatID === activeFormatID) {
return;
@ -66,7 +66,7 @@
if (hasContent && supportContentFiltering) {
var message = Drupal.t('Changing the text format to %text_format will permanently remove content that is not allowed in that text format.<br><br>Save your changes before switching the text format to avoid losing data.', {
'%text_format': $select.find('option:selected').text()
'%text_format': $(select).find('option:selected').text()
});
var confirmationDialog = Drupal.dialog("<div>".concat(message, "</div>"), {
title: Drupal.t('Change text format?'),
@ -83,7 +83,7 @@
text: Drupal.t('Cancel'),
class: 'button',
click: function click() {
$select.val(activeFormatID);
select.value = activeFormatID;
confirmationDialog.close();
}
}],
@ -117,7 +117,7 @@
return;
}
var activeFormatID = $this.val();
var activeFormatID = editor.value;
field.setAttribute('data-editor-active-text-format', activeFormatID);
if (settings.editor.formats[activeFormatID]) {
@ -157,7 +157,7 @@
editors.forEach(function (editor) {
var $this = $(editor);
var activeFormatID = $this.val();
var activeFormatID = editor.value;
var field = findFieldForFormatSelector($this);
if (field && activeFormatID in settings.editor.formats) {

View File

@ -43,27 +43,32 @@
// When the user selects a new field type, clear the "existing field"
// selection.
$newFieldType.on('change', function () {
if ($(this).val() !== '') {
if (this.value !== '') {
// Reset the "existing storage name" selection.
$existingStorageName.val('').trigger('change');
if ($existingStorageName.length) {
$existingStorageName[0].value = '';
$existingStorageName.trigger('change');
}
}
});
// When the user selects an existing storage name, clear the "new field
// type" selection and populate the 'existing_storage_label' element.
$existingStorageName.on('change', function () {
const value = $(this).val();
const { value } = this;
if (value !== '') {
// Reset the "new field type" selection.
$newFieldType.val('').trigger('change');
if ($newFieldType.length) {
// Reset the "new field type" selection.
$newFieldType[0].value = '';
$newFieldType.trigger('change');
}
// Pre-populate the "existing storage label" element.
if (
typeof drupalSettings.existingFieldLabels[value] !== 'undefined'
) {
$existingStorageLabel.val(
drupalSettings.existingFieldLabels[value],
);
$existingStorageLabel[0].value =
drupalSettings.existingFieldLabels[value];
}
}
});
@ -152,8 +157,11 @@
// Handle region change.
const region = rowHandler.getRegion();
if (region !== rowHandler.region) {
// Remove parenting.
$row.find('select.js-field-parent').val('');
const $fieldParent = $row.find('select.js-field-parent');
if ($fieldParent.length) {
// Remove parenting.
$fieldParent[0].value = '';
}
// Let the row handler deal with the region change.
$.extend(refreshRows, rowHandler.regionChange(region));
// Update the row region.
@ -258,9 +266,11 @@
if (rowNames.length) {
// Add a throbber next each of the ajaxElements.
$(ajaxElements).after(Drupal.theme.ajaxProgressThrobber());
// Fire the Ajax update.
$('input[name=refresh_rows]').val(rowNames.join(' '));
const $refreshRows = $('input[name=refresh_rows]');
if ($refreshRows.length) {
// Fire the Ajax update.
$refreshRows[0].value = rowNames.join(' ');
}
$('input[data-drupal-selector="edit-refresh"]').trigger('mousedown');
// Disabled elements do not appear in POST ajax data, so we mark the
@ -318,7 +328,9 @@
* Either 'hidden' or 'content'.
*/
getRegion() {
return this.$regionSelect.val();
if (this.$regionSelect.length) {
return this.$regionSelect[0].value;
}
},
/**
@ -344,8 +356,10 @@
// Replace dashes with underscores.
region = region.replace(/-/g, '_');
// Set the region of the select list.
this.$regionSelect.val(region);
if (this.$regionSelect.length) {
// Set the region of the select list.
this.$regionSelect[0].value = region;
}
// Restore the formatter back to the default formatter only if it was
// disabled previously. Pseudo-fields do not have default formatters,
@ -354,10 +368,12 @@
const value =
typeof this.defaultPlugin !== 'undefined'
? this.defaultPlugin
: this.$pluginSelect.find('option').val();
: this.$pluginSelect.find('option')[0].value;
if (typeof value !== 'undefined') {
this.$pluginSelect.val(value);
if (this.$pluginSelect.length) {
this.$pluginSelect[0].value = value;
}
}
}

View File

@ -17,18 +17,24 @@
var $existingStorageName = $form.find('select[name="existing_storage_name"]');
var $existingStorageLabel = $form.find('input[name="existing_storage_label"]');
$newFieldType.on('change', function () {
if ($(this).val() !== '') {
$existingStorageName.val('').trigger('change');
if (this.value !== '') {
if ($existingStorageName.length) {
$existingStorageName[0].value = '';
$existingStorageName.trigger('change');
}
}
});
$existingStorageName.on('change', function () {
var value = $(this).val();
var value = this.value;
if (value !== '') {
$newFieldType.val('').trigger('change');
if ($newFieldType.length) {
$newFieldType[0].value = '';
$newFieldType.trigger('change');
}
if (typeof drupalSettings.existingFieldLabels[value] !== 'undefined') {
$existingStorageLabel.val(drupalSettings.existingFieldLabels[value]);
$existingStorageLabel[0].value = drupalSettings.existingFieldLabels[value];
}
}
});
@ -67,7 +73,12 @@
var region = rowHandler.getRegion();
if (region !== rowHandler.region) {
$row.find('select.js-field-parent').val('');
var $fieldParent = $row.find('select.js-field-parent');
if ($fieldParent.length) {
$fieldParent[0].value = '';
}
$.extend(refreshRows, rowHandler.regionChange(region));
rowHandler.region = region;
}
@ -119,7 +130,12 @@
if (rowNames.length) {
$(ajaxElements).after(Drupal.theme.ajaxProgressThrobber());
$('input[name=refresh_rows]').val(rowNames.join(' '));
var $refreshRows = $('input[name=refresh_rows]');
if ($refreshRows.length) {
$refreshRows[0].value = rowNames.join(' ');
}
$('input[data-drupal-selector="edit-refresh"]').trigger('mousedown');
$(ajaxElements).prop('disabled', true);
}
@ -142,17 +158,24 @@
Drupal.fieldUIDisplayOverview.field.prototype = {
getRegion: function getRegion() {
return this.$regionSelect.val();
if (this.$regionSelect.length) {
return this.$regionSelect[0].value;
}
},
regionChange: function regionChange(region) {
region = region.replace(/-/g, '_');
this.$regionSelect.val(region);
if (this.$regionSelect.length) {
this.$regionSelect[0].value = region;
}
if (this.region === 'hidden') {
var value = typeof this.defaultPlugin !== 'undefined' ? this.defaultPlugin : this.$pluginSelect.find('option').val();
var value = typeof this.defaultPlugin !== 'undefined' ? this.defaultPlugin : this.$pluginSelect.find('option')[0].value;
if (typeof value !== 'undefined') {
this.$pluginSelect.val(value);
if (this.$pluginSelect.length) {
this.$pluginSelect[0].value = value;
}
}
}

View File

@ -16,7 +16,7 @@
attach(context) {
function updateFilterGuidelines(event) {
const $this = $(event.target);
const value = $this.val();
const { value } = event.target;
$this
.closest('.js-filter-wrapper')
.find('[data-drupal-format-id]')

View File

@ -17,9 +17,9 @@
* An array of filter rules.
*/
getRules() {
const currentValue = $(
const currentValue = document.querySelector(
'#edit-filters-filter-html-settings-allowed-html',
).val();
).value;
const rules =
Drupal.behaviors.filterFilterHtmlUpdating._parseSetting(currentValue);

View File

@ -9,7 +9,7 @@
if (Drupal.filterConfiguration) {
Drupal.filterConfiguration.liveSettingParsers.filter_html = {
getRules: function getRules() {
var currentValue = $('#edit-filters-filter-html-settings-allowed-html').val();
var currentValue = document.querySelector('#edit-filters-filter-html-settings-allowed-html').value;
var rules = Drupal.behaviors.filterFilterHtmlUpdating._parseSetting(currentValue);

View File

@ -10,7 +10,7 @@
attach: function attach(context) {
function updateFilterGuidelines(event) {
var $this = $(event.target);
var value = $this.val();
var value = event.target.value;
$this.closest('.js-filter-wrapper').find('[data-drupal-format-id]').hide().filter("[data-drupal-format-id=\"".concat(value, "\"]")).show();
}

View File

@ -18,8 +18,7 @@
Drupal.quickedit.EditorView.prototype.initialize.call(this, options);
// Set our original value to our current HTML (for reverting).
this.model.set('originalValue', this.$el.html().trim());
// $.val() callback function for copying input from our custom form to
// the Quick Edit Field Form.
// Copy input from our custom form to the Quick Edit Field Form.
this.model.set('currentValue', function (index, value) {
const matches = $(this)
.attr('name')
@ -33,7 +32,7 @@
`.quickedit-image-field-info input[name="${name}"]`,
);
if ($input.length) {
return $input.val();
return $input[0].value;
}
}
});

View File

@ -19,7 +19,7 @@
var $input = $toolgroup.find(".quickedit-image-field-info input[name=\"".concat(name, "\"]"));
if ($input.length) {
return $input.val();
return $input[0].value;
}
}
});

View File

@ -32,7 +32,7 @@
* The jQuery event for the keyup event that triggered the filter.
*/
const filterBlockList = (e) => {
const query = $(e.target).val().toLowerCase();
const query = e.target.value.toLowerCase();
/**
* Shows or hides the block entry based on the query.

View File

@ -18,7 +18,7 @@
var $filterLinks = $categories.find('.js-layout-builder-block-link');
var filterBlockList = function filterBlockList(e) {
var query = $(e.target).val().toLowerCase();
var query = e.target.value.toLowerCase();
var toggleBlockEntry = function toggleBlockEntry(index, link) {
var $link = $(link);

View File

@ -23,14 +23,12 @@
$form.find('.file-import-input').on('change', function () {
// If the filename is fully the language code or the filename
// ends with a language code, pre-select that one.
const matches = $(this)
.val()
.match(/([^.][.]*)([\w-]+)\.po$/);
const matches = this.value.match(/([^.][.]*)([\w-]+)\.po$/);
if (
matches &&
$langcode.find(`option[value="${matches[2]}"]`).length
) {
$langcode.val(matches[2]);
$langcode[0].value = matches[2];
}
});
}

View File

@ -14,10 +14,10 @@
var $form = $(form);
var $langcode = $form.find('.langcode-input');
$form.find('.file-import-input').on('change', function () {
var matches = $(this).val().match(/([^.][.]*)([\w-]+)\.po$/);
var matches = this.value.match(/([^.][.]*)([\w-]+)\.po$/);
if (matches && $langcode.find("option[value=\"".concat(matches[2], "\"]")).length) {
$langcode.val(matches[2]);
$langcode[0].value = matches[2];
}
});
}

View File

@ -14,26 +14,27 @@
*/
Drupal.behaviors.mediaFormSummaries = {
attach(context) {
const $context = $(context);
$(context)
.find('.media-form-author')
.drupalSetSummary((context) => {
const nameInput = context.querySelector('.field--name-uid input');
const name = nameInput && nameInput.value;
const dateInput = context.querySelector('.field--name-created input');
const date = dateInput && dateInput.value;
$context.find('.media-form-author').drupalSetSummary((context) => {
const $authorContext = $(context);
const name = $authorContext.find('.field--name-uid input').val();
const date = $authorContext.find('.field--name-created input').val();
if (name && date) {
return Drupal.t('By @name on @date', {
'@name': name,
'@date': date,
});
}
if (name) {
return Drupal.t('By @name', { '@name': name });
}
if (date) {
return Drupal.t('Authored on @date', { '@date': date });
}
});
if (name && date) {
return Drupal.t('By @name on @date', {
'@name': name,
'@date': date,
});
}
if (name) {
return Drupal.t('By @name', { '@name': name });
}
if (date) {
return Drupal.t('Authored on @date', { '@date': date });
}
});
},
};
})(jQuery, Drupal);

View File

@ -8,11 +8,11 @@
(function ($, Drupal) {
Drupal.behaviors.mediaFormSummaries = {
attach: function attach(context) {
var $context = $(context);
$context.find('.media-form-author').drupalSetSummary(function (context) {
var $authorContext = $(context);
var name = $authorContext.find('.field--name-uid input').val();
var date = $authorContext.find('.field--name-created input').val();
$(context).find('.media-form-author').drupalSetSummary(function (context) {
var nameInput = context.querySelector('.field--name-uid input');
var name = nameInput && nameInput.value;
var dateInput = context.querySelector('.field--name-created input');
var date = dateInput && dateInput.value;
if (name && date) {
return Drupal.t('By @name on @date', {

View File

@ -342,18 +342,24 @@
currentSelection.splice(position, 1);
}
// Set the selection in the hidden form element.
$form
.find('#media-library-modal-selection')
.val(currentSelection.join())
.trigger('change');
const mediaLibraryModalSelection = document.querySelector(
'#media-library-modal-selection',
);
if (mediaLibraryModalSelection) {
// Set the selection in the hidden form element.
mediaLibraryModalSelection.value = currentSelection.join();
$(mediaLibraryModalSelection).trigger('change');
}
// Set the selection in the media library add form. Since the form is
// not necessarily loaded within the same context, we can't use the
// context here.
$('.js-media-library-add-form-current-selection').val(
currentSelection.join(),
);
document
.querySelectorAll('.js-media-library-add-form-current-selection')
.forEach((item) => {
item.value = currentSelection.join();
});
});
// The hidden selection form field changes when the selection is updated.

View File

@ -175,8 +175,16 @@
currentSelection.splice(position, 1);
}
$form.find('#media-library-modal-selection').val(currentSelection.join()).trigger('change');
$('.js-media-library-add-form-current-selection').val(currentSelection.join());
var mediaLibraryModalSelection = document.querySelector('#media-library-modal-selection');
if (mediaLibraryModalSelection) {
mediaLibraryModalSelection.value = currentSelection.join();
$(mediaLibraryModalSelection).trigger('change');
}
document.querySelectorAll('.js-media-library-add-form-current-selection').forEach(function (item) {
item.value = currentSelection.join();
});
});
$(once('media-library-selection-change', $form.find('#media-library-modal-selection'))).on('change', function (e) {
updateSelectionCount(settings.media_library.selection_remaining);

View File

@ -22,7 +22,7 @@
$(widget)
.children()
.each((index, child) => {
$(child).find('.js-media-library-item-weight').val(index);
$(child).find('.js-media-library-item-weight')[0].value = index;
});
},
});

View File

@ -15,7 +15,7 @@
handle: '.js-media-library-item-preview',
onEnd: function onEnd() {
$(widget).children().each(function (index, child) {
$(child).find('.js-media-library-item-weight').val(index);
$(child).find('.js-media-library-item-weight')[0].value = index;
});
}
});

View File

@ -32,6 +32,7 @@ ui:
dependencies:
- core/drupal.ajax
- core/drupal.announce
- core/drupal.nodelist.foreach
- core/once
- core/jquery.once.bc
- core/jquery

View File

@ -32,7 +32,7 @@
$menu.find('input:checked').each(function () {
// Get the names of all checked menus.
values.push(Drupal.checkPlain($(this).val()));
values.push(Drupal.checkPlain(this.value));
});
$.ajax({
@ -45,21 +45,17 @@
success(options) {
const $select = $('#edit-menu-parent');
// Save key of last selected element.
const selected = $select.val();
const selected = $select[0].value;
// Remove all existing options from dropdown.
$select.children().remove();
// Add new options to dropdown. Keep a count of options for testing later.
let totalOptions = 0;
Object.keys(options || {}).forEach((machineName) => {
$select.append(
$(
`<option ${
machineName === selected ? ' selected="selected"' : ''
}></option>`,
)
.val(machineName)
.text(options[machineName]),
);
const selectContents = document.createElement('option');
selectContents.selected = machineName === selected;
selectContents.value = machineName;
selectContents.innerText = options[machineName];
$select.append(selectContents);
totalOptions++;
});

View File

@ -22,7 +22,7 @@
var $menu = $('#edit-menu');
var values = [];
$menu.find('input:checked').each(function () {
values.push(Drupal.checkPlain($(this).val()));
values.push(Drupal.checkPlain(this.value));
});
$.ajax({
url: "".concat(window.location.protocol, "//").concat(window.location.host).concat(Drupal.url('admin/structure/menu/parents')),
@ -33,11 +33,15 @@
dataType: 'json',
success: function success(options) {
var $select = $('#edit-menu-parent');
var selected = $select.val();
var selected = $select[0].value;
$select.children().remove();
var totalOptions = 0;
Object.keys(options || {}).forEach(function (machineName) {
$select.append($("<option ".concat(machineName === selected ? ' selected="selected"' : '', "></option>")).val(machineName).text(options[machineName]));
var selectContents = document.createElement('option');
selectContents.selected = machineName === selected;
selectContents.value = machineName;
selectContents.innerText = options[machineName];
$select.append(selectContents);
totalOptions++;
});
$select.closest('div').toggle(totalOptions > 0).attr('hidden', totalOptions === 0);

View File

@ -22,7 +22,7 @@
$context.find('.js-form-item-menu-enabled input').is(':checked')
) {
return Drupal.checkPlain(
$context.find('.js-form-item-menu-title input').val(),
$context.find('.js-form-item-menu-title input')[0].value,
);
}
@ -60,7 +60,7 @@
// If there is a link title already, mark it as overridden. The user
// expects that toggling the checkbox twice will take over the node's
// title.
if ($checkbox.is(':checked') && $linkTitle.val().length) {
if ($checkbox.is(':checked') && $linkTitle[0].value.length) {
$linkTitle.data('menuLinkAutomaticTitleOverridden', true);
}
// Whenever the value is changed manually, disable this behavior.
@ -71,10 +71,10 @@
$checkbox.on('change', () => {
if ($checkbox.is(':checked')) {
if (!$linkTitle.data('menuLinkAutomaticTitleOverridden')) {
$linkTitle.val($title.val());
$linkTitle[0].value = $title[0].value;
}
} else {
$linkTitle.val('');
$linkTitle[0].value = '';
$linkTitle.removeData('menuLinkAutomaticTitleOverridden');
}
$checkbox.closest('.vertical-tabs-pane').trigger('summaryUpdated');
@ -86,8 +86,8 @@
!$linkTitle.data('menuLinkAutomaticTitleOverridden') &&
$checkbox.is(':checked')
) {
$linkTitle.val($title.val());
$linkTitle.val($title.val()).trigger('formUpdated');
$linkTitle[0].value = $title[0].value;
$linkTitle.trigger('formUpdated');
}
});
});

View File

@ -12,7 +12,7 @@
var $context = $(context);
if ($context.find('.js-form-item-menu-enabled input').is(':checked')) {
return Drupal.checkPlain($context.find('.js-form-item-menu-title input').val());
return Drupal.checkPlain($context.find('.js-form-item-menu-title input')[0].value);
}
return Drupal.t('Not in menu');
@ -32,7 +32,7 @@
return;
}
if ($checkbox.is(':checked') && $linkTitle.val().length) {
if ($checkbox.is(':checked') && $linkTitle[0].value.length) {
$linkTitle.data('menuLinkAutomaticTitleOverridden', true);
}
@ -42,10 +42,10 @@
$checkbox.on('change', function () {
if ($checkbox.is(':checked')) {
if (!$linkTitle.data('menuLinkAutomaticTitleOverridden')) {
$linkTitle.val($title.val());
$linkTitle[0].value = $title[0].value;
}
} else {
$linkTitle.val('');
$linkTitle[0].value = '';
$linkTitle.removeData('menuLinkAutomaticTitleOverridden');
}
@ -54,8 +54,8 @@
});
$title.on('keyup', function () {
if (!$linkTitle.data('menuLinkAutomaticTitleOverridden') && $checkbox.is(':checked')) {
$linkTitle.val($title.val());
$linkTitle.val($title.val()).trigger('formUpdated');
$linkTitle[0].value = $title[0].value;
$linkTitle.trigger('formUpdated');
}
});
});

View File

@ -19,7 +19,7 @@
$context.find('#edit-submission').drupalSetSummary((context) => {
const vals = [];
vals.push(
Drupal.checkPlain($(context).find('#edit-title-label').val()) ||
Drupal.checkPlain($(context).find('#edit-title-label')[0].value) ||
Drupal.t('Requires a title'),
);
return vals.join(', ');

View File

@ -11,7 +11,7 @@
var $context = $(context);
$context.find('#edit-submission').drupalSetSummary(function (context) {
var vals = [];
vals.push(Drupal.checkPlain($(context).find('#edit-title-label').val()) || Drupal.t('Requires a title'));
vals.push(Drupal.checkPlain($(context).find('#edit-title-label')[0].value) || Drupal.t('Requires a title'));
return vals.join(', ');
});
$context.find('#edit-workflow').drupalSetSummary(function (context) {

View File

@ -17,9 +17,10 @@
const $context = $(context);
$context.find('.node-form-author').drupalSetSummary((context) => {
const $authorContext = $(context);
const name = $authorContext.find('.field--name-uid input').val();
const date = $authorContext.find('.field--name-created input').val();
const nameElement = context.querySelector('.field--name-uid input');
const name = nameElement && nameElement.value;
const dateElement = context.querySelector('.field--name-created input');
const date = dateElement && dateElement.value;
if (name && date) {
return Drupal.t('By @name on @date', {

View File

@ -10,9 +10,10 @@
attach: function attach(context) {
var $context = $(context);
$context.find('.node-form-author').drupalSetSummary(function (context) {
var $authorContext = $(context);
var name = $authorContext.find('.field--name-uid input').val();
var date = $authorContext.find('.field--name-created input').val();
var nameElement = context.querySelector('.field--name-uid input');
var name = nameElement && nameElement.value;
var dateElement = context.querySelector('.field--name-created input');
var date = dateElement && dateElement.value;
if (name && date) {
return Drupal.t('By @name on @date', {

View File

@ -16,8 +16,10 @@
$(context)
.find('.path-form')
.drupalSetSummary((context) => {
const path = $('.js-form-item-path-0-alias input').val();
const pathElement = document.querySelector(
'.js-form-item-path-0-alias input',
);
const path = pathElement && pathElement.value;
return path
? Drupal.t('Alias: @alias', { '@alias': path })
: Drupal.t('No alias');

View File

@ -9,7 +9,8 @@
Drupal.behaviors.pathDetailsSummaries = {
attach: function attach(context) {
$(context).find('.path-form').drupalSetSummary(function (context) {
var path = $('.js-form-item-path-0-alias input').val();
var pathElement = document.querySelector('.js-form-item-path-0-alias input');
var path = pathElement && pathElement.value;
return path ? Drupal.t('Alias: @alias', {
'@alias': path
}) : Drupal.t('No alias');

View File

@ -198,6 +198,7 @@
const $form = $(`#${backstageId}`).find('form');
// Fill in the value in any <input> that isn't hidden or a submit
// button.
// eslint-disable-next-line jquery/no-val
$form
.find(':input[type!="hidden"][type!="submit"]:not(select)')
// Don't mess with the node summary.

View File

@ -42,7 +42,7 @@
* The jQuery event triggered.
*/
function dateFormatHandler(e) {
const baseValue = $(e.target).val() || '';
const baseValue = e.target.value || '';
const dateString = baseValue.replace(/\\?(.?)/gi, (key, value) =>
dateFormats[key] ? dateFormats[key] : value,
);

View File

@ -20,7 +20,7 @@
var $preview = $target.find('em');
function dateFormatHandler(e) {
var baseValue = $(e.target).val() || '';
var baseValue = e.target.value || '';
var dateString = baseValue.replace(/\\?(.?)/gi, function (key, value) {
return dateFormats[key] ? dateFormats[key] : value;
});

View File

@ -58,9 +58,9 @@
* Custom value from jQuery trigger.
*/
valueTargetCopyHandler(e, value) {
const $target = $(e.target);
if ($target.val() === '') {
$target.val(value);
const { target } = e;
if (target.value === '') {
target.value = value;
}
},
@ -74,7 +74,7 @@
* The event triggered.
*/
valueSourceBlurHandler(e) {
const value = $(e.target).val();
const { value } = e.target;
const targetIds = drupalSettings.copyFieldValue[e.target.id];
$(`#${targetIds.join(', #')}`).trigger('value:copy', value);
},

View File

@ -25,14 +25,14 @@
}
},
valueTargetCopyHandler: function valueTargetCopyHandler(e, value) {
var $target = $(e.target);
var target = e.target;
if ($target.val() === '') {
$target.val(value);
if (target.value === '') {
target.value = value;
}
},
valueSourceBlurHandler: function valueSourceBlurHandler(e) {
var value = $(e.target).val();
var value = e.target.value;
var targetIds = drupalSettings.copyFieldValue[e.target.id];
$("#".concat(targetIds.join(', #'))).trigger('value:copy', value);
}

View File

@ -35,7 +35,7 @@
}
function filterModuleList(e) {
const query = $(e.target).val();
const query = e.target.value;
// Case insensitive expression to find query at the beginning of a word.
const re = new RegExp(`\\b${query}`, 'i');

View File

@ -41,7 +41,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
}
function filterModuleList(e) {
var query = $(e.target).val();
var query = e.target.value;
var re = new RegExp("\\b".concat(query), 'i');
function showModuleRow(index, row) {

View File

@ -3,7 +3,7 @@
* Testing behavior for JSWebAssertTest.
*/
(function ($, Drupal, drupalSettings) {
(function (Drupal, drupalSettings) {
/**
* @type {Drupal~behavior}
*
@ -12,9 +12,13 @@
*/
Drupal.behaviors.js_webassert_test_wait_for_ajax_request = {
attach(context) {
$('input[name="test_assert_wait_on_ajax_input"]').val(
'js_webassert_test',
const waitAjaxInput = document.querySelector(
'input[name="test_assert_wait_on_ajax_input"]',
);
// Confirm the input exists before assigning a value to it.
if (waitAjaxInput) {
waitAjaxInput.value = 'js_webassert_test';
}
},
};
})(jQuery, Drupal, drupalSettings);
})(Drupal, drupalSettings);

View File

@ -5,10 +5,14 @@
* @preserve
**/
(function ($, Drupal, drupalSettings) {
(function (Drupal, drupalSettings) {
Drupal.behaviors.js_webassert_test_wait_for_ajax_request = {
attach: function attach(context) {
$('input[name="test_assert_wait_on_ajax_input"]').val('js_webassert_test');
var waitAjaxInput = document.querySelector('input[name="test_assert_wait_on_ajax_input"]');
if (waitAjaxInput) {
waitAjaxInput.value = 'js_webassert_test';
}
}
};
})(jQuery, Drupal, drupalSettings);
})(Drupal, drupalSettings);

View File

@ -3,7 +3,6 @@ wait_for_ajax_request:
js:
js/js_webassert_test.wait_for_ajax_request.js: {}
dependencies:
- core/jquery
- core/drupal
wait_for_element:
version: VERSION

View File

@ -64,7 +64,7 @@
.appendTo($summaryLabel);
// If no summary is set, hide the summary field.
if ($widget.find('.js-text-summary').val() === '') {
if (summary.value === '') {
$link.trigger('click');
}
});

View File

@ -44,7 +44,7 @@
toggleClick = !toggleClick;
}).appendTo($summaryLabel);
if ($widget.find('.js-text-summary').val() === '') {
if (summary.value === '') {
$link.trigger('click');
}
});

View File

@ -287,9 +287,9 @@
const $orientationToggle = this.$el
.find('.toolbar-toggle-orientation')
.toggle(this.model.get('isTrayToggleVisible'));
$orientationToggle
.find('button')
.val(antiOrientation)
const $orientationToggleButton = $orientationToggle.find('button');
$orientationToggleButton[0].value = antiOrientation;
$orientationToggleButton
.attr('title', this.strings[antiOrientation])
.text(this.strings[antiOrientation])
.removeClass(iconClass)

View File

@ -135,7 +135,9 @@
var iconClass = "toolbar-icon-toggle-".concat(orientation);
var iconAntiClass = "toolbar-icon-toggle-".concat(antiOrientation);
var $orientationToggle = this.$el.find('.toolbar-toggle-orientation').toggle(this.model.get('isTrayToggleVisible'));
$orientationToggle.find('button').val(antiOrientation).attr('title', this.strings[antiOrientation]).text(this.strings[antiOrientation]).removeClass(iconClass).addClass(iconAntiClass);
var $orientationToggleButton = $orientationToggle.find('button');
$orientationToggleButton[0].value = antiOrientation;
$orientationToggleButton.attr('title', this.strings[antiOrientation]).text(this.strings[antiOrientation]).removeClass(iconClass).addClass(iconAntiClass);
var dir = document.documentElement.dir;
var edge = dir === 'rtl' ? 'right' : 'left';
$trays.removeAttr('data-offset-left data-offset-right data-offset-top');

View File

@ -169,12 +169,12 @@
const addWidgetClasses = () => {
$passwordWidget
.addClass(
$mainInput.val()
$mainInput[0].value
? cssClasses.passwordFilled
: cssClasses.passwordEmpty,
)
.addClass(
$confirmInput.val()
$confirmInput[0].value
? cssClasses.confirmFilled
: cssClasses.confirmEmpty,
);
@ -187,7 +187,7 @@
* The value of the confirm input.
*/
const passwordCheckMatch = (confirmInputVal) => {
const passwordsAreMatching = $mainInput.val() === confirmInputVal;
const passwordsAreMatching = $mainInput[0].value === confirmInputVal;
const confirmClass = passwordsAreMatching
? cssClasses.passwordsMatch
: cssClasses.passwordsNotMatch;
@ -216,7 +216,7 @@
if (settings.password.showStrengthIndicator) {
// Evaluate the password strength.
const result = Drupal.evaluatePasswordStrength(
$mainInput.val(),
$mainInput[0].value,
settings.password,
);
const $currentPasswordSuggestions = $(
@ -255,8 +255,8 @@
}
// Check the value in the confirm input and show results.
if ($confirmInput.val()) {
passwordCheckMatch($confirmInput.val());
if ($confirmInput[0].value) {
passwordCheckMatch($confirmInput[0].value);
$passwordConfirmMessage.css({ visibility: 'visible' });
} else {
$passwordConfirmMessage.css({ visibility: 'hidden' });
@ -310,7 +310,9 @@
// otherwise use value from the database.
const $usernameBox = $('input.username');
const username =
$usernameBox.length > 0 ? $usernameBox.val() : passwordSettings.username;
$usernameBox.length > 0
? $usernameBox[0].value
: passwordSettings.username;
// Lose 5 points for every character less than 12, plus a 30 point penalty.
if (password.length < 12) {

View File

@ -75,11 +75,11 @@
}
var addWidgetClasses = function addWidgetClasses() {
$passwordWidget.addClass($mainInput.val() ? cssClasses.passwordFilled : cssClasses.passwordEmpty).addClass($confirmInput.val() ? cssClasses.confirmFilled : cssClasses.confirmEmpty);
$passwordWidget.addClass($mainInput[0].value ? cssClasses.passwordFilled : cssClasses.passwordEmpty).addClass($confirmInput[0].value ? cssClasses.confirmFilled : cssClasses.confirmEmpty);
};
var passwordCheckMatch = function passwordCheckMatch(confirmInputVal) {
var passwordsAreMatching = $mainInput.val() === confirmInputVal;
var passwordsAreMatching = $mainInput[0].value === confirmInputVal;
var confirmClass = passwordsAreMatching ? cssClasses.passwordsMatch : cssClasses.passwordsNotMatch;
var confirmMessage = passwordsAreMatching ? settings.password.confirmSuccess : settings.password.confirmFailure;
@ -94,7 +94,7 @@
var passwordCheck = function passwordCheck() {
if (settings.password.showStrengthIndicator) {
var result = Drupal.evaluatePasswordStrength($mainInput.val(), settings.password);
var result = Drupal.evaluatePasswordStrength($mainInput[0].value, settings.password);
var $currentPasswordSuggestions = $(Drupal.theme('passwordSuggestions', settings.password, result.messageTips));
if (password.$suggestions.html() !== $currentPasswordSuggestions.html()) {
@ -110,8 +110,8 @@
password.$strengthTextWrapper.html(result.indicatorText);
}
if ($confirmInput.val()) {
passwordCheckMatch($confirmInput.val());
if ($confirmInput[0].value) {
passwordCheckMatch($confirmInput[0].value);
$passwordConfirmMessage.css({
visibility: 'visible'
});
@ -149,7 +149,7 @@
var hasNumbers = /[0-9]/.test(password);
var hasPunctuation = /[^a-zA-Z0-9]/.test(password);
var $usernameBox = $('input.username');
var username = $usernameBox.length > 0 ? $usernameBox.val() : passwordSettings.username;
var username = $usernameBox.length > 0 ? $usernameBox[0].value : passwordSettings.username;
if (password.length < 12) {
msg.push(passwordSettings.tooShort);

View File

@ -194,8 +194,13 @@
const href = $(this).attr('href');
// Cut of #views-tabset.
const displayId = href.substr(11);
// Set the form element.
$('#views-live-preview #preview-display-id').val(displayId);
const viewsPreviewId = document.querySelector(
'#views-live-preview #preview-display-id',
);
if (viewsPreviewId) {
// Set the form element if it is present.
viewsPreviewId.value = displayId;
}
});
},
};

View File

@ -71,7 +71,11 @@
$(once('views-ajax', '#views-tabset a')).on('click', function () {
var href = $(this).attr('href');
var displayId = href.substr(11);
$('#views-live-preview #preview-display-id').val(displayId);
var viewsPreviewId = document.querySelector('#views-live-preview #preview-display-id');
if (viewsPreviewId) {
viewsPreviewId.value = displayId;
}
});
}
};

View File

@ -207,7 +207,7 @@
* The source form field value.
*/
getTransliterated() {
let from = this.source.val();
let from = this.source.length ? this.source[0].value : '';
if (this.exclude) {
from = from.toLowerCase().replace(this.exclude, this.replace);
}
@ -223,7 +223,7 @@
this.target.each(function (i) {
// Ensure that the maxlength is not exceeded by prepopulating the field.
const maxlength = $(this).attr('maxlength') - suffix.length;
$(this).val(transliterated.substr(0, maxlength) + suffix);
this.value = transliterated.substr(0, maxlength) + suffix;
});
},
@ -390,9 +390,9 @@
// placed in an 'Add' dropdown. @todo This assumes English, but so does
// $addDisplayDropdown above. Add support for translation.
$displayButtons.each(function () {
const label = $(this).val();
const label = this.value;
if (label.substr(0, 4) === 'Add ') {
$(this).val(label.substr(4));
this.value = label.substr(4);
}
});
$addDisplayDropdown.appendTo($menu);
@ -559,10 +559,10 @@
handleFilter(event) {
// Determine the user's search query. The search text has been converted
// to lowercase.
const search = this.$searchBox.val().toLowerCase();
const search = this.$searchBox[0].value.toLowerCase();
const words = search.split(' ');
// Get selected Group
const group = this.$controlGroup.val();
const group = this.$controlGroup[0].value;
// Search through the search texts in the form for matching text.
this.options.forEach((option) => {
@ -753,7 +753,7 @@
// When the link is clicked, dynamically click the hidden form
// button for adding a new filter group.
$(
`<ul class="action-links"><li><a id="views-add-group-link" href="#">${this.addGroupButton.val()}</a></li></ul>`,
`<ul class="action-links"><li><a id="views-add-group-link" href="#">${this.addGroupButton[0].value}</a></li></ul>`,
).prependTo(this.table.parent()),
),
)
@ -896,7 +896,9 @@
const operators = this.dropdowns.find('select').not($target);
// Change the other operators to match this new value.
operators.val($target.val());
operators.each(function (index, item) {
item.value = $target[0].value;
});
},
/**
@ -984,7 +986,7 @@
groupField
.removeClass(`views-group-select-${oldGroupName}`)
.addClass(`views-group-select-${groupName}`);
groupField.val(groupName);
groupField[0].value = groupName;
}
};
},
@ -1236,26 +1238,28 @@
).forEach((dropdown) => {
// Closures! :(
const $context = $(context);
const $submit = $context.find('[id^=edit-submit]');
const oldValue = $submit.val();
const submit = context.querySelector('[id^=edit-submit]');
const oldValue = submit ? submit.value : '';
$(once('views-ui-override-button-text', $submit)).on(
$(once('views-ui-override-button-text', submit)).on(
'mouseup',
function () {
$(this).val(oldValue);
this.value = oldValue;
return true;
},
);
$(dropdown)
.on('change', function () {
const $this = $(this);
if ($this.val() === 'default') {
$submit.val(Drupal.t('Apply (all displays)'));
} else if ($this.val() === 'default_revert') {
$submit.val(Drupal.t('Revert to default'));
if (!submit) {
return;
}
if (this.value === 'default') {
submit.value = Drupal.t('Apply (all displays)');
} else if (this.value === 'default_revert') {
submit.value = Drupal.t('Revert to default');
} else {
$submit.val(Drupal.t('Apply (this display)'));
submit.value = Drupal.t('Apply (this display)');
}
const $dialog = $context.closest('.ui-dialog-content');
$dialog.trigger('dialogButtonsChange');

View File

@ -79,7 +79,7 @@
this.target.on('focus.viewsUi', this.unbind);
},
getTransliterated: function getTransliterated() {
var from = this.source.val();
var from = this.source.length ? this.source[0].value : '';
if (this.exclude) {
from = from.toLowerCase().replace(this.exclude, this.replace);
@ -92,7 +92,7 @@
var suffix = this.suffix;
this.target.each(function (i) {
var maxlength = $(this).attr('maxlength') - suffix.length;
$(this).val(transliterated.substr(0, maxlength) + suffix);
this.value = transliterated.substr(0, maxlength) + suffix;
});
},
_unbind: function _unbind() {
@ -170,10 +170,10 @@
var $displayButtons = $menu.nextAll('input.add-display').detach();
$displayButtons.appendTo($addDisplayDropdown.find('.action-list')).wrap('<li>').parent().eq(0).addClass('first').end().eq(-1).addClass('last');
$displayButtons.each(function () {
var label = $(this).val();
var label = this.value;
if (label.substr(0, 4) === 'Add ') {
$(this).val(label.substr(4));
this.value = label.substr(4);
}
});
$addDisplayDropdown.appendTo($menu);
@ -253,9 +253,9 @@
return options;
},
handleFilter: function handleFilter(event) {
var search = this.$searchBox.val().toLowerCase();
var search = this.$searchBox[0].value.toLowerCase();
var words = search.split(' ');
var group = this.$controlGroup.val();
var group = this.$controlGroup[0].value;
this.options.forEach(function (option) {
function hasWord(word) {
return option.searchText.indexOf(word) !== -1;
@ -320,7 +320,7 @@
$.extend(Drupal.viewsUi.RearrangeFilterHandler.prototype, {
insertAddRemoveFilterGroupLinks: function insertAddRemoveFilterGroupLinks() {
$(once('views-rearrange-filter-handler', $("<ul class=\"action-links\"><li><a id=\"views-add-group-link\" href=\"#\">".concat(this.addGroupButton.val(), "</a></li></ul>")).prependTo(this.table.parent()))).find('#views-add-group-link').on('click.views-rearrange-filter-handler', $.proxy(this, 'clickAddGroupButton'));
$(once('views-rearrange-filter-handler', $("<ul class=\"action-links\"><li><a id=\"views-add-group-link\" href=\"#\">".concat(this.addGroupButton[0].value, "</a></li></ul>")).prependTo(this.table.parent()))).find('#views-add-group-link').on('click.views-rearrange-filter-handler', $.proxy(this, 'clickAddGroupButton'));
var length = this.removeGroupButtons.length;
var i;
@ -380,7 +380,9 @@
operatorChangeHandler: function operatorChangeHandler(event) {
var $target = $(event.target);
var operators = this.dropdowns.find('select').not($target);
operators.val($target.val());
operators.each(function (index, item) {
item.value = $target[0].value;
});
},
modifyTableDrag: function modifyTableDrag() {
var tableDrag = Drupal.tableDrag['views-rearrange-filters'];
@ -423,7 +425,7 @@
if (!groupField.is(".views-group-select-".concat(groupName))) {
var oldGroupName = groupField.attr('class').replace(/([^ ]+[ ]+)*views-group-select-([^ ]+)([ ]+[^ ]+)*/, '$2');
groupField.removeClass("views-group-select-".concat(oldGroupName)).addClass("views-group-select-".concat(groupName));
groupField.val(groupName);
groupField[0].value = groupName;
}
};
},
@ -544,21 +546,23 @@
attach: function attach(context) {
once('views-ui-override-button-text', '[data-drupal-selector="edit-override-dropdown"]', context).forEach(function (dropdown) {
var $context = $(context);
var $submit = $context.find('[id^=edit-submit]');
var oldValue = $submit.val();
$(once('views-ui-override-button-text', $submit)).on('mouseup', function () {
$(this).val(oldValue);
var submit = context.querySelector('[id^=edit-submit]');
var oldValue = submit ? submit.value : '';
$(once('views-ui-override-button-text', submit)).on('mouseup', function () {
this.value = oldValue;
return true;
});
$(dropdown).on('change', function () {
var $this = $(this);
if (!submit) {
return;
}
if ($this.val() === 'default') {
$submit.val(Drupal.t('Apply (all displays)'));
} else if ($this.val() === 'default_revert') {
$submit.val(Drupal.t('Revert to default'));
if (this.value === 'default') {
submit.value = Drupal.t('Apply (all displays)');
} else if (this.value === 'default_revert') {
submit.value = Drupal.t('Revert to default');
} else {
$submit.val(Drupal.t('Apply (this display)'));
submit.value = Drupal.t('Apply (this display)');
}
var $dialog = $context.closest('.ui-dialog-content');

View File

@ -26,7 +26,7 @@
let $rows;
function filterViewList(e) {
const query = $(e.target).val().toLowerCase();
const query = e.target.value.toLowerCase();
function showViewRow(index, row) {
const $row = $(row);

View File

@ -32,7 +32,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var $rows;
function filterViewList(e) {
var query = $(e.target).val().toLowerCase();
var query = e.target.value.toLowerCase();
function showViewRow(index, row) {
var $row = $(row);

View File

@ -25,16 +25,22 @@
// Solid background.
$colorPreview.css(
'backgroundColor',
$colorPalette.find('input[name="palette[bg]"]').val(),
$colorPalette.find('input[name="palette[bg]"]')[0].value,
);
// Text preview.
$colorPreview
.find('.color-preview-main h2, .color-preview .preview-content')
.css('color', $colorPalette.find('input[name="palette[text]"]').val());
.css(
'color',
$colorPalette.find('input[name="palette[text]"]')[0].value,
);
$colorPreview
.find('.color-preview-content a')
.css('color', $colorPalette.find('input[name="palette[link]"]').val());
.css(
'color',
$colorPalette.find('input[name="palette[link]"]')[0].value,
);
// Sidebar block.
const $colorPreviewBlock = $colorPreview.find(
@ -42,11 +48,11 @@
);
$colorPreviewBlock.css(
'background-color',
$colorPalette.find('input[name="palette[sidebar]"]').val(),
$colorPalette.find('input[name="palette[sidebar]"]')[0].value,
);
$colorPreviewBlock.css(
'border-color',
$colorPalette.find('input[name="palette[sidebarborders]"]').val(),
$colorPalette.find('input[name="palette[sidebarborders]"]')[0].value,
);
// Footer wrapper background.
@ -54,16 +60,14 @@
.find('.color-preview-footer-wrapper')
.css(
'background-color',
$colorPalette.find('input[name="palette[footer]"]').val(),
$colorPalette.find('input[name="palette[footer]"]')[0].value,
);
// CSS3 Gradients.
const gradientStart = $colorPalette
.find('input[name="palette[top]"]')
.val();
const gradientEnd = $colorPalette
.find('input[name="palette[bottom]"]')
.val();
const gradientStart = $colorPalette.find('input[name="palette[top]"]')[0]
.value;
const gradientEnd = $colorPalette.find('input[name="palette[bottom]"]')[0]
.value;
$colorPreview
.find('.color-preview-header')
@ -76,7 +80,7 @@
.find('.color-preview-site-name')
.css(
'color',
$colorPalette.find('input[name="palette[titleslogan]"]').val(),
$colorPalette.find('input[name="palette[titleslogan]"]')[0].value,
);
},
};

View File

@ -20,17 +20,17 @@
var $colorPreview = $form.find('.color-preview');
var $colorPalette = $form.find('.js-color-palette');
$colorPreview.css('backgroundColor', $colorPalette.find('input[name="palette[bg]"]').val());
$colorPreview.find('.color-preview-main h2, .color-preview .preview-content').css('color', $colorPalette.find('input[name="palette[text]"]').val());
$colorPreview.find('.color-preview-content a').css('color', $colorPalette.find('input[name="palette[link]"]').val());
$colorPreview.css('backgroundColor', $colorPalette.find('input[name="palette[bg]"]')[0].value);
$colorPreview.find('.color-preview-main h2, .color-preview .preview-content').css('color', $colorPalette.find('input[name="palette[text]"]')[0].value);
$colorPreview.find('.color-preview-content a').css('color', $colorPalette.find('input[name="palette[link]"]')[0].value);
var $colorPreviewBlock = $colorPreview.find('.color-preview-sidebar .color-preview-block');
$colorPreviewBlock.css('background-color', $colorPalette.find('input[name="palette[sidebar]"]').val());
$colorPreviewBlock.css('border-color', $colorPalette.find('input[name="palette[sidebarborders]"]').val());
$colorPreview.find('.color-preview-footer-wrapper').css('background-color', $colorPalette.find('input[name="palette[footer]"]').val());
var gradientStart = $colorPalette.find('input[name="palette[top]"]').val();
var gradientEnd = $colorPalette.find('input[name="palette[bottom]"]').val();
$colorPreviewBlock.css('background-color', $colorPalette.find('input[name="palette[sidebar]"]')[0].value);
$colorPreviewBlock.css('border-color', $colorPalette.find('input[name="palette[sidebarborders]"]')[0].value);
$colorPreview.find('.color-preview-footer-wrapper').css('background-color', $colorPalette.find('input[name="palette[footer]"]')[0].value);
var gradientStart = $colorPalette.find('input[name="palette[top]"]')[0].value;
var gradientEnd = $colorPalette.find('input[name="palette[bottom]"]')[0].value;
$colorPreview.find('.color-preview-header').attr('style', "background-color: ".concat(gradientStart, "; background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(").concat(gradientStart, "), to(").concat(gradientEnd, ")); background-image: -moz-linear-gradient(-90deg, ").concat(gradientStart, ", ").concat(gradientEnd, ");"));
$colorPreview.find('.color-preview-site-name').css('color', $colorPalette.find('input[name="palette[titleslogan]"]').val());
$colorPreview.find('.color-preview-site-name').css('color', $colorPalette.find('input[name="palette[titleslogan]"]')[0].value);
}
};
})(jQuery, Drupal, drupalSettings);

View File

@ -104,7 +104,8 @@
once('vertical-tabs', '[data-vertical-tabs-panes]', context).forEach(
(panes) => {
const $this = $(panes).addClass('vertical-tabs__items--processed');
const focusID = $this.find(':hidden.vertical-tabs__active-tab').val();
const focusID = $this.find(':hidden.vertical-tabs__active-tab')[0]
.value;
let tabFocus;
// Check if there are some details that can be converted to

View File

@ -17,7 +17,7 @@
$(once('vertical-tabs-fragments', 'body')).on('formFragmentLinkClickOrHashChange.verticalTabs', handleFragmentLinkClickOrHashChange);
once('vertical-tabs', '[data-vertical-tabs-panes]', context).forEach(function (panes) {
var $this = $(panes).addClass('vertical-tabs__items--processed');
var focusID = $this.find(':hidden.vertical-tabs__active-tab').val();
var focusID = $this.find(':hidden.vertical-tabs__active-tab')[0].value;
var tabFocus;
var $details = $this.find('> details');