diff --git a/core/misc/states.es6.js b/core/misc/states.es6.js index b47b90de57..7e494f3571 100644 --- a/core/misc/states.es6.js +++ b/core/misc/states.es6.js @@ -120,38 +120,30 @@ * dependee's compliance status. */ initializeDependee(selector, dependeeStates) { - let state; - const self = this; - - function stateEventHandler(e) { - self.update(e.data.selector, e.data.state, e.value); - } - // Cache for the states of this dependee. this.values[selector] = {}; - // eslint-disable-next-line no-restricted-syntax - for (const i in dependeeStates) { - if (dependeeStates.hasOwnProperty(i)) { - state = dependeeStates[i]; - // Make sure we're not initializing this selector/state combination - // twice. - if ($.inArray(state, dependeeStates) === -1) { - continue; - } + Object.keys(dependeeStates).forEach((i) => { + let state = dependeeStates[i]; + // Make sure we're not initializing this selector/state combination + // twice. + if ($.inArray(state, dependeeStates) === -1) { + return; + } - state = states.State.sanitize(state); + state = states.State.sanitize(state); - // Initialize the value of this state. - this.values[selector][state.name] = null; + // Initialize the value of this state. + this.values[selector][state.name] = null; - // Monitor state changes of the specified state for this dependee. - $(selector).on(`state:${state}`, { selector, state }, stateEventHandler); + // Monitor state changes of the specified state for this dependee. + $(selector).on(`state:${state}`, { selector, state }, (e) => { + this.update(e.data.selector, e.data.state, e.value); + }); - // Make sure the event we just bound ourselves to is actually fired. - new states.Trigger({ selector, state }); - } - } + // Make sure the event we just bound ourselves to is actually fired. + new states.Trigger({ selector, state }); + }); }, /** @@ -260,18 +252,23 @@ // Make sure we don't try to iterate over things other than objects. This // shouldn't normally occur, but in case the condition definition is // bogus, we don't want to end up with an infinite loop. + else if ($.isPlainObject(constraints)) { // This constraint is an object (AND). - // eslint-disable-next-line no-restricted-syntax - for (const n in constraints) { - if (constraints.hasOwnProperty(n)) { - result = ternary(result, this.checkConstraints(constraints[n], selector, n)); - // False and anything else will evaluate to false, so return when - // any false condition is found. - if (result === false) { - return false; - } + if (Object.keys(constraints).every((constraint) => { + result = ternary( + result, + this.checkConstraints( + constraints[constraint], + selector, + constraint, + ), + ); + if (result === false) { + return false; } + })) { + return false; } } return result; diff --git a/core/misc/states.js b/core/misc/states.js index 4fd2052a43..2f5d039239 100644 --- a/core/misc/states.js +++ b/core/misc/states.js @@ -63,32 +63,27 @@ states.Dependent.prototype = { initializeDependee: function initializeDependee(selector, dependeeStates) { - var state = void 0; - var self = this; - - function stateEventHandler(e) { - self.update(e.data.selector, e.data.state, e.value); - } + var _this2 = this; this.values[selector] = {}; - for (var i in dependeeStates) { - if (dependeeStates.hasOwnProperty(i)) { - state = dependeeStates[i]; + Object.keys(dependeeStates).forEach(function (i) { + var state = dependeeStates[i]; - if ($.inArray(state, dependeeStates) === -1) { - continue; - } + if ($.inArray(state, dependeeStates) === -1) { + return; + } - state = states.State.sanitize(state); + state = states.State.sanitize(state); - this.values[selector][state.name] = null; + _this2.values[selector][state.name] = null; - $(selector).on('state:' + state, { selector: selector, state: state }, stateEventHandler); + $(selector).on('state:' + state, { selector: selector, state: state }, function (e) { + _this2.update(e.data.selector, e.data.state, e.value); + }); - new states.Trigger({ selector: selector, state: state }); - } - } + new states.Trigger({ selector: selector, state: state }); + }); }, compare: function compare(reference, selector, state) { var value = this.values[selector][state.name]; @@ -116,6 +111,8 @@ } }, verifyConstraints: function verifyConstraints(constraints, selector) { + var _this3 = this; + var result = void 0; if ($.isArray(constraints)) { var hasXor = $.inArray('xor', constraints) === -1; @@ -131,14 +128,13 @@ } } } else if ($.isPlainObject(constraints)) { - for (var n in constraints) { - if (constraints.hasOwnProperty(n)) { - result = ternary(result, this.checkConstraints(constraints[n], selector, n)); - - if (result === false) { - return false; - } + if (Object.keys(constraints).every(function (constraint) { + result = ternary(result, _this3.checkConstraints(constraints[constraint], selector, constraint)); + if (result === false) { + return false; } + })) { + return false; } } return result; @@ -188,7 +184,7 @@ states.Trigger.prototype = { initialize: function initialize() { - var _this2 = this; + var _this4 = this; var trigger = states.Trigger.states[this.state]; @@ -196,7 +192,7 @@ trigger.call(window, this.element); } else { Object.keys(trigger || {}).forEach(function (event) { - _this2.defaultTrigger(event, trigger[event]); + _this4.defaultTrigger(event, trigger[event]); }); } diff --git a/core/misc/tabledrag.es6.js b/core/misc/tabledrag.es6.js index 0a69deb2ca..29e8e03e6f 100644 --- a/core/misc/tabledrag.es6.js +++ b/core/misc/tabledrag.es6.js @@ -260,17 +260,15 @@ let columnIndex; Object.keys(this.tableSettings || {}).forEach((group) => { // Find the first field in this group. - // eslint-disable-next-line no-restricted-syntax - for (const d in this.tableSettings[group]) { - if (this.tableSettings[group].hasOwnProperty(d)) { - const field = $table.find(`.${this.tableSettings[group][d].target}`).eq(0); - if (field.length && this.tableSettings[group][d].hidden) { - hidden = this.tableSettings[group][d].hidden; - cell = field.closest('td'); - break; - } + Object.keys(this.tableSettings[group]).some((tableSetting) => { + const field = $table.find(`.${this.tableSettings[group][tableSetting].target}`).eq(0); + if (field.length && this.tableSettings[group][tableSetting].hidden) { + hidden = this.tableSettings[group][tableSetting].hidden; + cell = field.closest('td'); + return true; } - } + return false; + }); // Mark the column containing this field so it can be hidden. if (hidden && cell[0]) { @@ -412,23 +410,18 @@ Drupal.tableDrag.prototype.rowSettings = function (group, row) { const field = $(row).find(`.${group}`); const tableSettingsGroup = this.tableSettings[group]; - // eslint-disable-next-line no-restricted-syntax - for (const delta in tableSettingsGroup) { - if (tableSettingsGroup.hasOwnProperty(delta)) { - const targetClass = tableSettingsGroup[delta].target; - if (field.is(`.${targetClass}`)) { - // Return a copy of the row settings. - const rowSettings = {}; - // eslint-disable-next-line no-restricted-syntax - for (const n in tableSettingsGroup[delta]) { - if (tableSettingsGroup[delta].hasOwnProperty(n)) { - rowSettings[n] = tableSettingsGroup[delta][n]; - } - } - return rowSettings; - } + return Object.keys(tableSettingsGroup).map((delta) => { + const targetClass = tableSettingsGroup[delta].target; + let rowSettings; + if (field.is(`.${targetClass}`)) { + // Return a copy of the row settings. + rowSettings = {}; + Object.keys(tableSettingsGroup[delta]).forEach((n) => { + rowSettings[n] = tableSettingsGroup[delta][n]; + }); } - } + return rowSettings; + }).filter(rowSetting => rowSetting)[0]; }; /** @@ -879,11 +872,9 @@ if ((y > (rowY - rowHeight)) && (y < (rowY + rowHeight))) { if (this.indentEnabled) { // Check that this row is not a child of the row being dragged. - // eslint-disable-next-line no-restricted-syntax - for (n in this.rowObject.group) { - if (this.rowObject.group[n] === row) { - return null; - } + if (Object.keys(this.rowObject.group) + .some(o => (this.rowObject.group[o] === row))) { + return null; } } // Do not allow a row to be swapped with itself. diff --git a/core/misc/tabledrag.js b/core/misc/tabledrag.js index 06dccfab06..3330aeb8bb 100644 --- a/core/misc/tabledrag.js +++ b/core/misc/tabledrag.js @@ -4,6 +4,7 @@ * https://www.drupal.org/node/2815083 * @preserve **/ +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; (function ($, Drupal, drupalSettings) { var showWeight = JSON.parse(localStorage.getItem('Drupal.tableDrag.showWeight')); @@ -121,16 +122,15 @@ var cell = void 0; var columnIndex = void 0; Object.keys(this.tableSettings || {}).forEach(function (group) { - for (var d in _this2.tableSettings[group]) { - if (_this2.tableSettings[group].hasOwnProperty(d)) { - var field = $table.find('.' + _this2.tableSettings[group][d].target).eq(0); - if (field.length && _this2.tableSettings[group][d].hidden) { - hidden = _this2.tableSettings[group][d].hidden; - cell = field.closest('td'); - break; - } + Object.keys(_this2.tableSettings[group]).some(function (tableSetting) { + var field = $table.find('.' + _this2.tableSettings[group][tableSetting].target).eq(0); + if (field.length && _this2.tableSettings[group][tableSetting].hidden) { + hidden = _this2.tableSettings[group][tableSetting].hidden; + cell = field.closest('td'); + return true; } - } + return false; + }); if (hidden && cell[0]) { columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1; @@ -213,22 +213,19 @@ Drupal.tableDrag.prototype.rowSettings = function (group, row) { var field = $(row).find('.' + group); var tableSettingsGroup = this.tableSettings[group]; - - for (var delta in tableSettingsGroup) { - if (tableSettingsGroup.hasOwnProperty(delta)) { - var targetClass = tableSettingsGroup[delta].target; - if (field.is('.' + targetClass)) { - var rowSettings = {}; - - for (var n in tableSettingsGroup[delta]) { - if (tableSettingsGroup[delta].hasOwnProperty(n)) { - rowSettings[n] = tableSettingsGroup[delta][n]; - } - } - return rowSettings; - } + return Object.keys(tableSettingsGroup).map(function (delta) { + var targetClass = tableSettingsGroup[delta].target; + var rowSettings = void 0; + if (field.is('.' + targetClass)) { + rowSettings = {}; + Object.keys(tableSettingsGroup[delta]).forEach(function (n) { + rowSettings[n] = tableSettingsGroup[delta][n]; + }); } - } + return rowSettings; + }).filter(function (rowSetting) { + return rowSetting; + })[0]; }; Drupal.tableDrag.prototype.makeDraggable = function (item) { @@ -532,8 +529,11 @@ }; Drupal.tableDrag.prototype.findDropTargetRow = function (x, y) { + var _this3 = this; + var rows = $(this.table.tBodies[0].rows).not(':hidden'); - for (var n = 0; n < rows.length; n++) { + + var _loop = function _loop(n) { var row = rows[n]; var $row = $(row); var rowY = $row.offset().top; @@ -546,35 +546,49 @@ } if (y > rowY - rowHeight && y < rowY + rowHeight) { - if (this.indentEnabled) { - for (n in this.rowObject.group) { - if (this.rowObject.group[n] === row) { - return null; - } + if (_this3.indentEnabled) { + if (Object.keys(_this3.rowObject.group).some(function (o) { + return _this3.rowObject.group[o] === row; + })) { + return { + v: null + }; } - } else if (row === this.rowObject.element) { - return null; + } else if (row === _this3.rowObject.element) { + return { + v: null + }; } - if (!this.rowObject.isValidSwap(row)) { - return null; + if (!_this3.rowObject.isValidSwap(row)) { + return { + v: null + }; } while ($row.is(':hidden') && $row.prev('tr').is(':hidden')) { $row = $row.prev('tr:first-of-type'); row = $row.get(0); } - return row; + return { + v: row + }; } + }; + + for (var n = 0; n < rows.length; n++) { + var _ret = _loop(n); + + if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v; } return null; }; Drupal.tableDrag.prototype.updateFields = function (changedRow) { - var _this3 = this; + var _this4 = this; Object.keys(this.tableSettings || {}).forEach(function (group) { - _this3.updateField(changedRow, group); + _this4.updateField(changedRow, group); }); }; @@ -926,10 +940,10 @@ }; Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () { - var _this4 = this; + var _this5 = this; Object.keys(this.children || {}).forEach(function (n) { - $(_this4.children[n]).find('.js-indentation').removeClass('tree-child').removeClass('tree-child-first').removeClass('tree-child-last').removeClass('tree-child-horizontal'); + $(_this5.children[n]).find('.js-indentation').removeClass('tree-child').removeClass('tree-child-first').removeClass('tree-child-last').removeClass('tree-child-horizontal'); }); }; diff --git a/core/modules/color/color.es6.js b/core/modules/color/color.es6.js index c4f923a02d..42c032f9ad 100644 --- a/core/modules/color/color.es6.js +++ b/core/modules/color/color.es6.js @@ -14,9 +14,6 @@ */ Drupal.behaviors.color = { attach(context, settings) { - let i; - let j; - let colors; // This behavior attaches by ID, so is only valid once on a page. const form = $(context).find('#system-theme-settings .color-form').once('color'); if (form.length === 0) { @@ -53,7 +50,7 @@ // Each gradient line should have a height (or width for horizontal // gradients) of 10px (because we divided the height/width by 10 // above). - for (j = 0; j < (settings.gradients[i].direction === 'vertical' ? height[i] : width[i]); ++j) { + for (let j = 0; j < (settings.gradients[i].direction === 'vertical' ? height[i] : width[i]); ++j) { gradient.append('
'); } }); @@ -64,7 +61,7 @@ const colorScheme = this.options[this.selectedIndex].value; if (colorScheme !== '' && schemes[colorScheme]) { // Get colors of active scheme. - colors = schemes[colorScheme]; + const colors = schemes[colorScheme]; Object.keys(colors || {}).forEach((fieldName) => { callback($(`#edit-palette-${fieldName}`), colors[fieldName], false, true); }); @@ -154,6 +151,8 @@ */ function callback(input, color, propagate, colorScheme) { let matched; + let i; + let j; // Set background/foreground colors. $(input).css({ backgroundColor: color, diff --git a/core/modules/color/color.js b/core/modules/color/color.js index 5cc0b9be12..dc25998740 100644 --- a/core/modules/color/color.js +++ b/core/modules/color/color.js @@ -8,10 +8,6 @@ (function ($, Drupal) { Drupal.behaviors.color = { attach: function attach(context, settings) { - var i = void 0; - var j = void 0; - var colors = void 0; - var form = $(context).find('#system-theme-settings .color-form').once('color'); if (form.length === 0) { return; @@ -40,7 +36,7 @@ width.push(parseInt(gradient.css('width'), 10) / 10); - for (j = 0; j < (settings.gradients[i].direction === 'vertical' ? height[i] : width[i]); ++j) { + for (var j = 0; j < (settings.gradients[i].direction === 'vertical' ? height[i] : width[i]); ++j) { gradient.append('
'); } }); @@ -49,7 +45,7 @@ var schemes = settings.color.schemes; var colorScheme = this.options[this.selectedIndex].value; if (colorScheme !== '' && schemes[colorScheme]) { - colors = schemes[colorScheme]; + var colors = schemes[colorScheme]; Object.keys(colors || {}).forEach(function (fieldName) { callback($('#edit-palette-' + fieldName), colors[fieldName], false, true); }); @@ -95,6 +91,8 @@ function callback(input, color, propagate, colorScheme) { var matched = void 0; + var i = void 0; + var j = void 0; $(input).css({ backgroundColor: color, diff --git a/core/modules/editor/js/editor.admin.es6.js b/core/modules/editor/js/editor.admin.es6.js index a9c040c72e..5b7eac78b2 100644 --- a/core/modules/editor/js/editor.admin.es6.js +++ b/core/modules/editor/js/editor.admin.es6.js @@ -567,17 +567,10 @@ // If any filter's current status forbids the editor feature, return // false. Drupal.filterConfiguration.update(); - // eslint-disable-next-line no-restricted-syntax - for (const filterID in Drupal.filterConfiguration.statuses) { - if (Drupal.filterConfiguration.statuses.hasOwnProperty(filterID)) { - const filterStatus = Drupal.filterConfiguration.statuses[filterID]; - if (!(filterStatusAllowsFeature(filterStatus, feature))) { - return false; - } - } - } - - return true; + return Object.keys(Drupal.filterConfiguration.statuses) + .every(filterID => ( + filterStatusAllowsFeature(Drupal.filterConfiguration.statuses[filterID], feature) + )); }, }; diff --git a/core/modules/editor/js/editor.admin.js b/core/modules/editor/js/editor.admin.js index 9cec9ada6a..4a1014096e 100644 --- a/core/modules/editor/js/editor.admin.js +++ b/core/modules/editor/js/editor.admin.js @@ -256,17 +256,9 @@ } Drupal.filterConfiguration.update(); - - for (var filterID in Drupal.filterConfiguration.statuses) { - if (Drupal.filterConfiguration.statuses.hasOwnProperty(filterID)) { - var filterStatus = Drupal.filterConfiguration.statuses[filterID]; - if (!filterStatusAllowsFeature(filterStatus, feature)) { - return false; - } - } - } - - return true; + return Object.keys(Drupal.filterConfiguration.statuses).every(function (filterID) { + return filterStatusAllowsFeature(Drupal.filterConfiguration.statuses[filterID], feature); + }); } };