diff --git a/core/.eslintrc.passing.json b/core/.eslintrc.passing.json index db5f24e49d..24f22e857f 100644 --- a/core/.eslintrc.passing.json +++ b/core/.eslintrc.passing.json @@ -5,7 +5,6 @@ "no-use-before-define": "off", "no-throw-literal": "off", "no-shadow": "off", - "no-restricted-syntax": "off", "no-new": "off", "no-multi-assign": "off", "no-continue": "off", diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js index 5b449d5a34..c5aa9743c4 100644 --- a/core/misc/ajax.es6.js +++ b/core/misc/ajax.es6.js @@ -40,11 +40,7 @@ } // Load all Ajax behaviors specified in the settings. - for (const base in settings.ajax) { - if (settings.ajax.hasOwnProperty(base)) { - loadAjaxBehavior(base); - } - } + Object.keys(settings.ajax || {}).forEach(loadAjaxBehavior); Drupal.ajax.bindAjaxLinks(document.body); @@ -869,14 +865,14 @@ // Track if any command is altering the focus so we can avoid changing the // focus set by the Ajax command. let focusChanged = false; - for (const i in response) { - if (response.hasOwnProperty(i) && response[i].command && this.commands[response[i].command]) { + Object.keys(response).forEach((i) => { + if (response[i].command && this.commands[response[i].command]) { this.commands[response[i].command](this, response[i], status); if (response[i].command === 'invoke' && response[i].method === 'focus') { focusChanged = true; } } - } + }); // If the focus hasn't be changed by the ajax commands, try to refocus the // triggering element or one of its parents if that element does not exist diff --git a/core/misc/ajax.js b/core/misc/ajax.js index a899f4a9b9..eecb85b7de 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -21,11 +21,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr }); } - for (var base in settings.ajax) { - if (settings.ajax.hasOwnProperty(base)) { - loadAjaxBehavior(base); - } - } + Object.keys(settings.ajax || {}).forEach(loadAjaxBehavior); Drupal.ajax.bindAjaxLinks(document.body); @@ -395,6 +391,8 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr }; Drupal.Ajax.prototype.success = function (response, status) { + var _this = this; + if (this.progress.element) { $(this.progress.element).remove(); } @@ -406,14 +404,14 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr var elementParents = $(this.element).parents('[data-drupal-selector]').addBack().toArray(); var focusChanged = false; - for (var i in response) { - if (response.hasOwnProperty(i) && response[i].command && this.commands[response[i].command]) { - this.commands[response[i].command](this, response[i], status); + Object.keys(response).forEach(function (i) { + if (response[i].command && _this.commands[response[i].command]) { + _this.commands[response[i].command](_this, response[i], status); if (response[i].command === 'invoke' && response[i].method === 'focus') { focusChanged = true; } } - } + }); if (!focusChanged && this.element && !$(this.element).data('disable-refocus')) { var target = false; diff --git a/core/misc/drupal.es6.js b/core/misc/drupal.es6.js index 43a78f9f71..9cd4546f5c 100644 --- a/core/misc/drupal.es6.js +++ b/core/misc/drupal.es6.js @@ -152,8 +152,8 @@ window.Drupal = { behaviors: {}, locale: {} }; settings = settings || drupalSettings; const behaviors = Drupal.behaviors; // Execute all of them. - for (const i in behaviors) { - if (behaviors.hasOwnProperty(i) && typeof behaviors[i].attach === 'function') { + Object.keys(behaviors).forEach((i) => { + if (typeof behaviors[i].attach === 'function') { // Don't stop the execution of behaviors in case of an error. try { behaviors[i].attach(context, settings); @@ -162,7 +162,7 @@ window.Drupal = { behaviors: {}, locale: {} }; Drupal.throwError(e); } } - } + }); }; /** @@ -212,8 +212,8 @@ window.Drupal = { behaviors: {}, locale: {} }; trigger = trigger || 'unload'; const behaviors = Drupal.behaviors; // Execute all of them. - for (const i in behaviors) { - if (behaviors.hasOwnProperty(i) && typeof behaviors[i].detach === 'function') { + Object.keys(behaviors).forEach((i) => { + if (typeof behaviors[i].detach === 'function') { // Don't stop the execution of behaviors in case of an error. try { behaviors[i].detach(context, settings, trigger); @@ -222,7 +222,7 @@ window.Drupal = { behaviors: {}, locale: {} }; Drupal.throwError(e); } } - } + }); }; /** @@ -269,26 +269,24 @@ window.Drupal = { behaviors: {}, locale: {} }; // Keep args intact. const processedArgs = {}; // Transform arguments before inserting them. - for (const key in args) { - if (args.hasOwnProperty(key)) { - switch (key.charAt(0)) { - // Escaped only. - case '@': - processedArgs[key] = Drupal.checkPlain(args[key]); - break; - - // Pass-through. - case '!': - processedArgs[key] = args[key]; - break; - - // Escaped and placeholder. - default: - processedArgs[key] = Drupal.theme('placeholder', args[key]); - break; - } + Object.keys(args).forEach((key) => { + switch (key.charAt(0)) { + // Escaped only. + case '@': + processedArgs[key] = Drupal.checkPlain(args[key]); + break; + + // Pass-through. + case '!': + processedArgs[key] = args[key]; + break; + + // Escaped and placeholder. + default: + processedArgs[key] = Drupal.theme('placeholder', args[key]); + break; } - } + }); return Drupal.stringReplace(str, processedArgs, null); }; @@ -317,11 +315,7 @@ window.Drupal = { behaviors: {}, locale: {} }; // If the array of keys is not passed then collect the keys from the args. if (!Array.isArray(keys)) { keys = []; - for (const k in args) { - if (args.hasOwnProperty(k)) { - keys.push(k); - } - } + Object.keys(args).forEach(key => keys.push(key)); // Order the keys by the character length. The shortest one is the first. keys.sort((a, b) => a.length - b.length); diff --git a/core/misc/drupal.js b/core/misc/drupal.js index 0ede48da60..3cbe80490c 100644 --- a/core/misc/drupal.js +++ b/core/misc/drupal.js @@ -19,15 +19,15 @@ window.Drupal = { behaviors: {}, locale: {} }; settings = settings || drupalSettings; var behaviors = Drupal.behaviors; - for (var i in behaviors) { - if (behaviors.hasOwnProperty(i) && typeof behaviors[i].attach === 'function') { + Object.keys(behaviors).forEach(function (i) { + if (typeof behaviors[i].attach === 'function') { try { behaviors[i].attach(context, settings); } catch (e) { Drupal.throwError(e); } } - } + }); }; Drupal.detachBehaviors = function (context, settings, trigger) { @@ -36,15 +36,15 @@ window.Drupal = { behaviors: {}, locale: {} }; trigger = trigger || 'unload'; var behaviors = Drupal.behaviors; - for (var i in behaviors) { - if (behaviors.hasOwnProperty(i) && typeof behaviors[i].detach === 'function') { + Object.keys(behaviors).forEach(function (i) { + if (typeof behaviors[i].detach === 'function') { try { behaviors[i].detach(context, settings, trigger); } catch (e) { Drupal.throwError(e); } } - } + }); }; Drupal.checkPlain = function (str) { @@ -55,23 +55,21 @@ window.Drupal = { behaviors: {}, locale: {} }; Drupal.formatString = function (str, args) { var processedArgs = {}; - for (var key in args) { - if (args.hasOwnProperty(key)) { - switch (key.charAt(0)) { - case '@': - processedArgs[key] = Drupal.checkPlain(args[key]); - break; + Object.keys(args).forEach(function (key) { + switch (key.charAt(0)) { + case '@': + processedArgs[key] = Drupal.checkPlain(args[key]); + break; - case '!': - processedArgs[key] = args[key]; - break; + case '!': + processedArgs[key] = args[key]; + break; - default: - processedArgs[key] = Drupal.theme('placeholder', args[key]); - break; - } + default: + processedArgs[key] = Drupal.theme('placeholder', args[key]); + break; } - } + }); return Drupal.stringReplace(str, processedArgs, null); }; @@ -83,11 +81,9 @@ window.Drupal = { behaviors: {}, locale: {} }; if (!Array.isArray(keys)) { keys = []; - for (var k in args) { - if (args.hasOwnProperty(k)) { - keys.push(k); - } - } + Object.keys(args).forEach(function (key) { + return keys.push(key); + }); keys.sort(function (a, b) { return a.length - b.length; diff --git a/core/misc/states.es6.js b/core/misc/states.es6.js index fbf8db7c98..310fa3f97a 100644 --- a/core/misc/states.es6.js +++ b/core/misc/states.es6.js @@ -32,19 +32,19 @@ attach(context, settings) { const $states = $(context).find('[data-drupal-states]'); let config; - let state; const il = $states.length; + const createState = (i, state, config) => { + new states.Dependent({ + element: $($states[i]), + state: states.State.sanitize(state), + constraints: config[state], + }); + }; for (let i = 0; i < il; i++) { config = JSON.parse($states[i].getAttribute('data-drupal-states')); - for (state in config) { - if (config.hasOwnProperty(state)) { - new states.Dependent({ - element: $($states[i]), - state: states.State.sanitize(state), - constraints: config[state], - }); - } - } + Object.keys(config).forEach((state) => { + createState(i, state, config); + }); } // Execute all postponed functions now. @@ -74,11 +74,9 @@ $.extend(this, { values: {}, oldValue: null }, args); this.dependees = this.getDependees(); - for (const selector in this.dependees) { - if (this.dependees.hasOwnProperty(selector)) { - this.initializeDependee(selector, this.dependees[selector]); - } - } + Object.keys(this.dependees).forEach((selector) => { + this.initializeDependee(selector, this.dependees[selector]); + }); }; /** @@ -134,27 +132,25 @@ // Cache for the states of this dependee. this.values[selector] = {}; - 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) => { + 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 }, stateEventHandler); - // 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 }); + }); }, /** @@ -265,14 +261,15 @@ // bogus, we don't want to end up with an infinite loop. else if ($.isPlainObject(constraints)) { // This constraint is an object (AND). - 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; - } + const constraintsIds = Object.keys(constraints); + const length = constraintsIds.length; + for (let i = 0; i < length; i++) { + const n = constraintsIds[i]; + 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; } } } @@ -389,11 +386,9 @@ trigger.call(window, this.element); } else { - for (const event in trigger) { - if (trigger.hasOwnProperty(event)) { - this.defaultTrigger(event, trigger[event]); - } - } + Object.keys(trigger).forEach((event) => { + this.defaultTrigger(event, trigger[event]); + }); } // Mark this trigger as initialized for this element. diff --git a/core/misc/states.js b/core/misc/states.js index 61bbf46c61..113b8a8b06 100644 --- a/core/misc/states.js +++ b/core/misc/states.js @@ -14,19 +14,24 @@ attach: function attach(context, settings) { var $states = $(context).find('[data-drupal-states]'); var config = void 0; - var state = void 0; var il = $states.length; - for (var i = 0; i < il; i++) { + var createState = function createState(i, state, config) { + new states.Dependent({ + element: $($states[i]), + state: states.State.sanitize(state), + constraints: config[state] + }); + }; + + var _loop = function _loop(i) { config = JSON.parse($states[i].getAttribute('data-drupal-states')); - for (state in config) { - if (config.hasOwnProperty(state)) { - new states.Dependent({ - element: $($states[i]), - state: states.State.sanitize(state), - constraints: config[state] - }); - } - } + Object.keys(config).forEach(function (state) { + createState(i, state, config); + }); + }; + + for (var i = 0; i < il; i++) { + _loop(i); } while (states.postponed.length) { @@ -36,14 +41,14 @@ }; states.Dependent = function (args) { + var _this = this; + $.extend(this, { values: {}, oldValue: null }, args); this.dependees = this.getDependees(); - for (var selector in this.dependees) { - if (this.dependees.hasOwnProperty(selector)) { - this.initializeDependee(selector, this.dependees[selector]); - } - } + Object.keys(this.dependees).forEach(function (selector) { + _this.initializeDependee(selector, _this.dependees[selector]); + }); }; states.Dependent.comparisons = { @@ -60,6 +65,8 @@ states.Dependent.prototype = { initializeDependee: function initializeDependee(selector, dependeeStates) { + var _this2 = this; + var state = void 0; var self = this; @@ -69,23 +76,21 @@ this.values[selector] = {}; - for (var i in dependeeStates) { - if (dependeeStates.hasOwnProperty(i)) { - state = dependeeStates[i]; + Object.keys(dependeeStates).forEach(function (i) { + 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 }, stateEventHandler); - 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]; @@ -128,13 +133,14 @@ } } } 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; - } + var constraintsIds = Object.keys(constraints); + var length = constraintsIds.length; + for (var _i = 0; _i < length; _i++) { + var n = constraintsIds[_i]; + result = ternary(result, this.checkConstraints(constraints[n], selector, n)); + + if (result === false) { + return false; } } } @@ -185,16 +191,16 @@ states.Trigger.prototype = { initialize: function initialize() { + var _this3 = this; + var trigger = states.Trigger.states[this.state]; if (typeof trigger === 'function') { trigger.call(window, this.element); } else { - for (var event in trigger) { - if (trigger.hasOwnProperty(event)) { - this.defaultTrigger(event, trigger[event]); - } - } + Object.keys(trigger).forEach(function (event) { + _this3.defaultTrigger(event, trigger[event]); + }); } this.element.data('trigger:' + this.state, true); diff --git a/core/misc/tabledrag.es6.js b/core/misc/tabledrag.es6.js index ce621da43d..608d736e1d 100644 --- a/core/misc/tabledrag.es6.js +++ b/core/misc/tabledrag.es6.js @@ -41,11 +41,9 @@ } } - for (const base in settings.tableDrag) { - if (settings.tableDrag.hasOwnProperty(base)) { - initTableDrag($(context).find(`#${base}`).once('tabledrag'), base); - } - } + Object.keys(settings.tableDrag).forEach((base) => { + initTableDrag($(context).find(`#${base}`).once('tabledrag'), base); + }); }, }; @@ -172,20 +170,18 @@ * @type {bool} */ this.indentEnabled = false; - for (const group in tableSettings) { - if (tableSettings.hasOwnProperty(group)) { - for (const n in tableSettings[group]) { - if (tableSettings[group].hasOwnProperty(n)) { - if (tableSettings[group][n].relationship === 'parent') { - this.indentEnabled = true; - } - if (tableSettings[group][n].limit > 0) { - this.maxDepth = tableSettings[group][n].limit; - } + Object.keys(tableSettings).forEach((group) => { + for (const n in tableSettings[group]) { + if (tableSettings[group].hasOwnProperty(n)) { + if (tableSettings[group][n].relationship === 'parent') { + this.indentEnabled = true; + } + if (tableSettings[group][n].limit > 0) { + this.maxDepth = tableSettings[group][n].limit; } } } - } + }); if (this.indentEnabled) { /** * Total width of indents, set in makeDraggable. @@ -264,30 +260,28 @@ let hidden; let cell; let columnIndex; - for (const group in this.tableSettings) { - if (this.tableSettings.hasOwnProperty(group)) { - // Find the first field in this group. - 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).forEach((group) => { + // Find the first field in this group. + 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; } } + } - // Mark the column containing this field so it can be hidden. - if (hidden && cell[0]) { - // Add 1 to our indexes. The nth-child selector is 1 based, not 0 - // based. Match immediate children of the parent element to allow - // nesting. - columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1; - $table.find('> thead > tr, > tbody > tr, > tr').each(this.addColspanClass(columnIndex)); - } + // Mark the column containing this field so it can be hidden. + if (hidden && cell[0]) { + // Add 1 to our indexes. The nth-child selector is 1 based, not 0 + // based. Match immediate children of the parent element to allow + // nesting. + columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1; + $table.find('> thead > tr, > tbody > tr, > tr').each(this.addColspanClass(columnIndex)); } - } + }); this.displayColumns(showWeight); }; @@ -924,13 +918,11 @@ * DOM object for the row that was just dropped. */ Drupal.tableDrag.prototype.updateFields = function (changedRow) { - for (const group in this.tableSettings) { - if (this.tableSettings.hasOwnProperty(group)) { - // Each group may have a different setting for relationship, so we find - // the source rows for each separately. - this.updateField(changedRow, group); - } - } + Object.keys(this.tableSettings).forEach((group) => { + // Each group may have a different setting for relationship, so we find + // the source rows for each separately. + this.updateField(changedRow, group); + }); }; /** @@ -1484,15 +1476,13 @@ * Remove indentation helper classes from the current row group. */ Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () { - for (const n in this.children) { - if (this.children.hasOwnProperty(n)) { - $(this.children[n]).find('.js-indentation') - .removeClass('tree-child') - .removeClass('tree-child-first') - .removeClass('tree-child-last') - .removeClass('tree-child-horizontal'); - } - } + Object.keys(this.children).forEach((n) => { + $(this.children[n]).find('.js-indentation') + .removeClass('tree-child') + .removeClass('tree-child-first') + .removeClass('tree-child-last') + .removeClass('tree-child-horizontal'); + }); }; /** diff --git a/core/misc/tabledrag.js b/core/misc/tabledrag.js index e828bfe756..81acaeffcd 100644 --- a/core/misc/tabledrag.js +++ b/core/misc/tabledrag.js @@ -16,15 +16,15 @@ } } - for (var base in settings.tableDrag) { - if (settings.tableDrag.hasOwnProperty(base)) { - initTableDrag($(context).find('#' + base).once('tabledrag'), base); - } - } + Object.keys(settings.tableDrag).forEach(function (base) { + initTableDrag($(context).find('#' + base).once('tabledrag'), base); + }); } }; Drupal.tableDrag = function (table, tableSettings) { + var _this = this; + var self = this; var $table = $(table); @@ -59,20 +59,18 @@ this.windowHeight = 0; this.indentEnabled = false; - for (var group in tableSettings) { - if (tableSettings.hasOwnProperty(group)) { - for (var n in tableSettings[group]) { - if (tableSettings[group].hasOwnProperty(n)) { - if (tableSettings[group][n].relationship === 'parent') { - this.indentEnabled = true; - } - if (tableSettings[group][n].limit > 0) { - this.maxDepth = tableSettings[group][n].limit; - } + Object.keys(tableSettings).forEach(function (group) { + for (var n in tableSettings[group]) { + if (tableSettings[group].hasOwnProperty(n)) { + if (tableSettings[group][n].relationship === 'parent') { + _this.indentEnabled = true; + } + if (tableSettings[group][n].limit > 0) { + _this.maxDepth = tableSettings[group][n].limit; } } } - } + }); if (this.indentEnabled) { this.indentCount = 1; @@ -118,29 +116,29 @@ }; Drupal.tableDrag.prototype.initColumns = function () { + var _this2 = this; + var $table = this.$table; var hidden = void 0; var cell = void 0; var columnIndex = void 0; - for (var group in this.tableSettings) { - if (this.tableSettings.hasOwnProperty(group)) { - for (var d in this.tableSettings[group]) { - if (this.tableSettings[group].hasOwnProperty(d)) { - var 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).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; } } + } - if (hidden && cell[0]) { - columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1; - $table.find('> thead > tr, > tbody > tr, > tr').each(this.addColspanClass(columnIndex)); - } + if (hidden && cell[0]) { + columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1; + $table.find('> thead > tr, > tbody > tr, > tr').each(_this2.addColspanClass(columnIndex)); } - } + }); this.displayColumns(showWeight); }; @@ -577,11 +575,11 @@ }; Drupal.tableDrag.prototype.updateFields = function (changedRow) { - for (var group in this.tableSettings) { - if (this.tableSettings.hasOwnProperty(group)) { - this.updateField(changedRow, group); - } - } + var _this3 = this; + + Object.keys(this.tableSettings).forEach(function (group) { + _this3.updateField(changedRow, group); + }); }; Drupal.tableDrag.prototype.updateField = function (changedRow, group) { @@ -930,11 +928,11 @@ }; Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () { - for (var n in this.children) { - if (this.children.hasOwnProperty(n)) { - $(this.children[n]).find('.js-indentation').removeClass('tree-child').removeClass('tree-child-first').removeClass('tree-child-last').removeClass('tree-child-horizontal'); - } - } + var _this4 = 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'); + }); }; Drupal.tableDrag.prototype.row.prototype.markChanged = function () { diff --git a/core/modules/ckeditor/js/ckeditor.es6.js b/core/modules/ckeditor/js/ckeditor.es6.js index 21f6e4bb45..d34561f63e 100644 --- a/core/modules/ckeditor/js/ckeditor.es6.js +++ b/core/modules/ckeditor/js/ckeditor.es6.js @@ -182,11 +182,9 @@ const externalPlugins = format.editorSettings.drupalExternalPlugins; // Register and load additional CKEditor plugins as necessary. if (externalPlugins) { - for (const pluginName in externalPlugins) { - if (externalPlugins.hasOwnProperty(pluginName)) { - CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], ''); - } - } + Object.keys(externalPlugins).forEach((pluginName) => { + CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], ''); + }); delete format.editorSettings.drupalExternalPlugins; } }, diff --git a/core/modules/ckeditor/js/ckeditor.js b/core/modules/ckeditor/js/ckeditor.js index 17477e559e..df6ea11488 100644 --- a/core/modules/ckeditor/js/ckeditor.js +++ b/core/modules/ckeditor/js/ckeditor.js @@ -102,11 +102,9 @@ var externalPlugins = format.editorSettings.drupalExternalPlugins; if (externalPlugins) { - for (var pluginName in externalPlugins) { - if (externalPlugins.hasOwnProperty(pluginName)) { - CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], ''); - } - } + Object.keys(externalPlugins).forEach(function (pluginName) { + CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], ''); + }); delete format.editorSettings.drupalExternalPlugins; } } diff --git a/core/modules/ckeditor/js/plugins/drupallink/plugin.es6.js b/core/modules/ckeditor/js/plugins/drupallink/plugin.es6.js index 7444fcc243..6c5a347fea 100644 --- a/core/modules/ckeditor/js/plugins/drupallink/plugin.es6.js +++ b/core/modules/ckeditor/js/plugins/drupallink/plugin.es6.js @@ -34,11 +34,9 @@ function getAttributes(editor, data) { const set = {}; - for (const attributeName in data) { - if (data.hasOwnProperty(attributeName)) { - set[attributeName] = data[attributeName]; - } - } + Object.keys(data).forEach((attributeName) => { + set[attributeName] = data[attributeName]; + }); // CKEditor tracks the *actual* saved href in a data-cke-saved-* attribute // to work around browser quirks. We need to update it. @@ -46,11 +44,9 @@ // Remove all attributes which are not currently set. const removed = {}; - for (const s in set) { - if (set.hasOwnProperty(s)) { - delete removed[s]; - } - } + Object.keys(set).forEach((s) => { + delete removed[s]; + }); return { set, @@ -133,20 +129,18 @@ } // Update the link properties. else if (linkElement) { - for (const attrName in returnValues.attributes) { - if (returnValues.attributes.hasOwnProperty(attrName)) { - // Update the property if a value is specified. - if (returnValues.attributes[attrName].length > 0) { - const value = returnValues.attributes[attrName]; - linkElement.data(`cke-saved-${attrName}`, value); - linkElement.setAttribute(attrName, value); - } - // Delete the property if set to an empty string. - else { - linkElement.removeAttribute(attrName); - } + Object.keys(returnValues.attributes).forEach((attrName) => { + // Update the property if a value is specified. + if (returnValues.attributes[attrName].length > 0) { + const value = returnValues.attributes[attrName]; + linkElement.data(`cke-saved-${attrName}`, value); + linkElement.setAttribute(attrName, value); } - } + // Delete the property if set to an empty string. + else { + linkElement.removeAttribute(attrName); + } + }); } // Save snapshot for undo support. diff --git a/core/modules/ckeditor/js/plugins/drupallink/plugin.js b/core/modules/ckeditor/js/plugins/drupallink/plugin.js index 1f7f8c4668..81b662886e 100644 --- a/core/modules/ckeditor/js/plugins/drupallink/plugin.js +++ b/core/modules/ckeditor/js/plugins/drupallink/plugin.js @@ -32,20 +32,16 @@ function getAttributes(editor, data) { var set = {}; - for (var attributeName in data) { - if (data.hasOwnProperty(attributeName)) { - set[attributeName] = data[attributeName]; - } - } + Object.keys(data).forEach(function (attributeName) { + set[attributeName] = data[attributeName]; + }); set['data-cke-saved-href'] = set.href; var removed = {}; - for (var s in set) { - if (set.hasOwnProperty(s)) { - delete removed[s]; - } - } + Object.keys(set).forEach(function (s) { + delete removed[s]; + }); return { set: set, @@ -113,17 +109,15 @@ linkElement = getSelectedLink(editor); } else if (linkElement) { - for (var attrName in returnValues.attributes) { - if (returnValues.attributes.hasOwnProperty(attrName)) { - if (returnValues.attributes[attrName].length > 0) { - var value = returnValues.attributes[attrName]; - linkElement.data('cke-saved-' + attrName, value); - linkElement.setAttribute(attrName, value); - } else { - linkElement.removeAttribute(attrName); - } - } - } + Object.keys(returnValues.attributes).forEach(function (attrName) { + if (returnValues.attributes[attrName].length > 0) { + var value = returnValues.attributes[attrName]; + linkElement.data('cke-saved-' + attrName, value); + linkElement.setAttribute(attrName, value); + } else { + linkElement.removeAttribute(attrName); + } + }); } editor.fire('saveSnapshot'); diff --git a/core/modules/ckeditor/js/views/ControllerView.es6.js b/core/modules/ckeditor/js/views/ControllerView.es6.js index 869a004b96..2c1399253e 100644 --- a/core/modules/ckeditor/js/views/ControllerView.es6.js +++ b/core/modules/ckeditor/js/views/ControllerView.es6.js @@ -150,11 +150,9 @@ const hiddenEditorConfig = this.model.get('hiddenEditorConfig'); if (hiddenEditorConfig.drupalExternalPlugins) { const externalPlugins = hiddenEditorConfig.drupalExternalPlugins; - for (const pluginName in externalPlugins) { - if (externalPlugins.hasOwnProperty(pluginName)) { - CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], ''); - } - } + Object.keys(externalPlugins).forEach((pluginName) => { + CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], ''); + }); } CKEDITOR.inline($(`#${hiddenCKEditorID}`).get(0), CKEditorConfig); @@ -181,17 +179,15 @@ // @see getFeatureForButton() const features = {}; const buttonsToFeatures = {}; - for (const featureName in CKEFeatureRulesMap) { - if (CKEFeatureRulesMap.hasOwnProperty(featureName)) { - const feature = new Drupal.EditorFeature(featureName); - convertCKERulesToEditorFeature(feature, CKEFeatureRulesMap[featureName]); - features[featureName] = feature; - const command = e.editor.getCommand(featureName); - if (command) { - buttonsToFeatures[command.uiItems[0].name] = featureName; - } + Object.keys(CKEFeatureRulesMap).forEach((featureName) => { + const feature = new Drupal.EditorFeature(featureName); + convertCKERulesToEditorFeature(feature, CKEFeatureRulesMap[featureName]); + features[featureName] = feature; + const command = e.editor.getCommand(featureName); + if (command) { + buttonsToFeatures[command.uiItems[0].name] = featureName; } - } + }); callback(features, buttonsToFeatures); } @@ -326,25 +322,21 @@ // changed, rebuild the CKEditor features metadata. .on('CKEditorPluginSettingsChanged.ckeditorAdmin', (event, settingsChanges) => { // Update hidden CKEditor configuration. - for (const key in settingsChanges) { - if (settingsChanges.hasOwnProperty(key)) { - hiddenEditorConfig[key] = settingsChanges[key]; - } - } + Object.keys(settingsChanges).forEach((key) => { + hiddenEditorConfig[key] = settingsChanges[key]; + }); // Retrieve features for the updated hidden CKEditor configuration. getCKEditorFeatures(hiddenEditorConfig, (features) => { // Trigger a standardized text editor configuration event for each // feature that was modified by the configuration changes. const featuresMetadata = view.model.get('featuresMetadata'); - for (const name in features) { - if (features.hasOwnProperty(name)) { - const feature = features[name]; - if (featuresMetadata.hasOwnProperty(name) && !_.isEqual(featuresMetadata[name], feature)) { - Drupal.editorConfiguration.modifiedFeature(feature); - } + Object.keys(features).forEach((name) => { + const feature = features[name]; + if (featuresMetadata.hasOwnProperty(name) && !_.isEqual(featuresMetadata[name], feature)) { + Drupal.editorConfiguration.modifiedFeature(feature); } - } + }); // Update the CKEditor features metadata. view.model.set('featuresMetadata', features); }); diff --git a/core/modules/ckeditor/js/views/ControllerView.js b/core/modules/ckeditor/js/views/ControllerView.js index 4a19c29dfe..d86e3725e1 100644 --- a/core/modules/ckeditor/js/views/ControllerView.js +++ b/core/modules/ckeditor/js/views/ControllerView.js @@ -91,11 +91,9 @@ var hiddenEditorConfig = this.model.get('hiddenEditorConfig'); if (hiddenEditorConfig.drupalExternalPlugins) { var externalPlugins = hiddenEditorConfig.drupalExternalPlugins; - for (var pluginName in externalPlugins) { - if (externalPlugins.hasOwnProperty(pluginName)) { - CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], ''); - } - } + Object.keys(externalPlugins).forEach(function (pluginName) { + CKEDITOR.plugins.addExternal(pluginName, externalPlugins[pluginName], ''); + }); } CKEDITOR.inline($('#' + hiddenCKEditorID).get(0), CKEditorConfig); @@ -116,17 +114,15 @@ var features = {}; var buttonsToFeatures = {}; - for (var featureName in CKEFeatureRulesMap) { - if (CKEFeatureRulesMap.hasOwnProperty(featureName)) { - var feature = new Drupal.EditorFeature(featureName); - convertCKERulesToEditorFeature(feature, CKEFeatureRulesMap[featureName]); - features[featureName] = feature; - var command = e.editor.getCommand(featureName); - if (command) { - buttonsToFeatures[command.uiItems[0].name] = featureName; - } + Object.keys(CKEFeatureRulesMap).forEach(function (featureName) { + var feature = new Drupal.EditorFeature(featureName); + convertCKERulesToEditorFeature(feature, CKEFeatureRulesMap[featureName]); + features[featureName] = feature; + var command = e.editor.getCommand(featureName); + if (command) { + buttonsToFeatures[command.uiItems[0].name] = featureName; } - } + }); callback(features, buttonsToFeatures); } @@ -200,22 +196,18 @@ var configEvent = action === 'added' ? 'addedFeature' : 'removedFeature'; Drupal.editorConfiguration[configEvent](feature); }).on('CKEditorPluginSettingsChanged.ckeditorAdmin', function (event, settingsChanges) { - for (var key in settingsChanges) { - if (settingsChanges.hasOwnProperty(key)) { - hiddenEditorConfig[key] = settingsChanges[key]; - } - } + Object.keys(settingsChanges).forEach(function (key) { + hiddenEditorConfig[key] = settingsChanges[key]; + }); getCKEditorFeatures(hiddenEditorConfig, function (features) { var featuresMetadata = view.model.get('featuresMetadata'); - for (var name in features) { - if (features.hasOwnProperty(name)) { - var feature = features[name]; - if (featuresMetadata.hasOwnProperty(name) && !_.isEqual(featuresMetadata[name], feature)) { - Drupal.editorConfiguration.modifiedFeature(feature); - } + Object.keys(features).forEach(function (name) { + var feature = features[name]; + if (featuresMetadata.hasOwnProperty(name) && !_.isEqual(featuresMetadata[name], feature)) { + Drupal.editorConfiguration.modifiedFeature(feature); } - } + }); view.model.set('featuresMetadata', features); }); diff --git a/core/modules/color/color.es6.js b/core/modules/color/color.es6.js index 5a514e564c..c9c7871aca 100644 --- a/core/modules/color/color.es6.js +++ b/core/modules/color/color.es6.js @@ -33,34 +33,30 @@ // Decode reference colors to HSL. const reference = settings.color.reference; - for (i in reference) { - if (reference.hasOwnProperty(i)) { - reference[i] = farb.RGBToHSL(farb.unpack(reference[i])); - } - } + Object.keys(reference).forEach((i) => { + reference[i] = farb.RGBToHSL(farb.unpack(reference[i])); + }); // Build a preview. const height = []; const width = []; // Loop through all defined gradients. - for (i in settings.gradients) { - if (settings.gradients.hasOwnProperty(i)) { - // Add element to display the gradient. - $('.color-preview').once('color').append(`
`); - const gradient = $(`.color-preview #gradient-${i}`); - // Add height of current gradient to the list (divided by 10). - height.push(parseInt(gradient.css('height'), 10) / 10); - // Add width of current gradient to the list (divided by 10). - width.push(parseInt(gradient.css('width'), 10) / 10); - // Add rows (or columns for horizontal gradients). - // 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) { - gradient.append('
'); - } + Object.keys(settings.gradients).forEach((i) => { + // Add element to display the gradient. + $('.color-preview').once('color').append(`
`); + const gradient = $(`.color-preview #gradient-${i}`); + // Add height of current gradient to the list (divided by 10). + height.push(parseInt(gradient.css('height'), 10) / 10); + // Add width of current gradient to the list (divided by 10). + width.push(parseInt(gradient.css('width'), 10) / 10); + // Add rows (or columns for horizontal gradients). + // 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) { + gradient.append('
'); } - } + }); // Set up colorScheme selector. form.find('#edit-scheme').on('change', function () { @@ -69,11 +65,9 @@ if (colorScheme !== '' && schemes[colorScheme]) { // Get colors of active scheme. colors = schemes[colorScheme]; - for (const fieldName in colors) { - if (colors.hasOwnProperty(fieldName)) { - callback($(`#edit-palette-${fieldName}`), colors[fieldName], false, true); - } - } + Object.keys(colors).forEach((fieldName) => { + callback($(`#edit-palette-${fieldName}`), colors[fieldName], false, true); + }); preview(); } }); diff --git a/core/modules/color/color.js b/core/modules/color/color.js index 1b036c3aa1..23bf7b6eb4 100644 --- a/core/modules/color/color.js +++ b/core/modules/color/color.js @@ -25,40 +25,34 @@ var farb = $.farbtastic('.color-placeholder'); var reference = settings.color.reference; - for (i in reference) { - if (reference.hasOwnProperty(i)) { - reference[i] = farb.RGBToHSL(farb.unpack(reference[i])); - } - } + Object.keys(reference).forEach(function (i) { + reference[i] = farb.RGBToHSL(farb.unpack(reference[i])); + }); var height = []; var width = []; - for (i in settings.gradients) { - if (settings.gradients.hasOwnProperty(i)) { - $('.color-preview').once('color').append('
'); - var gradient = $('.color-preview #gradient-' + i); + Object.keys(settings.gradients).forEach(function (i) { + $('.color-preview').once('color').append('
'); + var gradient = $('.color-preview #gradient-' + i); - height.push(parseInt(gradient.css('height'), 10) / 10); + height.push(parseInt(gradient.css('height'), 10) / 10); - width.push(parseInt(gradient.css('width'), 10) / 10); + width.push(parseInt(gradient.css('width'), 10) / 10); - for (j = 0; j < (settings.gradients[i].direction === 'vertical' ? height[i] : width[i]); ++j) { - gradient.append('
'); - } + for (j = 0; j < (settings.gradients[i].direction === 'vertical' ? height[i] : width[i]); ++j) { + gradient.append('
'); } - } + }); form.find('#edit-scheme').on('change', function () { var schemes = settings.color.schemes; var colorScheme = this.options[this.selectedIndex].value; if (colorScheme !== '' && schemes[colorScheme]) { colors = schemes[colorScheme]; - for (var fieldName in colors) { - if (colors.hasOwnProperty(fieldName)) { - callback($('#edit-palette-' + fieldName), colors[fieldName], false, true); - } - } + Object.keys(colors).forEach(function (fieldName) { + callback($('#edit-palette-' + fieldName), colors[fieldName], false, true); + }); preview(); } }); diff --git a/core/modules/color/preview.es6.js b/core/modules/color/preview.es6.js index 357a62680b..f60717fcfe 100644 --- a/core/modules/color/preview.es6.js +++ b/core/modules/color/preview.es6.js @@ -38,34 +38,28 @@ form.find('#text a, #text h2').css('color', form.find('.color-palette input[name="palette[link]"]').val()); function gradientLineColor(i, element) { - for (const k in accum) { - if (accum.hasOwnProperty(k)) { - accum[k] += delta[k]; - } - } + Object.keys(accum).forEach((k) => { + accum[k] += delta[k]; + }); element.style.backgroundColor = farb.pack(accum); } // Set up gradients if there are some. let color_start; let color_end; - for (const i in settings.gradients) { - if (settings.gradients.hasOwnProperty(i)) { - color_start = farb.unpack(form.find(`.color-palette input[name="palette[${settings.gradients[i].colors[0]}]"]`).val()); - color_end = farb.unpack(form.find(`.color-palette input[name="palette[${settings.gradients[i].colors[1]}]"]`).val()); - if (color_start && color_end) { - delta = []; - for (const j in color_start) { - if (color_start.hasOwnProperty(j)) { - delta[j] = (color_end[j] - color_start[j]) / (settings.gradients[i].vertical ? height[i] : width[i]); - } - } - accum = color_start; - // Render gradient lines. - form.find(`#gradient-${i} > div`).each(gradientLineColor); - } + Object.keys(settings.gradients).forEach((gradientsKey) => { + color_start = farb.unpack(form.find(`.color-palette input[name="palette[${settings.gradients[gradientsKey].colors[0]}]"]`).val()); + color_end = farb.unpack(form.find(`.color-palette input[name="palette[${settings.gradients[gradientsKey].colors[1]}]"]`).val()); + if (color_start && color_end) { + delta = []; + Object.keys(color_start).forEach((colorStartKey) => { + delta[colorStartKey] = (color_end[colorStartKey] - color_start[colorStartKey]) / (settings.gradients[gradientsKey].vertical ? height[gradientsKey] : width[gradientsKey]); + }); + accum = color_start; + // Render gradient lines. + form.find(`#gradient-${gradientsKey} > div`).each(gradientLineColor); } - } + }); }, }; }(jQuery, Drupal)); diff --git a/core/modules/color/preview.js b/core/modules/color/preview.js index b4bcbcc896..253e52abe0 100644 --- a/core/modules/color/preview.js +++ b/core/modules/color/preview.js @@ -17,33 +17,27 @@ form.find('#text a, #text h2').css('color', form.find('.color-palette input[name="palette[link]"]').val()); function gradientLineColor(i, element) { - for (var k in accum) { - if (accum.hasOwnProperty(k)) { - accum[k] += delta[k]; - } - } + Object.keys(accum).forEach(function (k) { + accum[k] += delta[k]; + }); element.style.backgroundColor = farb.pack(accum); } var color_start = void 0; var color_end = void 0; - for (var i in settings.gradients) { - if (settings.gradients.hasOwnProperty(i)) { - color_start = farb.unpack(form.find('.color-palette input[name="palette[' + settings.gradients[i].colors[0] + ']"]').val()); - color_end = farb.unpack(form.find('.color-palette input[name="palette[' + settings.gradients[i].colors[1] + ']"]').val()); - if (color_start && color_end) { - delta = []; - for (var j in color_start) { - if (color_start.hasOwnProperty(j)) { - delta[j] = (color_end[j] - color_start[j]) / (settings.gradients[i].vertical ? height[i] : width[i]); - } - } - accum = color_start; + Object.keys(settings.gradients).forEach(function (gradientsKey) { + color_start = farb.unpack(form.find('.color-palette input[name="palette[' + settings.gradients[gradientsKey].colors[0] + ']"]').val()); + color_end = farb.unpack(form.find('.color-palette input[name="palette[' + settings.gradients[gradientsKey].colors[1] + ']"]').val()); + if (color_start && color_end) { + delta = []; + Object.keys(color_start).forEach(function (colorStartKey) { + delta[colorStartKey] = (color_end[colorStartKey] - color_start[colorStartKey]) / (settings.gradients[gradientsKey].vertical ? height[gradientsKey] : width[gradientsKey]); + }); + accum = color_start; - form.find('#gradient-' + i + ' > div').each(gradientLineColor); - } + form.find('#gradient-' + gradientsKey + ' > div').each(gradientLineColor); } - } + }); } }; })(jQuery, Drupal); \ No newline at end of file diff --git a/core/modules/comment/js/node-new-comments-link.es6.js b/core/modules/comment/js/node-new-comments-link.es6.js index e32c38cde0..ff986cd9a5 100644 --- a/core/modules/comment/js/node-new-comments-link.es6.js +++ b/core/modules/comment/js/node-new-comments-link.es6.js @@ -149,15 +149,15 @@ * Data about new comment links indexed by nodeID. */ function render(results) { - for (const nodeID in results) { - if (results.hasOwnProperty(nodeID) && $placeholdersToUpdate.hasOwnProperty(nodeID)) { + Object.keys(results).forEach((nodeID) => { + if ($placeholdersToUpdate.hasOwnProperty(nodeID)) { $placeholdersToUpdate[nodeID] .attr('href', results[nodeID].first_new_comment_link) .text(Drupal.formatPlural(results[nodeID].new_comment_count, '1 new comment', '@count new comments')) .removeClass('hidden'); show($placeholdersToUpdate[nodeID]); } - } + }); } if (drupalSettings.comment && drupalSettings.comment.newCommentsLinks) { diff --git a/core/modules/comment/js/node-new-comments-link.js b/core/modules/comment/js/node-new-comments-link.js index 37fdb58c5e..366e4e758b 100644 --- a/core/modules/comment/js/node-new-comments-link.js +++ b/core/modules/comment/js/node-new-comments-link.js @@ -70,12 +70,12 @@ } function render(results) { - for (var nodeID in results) { - if (results.hasOwnProperty(nodeID) && $placeholdersToUpdate.hasOwnProperty(nodeID)) { + Object.keys(results).forEach(function (nodeID) { + if ($placeholdersToUpdate.hasOwnProperty(nodeID)) { $placeholdersToUpdate[nodeID].attr('href', results[nodeID].first_new_comment_link).text(Drupal.formatPlural(results[nodeID].new_comment_count, '1 new comment', '@count new comments')).removeClass('hidden'); show($placeholdersToUpdate[nodeID]); } - } + }); } if (drupalSettings.comment && drupalSettings.comment.newCommentsLinks) { diff --git a/core/modules/content_translation/content_translation.admin.es6.js b/core/modules/content_translation/content_translation.admin.es6.js index 6736be69e5..94a59c34a0 100644 --- a/core/modules/content_translation/content_translation.admin.es6.js +++ b/core/modules/content_translation/content_translation.admin.es6.js @@ -29,15 +29,13 @@ // that name and copy over the input values that require all columns to be // translatable. if (options && options.dependent_selectors) { - for (const field in options.dependent_selectors) { - if (options.dependent_selectors.hasOwnProperty(field)) { - $fields = $context.find(`input[name^="${field}"]`); - dependent_columns = options.dependent_selectors[field]; + Object.keys(options.dependent_selectors).forEach((field) => { + $fields = $context.find(`input[name^="${field}"]`); + dependent_columns = options.dependent_selectors[field]; - $fields.on('change', fieldsChangeHandler($fields, dependent_columns)); - Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependent_columns); - } - } + $fields.on('change', fieldsChangeHandler($fields, dependent_columns)); + Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependent_columns); + }); } }, check($fields, dependent_columns, $changed) { @@ -50,23 +48,21 @@ // A field that has many different translatable parts can also define one // or more columns that require all columns to be translatable. - for (const index in dependent_columns) { - if (dependent_columns.hasOwnProperty(index)) { - column = dependent_columns[index]; + Object.keys(dependent_columns).forEach((index) => { + column = dependent_columns[index]; - if (!$changed) { - $element = $fields.filter(filterFieldsList); - } + if (!$changed) { + $element = $fields.filter(filterFieldsList); + } - if ($element.is(`input[value="${column}"]:checked`)) { - $fields.prop('checked', true) - .not($element).prop('disabled', true); - } - else { - $fields.prop('disabled', false); - } + if ($element.is(`input[value="${column}"]:checked`)) { + $fields.prop('checked', true) + .not($element).prop('disabled', true); } - } + else { + $fields.prop('disabled', false); + } + }); }, }; diff --git a/core/modules/content_translation/content_translation.admin.js b/core/modules/content_translation/content_translation.admin.js index 2d524870e9..e3ba01b5ba 100644 --- a/core/modules/content_translation/content_translation.admin.js +++ b/core/modules/content_translation/content_translation.admin.js @@ -20,15 +20,13 @@ } if (options && options.dependent_selectors) { - for (var field in options.dependent_selectors) { - if (options.dependent_selectors.hasOwnProperty(field)) { - $fields = $context.find('input[name^="' + field + '"]'); - dependent_columns = options.dependent_selectors[field]; + Object.keys(options.dependent_selectors).forEach(function (field) { + $fields = $context.find('input[name^="' + field + '"]'); + dependent_columns = options.dependent_selectors[field]; - $fields.on('change', fieldsChangeHandler($fields, dependent_columns)); - Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependent_columns); - } - } + $fields.on('change', fieldsChangeHandler($fields, dependent_columns)); + Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependent_columns); + }); } }, check: function check($fields, dependent_columns, $changed) { @@ -39,21 +37,19 @@ return $(field).val() === column; } - for (var index in dependent_columns) { - if (dependent_columns.hasOwnProperty(index)) { - column = dependent_columns[index]; + Object.keys(dependent_columns).forEach(function (index) { + column = dependent_columns[index]; - if (!$changed) { - $element = $fields.filter(filterFieldsList); - } + if (!$changed) { + $element = $fields.filter(filterFieldsList); + } - if ($element.is('input[value="' + column + '"]:checked')) { - $fields.prop('checked', true).not($element).prop('disabled', true); - } else { - $fields.prop('disabled', false); - } + if ($element.is('input[value="' + column + '"]:checked')) { + $fields.prop('checked', true).not($element).prop('disabled', true); + } else { + $fields.prop('disabled', false); } - } + }); } }; diff --git a/core/modules/editor/js/editor.admin.es6.js b/core/modules/editor/js/editor.admin.es6.js index b02fe8bc44..9eaff8164b 100644 --- a/core/modules/editor/js/editor.admin.es6.js +++ b/core/modules/editor/js/editor.admin.es6.js @@ -567,13 +567,12 @@ // If any filter's current status forbids the editor feature, return // false. Drupal.filterConfiguration.update(); - 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; - } - } + const disallowedFeature = Object.keys(Drupal.filterConfiguration.statuses).some((filterID) => { + const filterStatus = Drupal.filterConfiguration.statuses[filterID]; + return !filterStatusAllowsFeature(filterStatus, feature); + }); + if (disallowedFeature) { + return false; } return true; @@ -879,17 +878,15 @@ * up-to-date. */ update() { - for (const filterID in Drupal.filterConfiguration.statuses) { - if (Drupal.filterConfiguration.statuses.hasOwnProperty(filterID)) { - // Update status. - Drupal.filterConfiguration.statuses[filterID].active = $(`[name="filters[${filterID}][status]"]`).is(':checked'); - - // Update current rules. - if (Drupal.filterConfiguration.liveSettingParsers[filterID]) { - Drupal.filterConfiguration.statuses[filterID].rules = Drupal.filterConfiguration.liveSettingParsers[filterID].getRules(); - } + Object.keys(Drupal.filterConfiguration.statuses).forEach((filterID) => { + // Update status. + Drupal.filterConfiguration.statuses[filterID].active = $(`[name="filters[${filterID}][status]"]`).is(':checked'); + + // Update current rules. + if (Drupal.filterConfiguration.liveSettingParsers[filterID]) { + Drupal.filterConfiguration.statuses[filterID].rules = Drupal.filterConfiguration.liveSettingParsers[filterID].getRules(); } - } + }); }, }; diff --git a/core/modules/editor/js/editor.admin.js b/core/modules/editor/js/editor.admin.js index 377aef2324..cdb51cede9 100644 --- a/core/modules/editor/js/editor.admin.js +++ b/core/modules/editor/js/editor.admin.js @@ -256,13 +256,12 @@ } 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; - } - } + var disallowedFeature = Object.keys(Drupal.filterConfiguration.statuses).some(function (filterID) { + var filterStatus = Drupal.filterConfiguration.statuses[filterID]; + return !filterStatusAllowsFeature(filterStatus, feature); + }); + if (disallowedFeature) { + return false; } return true; @@ -331,15 +330,13 @@ liveSettingParsers: {}, update: function update() { - for (var filterID in Drupal.filterConfiguration.statuses) { - if (Drupal.filterConfiguration.statuses.hasOwnProperty(filterID)) { - Drupal.filterConfiguration.statuses[filterID].active = $('[name="filters[' + filterID + '][status]"]').is(':checked'); + Object.keys(Drupal.filterConfiguration.statuses).forEach(function (filterID) { + Drupal.filterConfiguration.statuses[filterID].active = $('[name="filters[' + filterID + '][status]"]').is(':checked'); - if (Drupal.filterConfiguration.liveSettingParsers[filterID]) { - Drupal.filterConfiguration.statuses[filterID].rules = Drupal.filterConfiguration.liveSettingParsers[filterID].getRules(); - } + if (Drupal.filterConfiguration.liveSettingParsers[filterID]) { + Drupal.filterConfiguration.statuses[filterID].rules = Drupal.filterConfiguration.liveSettingParsers[filterID].getRules(); } - } + }); } }; diff --git a/core/modules/field_ui/field_ui.es6.js b/core/modules/field_ui/field_ui.es6.js index e8f9f9aba5..3fa297e3b0 100644 --- a/core/modules/field_ui/field_ui.es6.js +++ b/core/modules/field_ui/field_ui.es6.js @@ -213,12 +213,10 @@ const rowNames = []; const ajaxElements = []; let rowName; - for (rowName in rows) { - if (rows.hasOwnProperty(rowName)) { - rowNames.push(rowName); - ajaxElements.push(rows[rowName]); - } - } + Object.keys(rows).forEach((rowName) => { + rowNames.push(rowName); + ajaxElements.push(rows[rowName]); + }); if (rowNames.length) { // Add a throbber next each of the ajaxElements. diff --git a/core/modules/field_ui/field_ui.js b/core/modules/field_ui/field_ui.js index f8bf3e5606..88d2672f45 100644 --- a/core/modules/field_ui/field_ui.js +++ b/core/modules/field_ui/field_ui.js @@ -121,12 +121,10 @@ var rowNames = []; var ajaxElements = []; var rowName = void 0; - for (rowName in rows) { - if (rows.hasOwnProperty(rowName)) { - rowNames.push(rowName); - ajaxElements.push(rows[rowName]); - } - } + Object.keys(rows).forEach(function (rowName) { + rowNames.push(rowName); + ajaxElements.push(rows[rowName]); + }); if (rowNames.length) { $(ajaxElements).after('
 
'); diff --git a/core/modules/filter/filter.filter_html.admin.es6.js b/core/modules/filter/filter.filter_html.admin.es6.js index c5809c09e8..277b373fd4 100644 --- a/core/modules/filter/filter.filter_html.admin.es6.js +++ b/core/modules/filter/filter.filter_html.admin.es6.js @@ -143,38 +143,36 @@ const editorRequiredTags = {}; // Map the newly added Text Editor features to Drupal.FilterHtmlRule // objects (to allow comparing userTags with autoTags). - for (featureName in newFeatures) { - if (newFeatures.hasOwnProperty(featureName)) { - feature = newFeatures[featureName]; - for (let f = 0; f < feature.length; f++) { - featureRule = feature[f]; - for (let t = 0; t < featureRule.required.tags.length; t++) { - tag = featureRule.required.tags[t]; - if (!_.has(editorRequiredTags, tag)) { - filterRule = new Drupal.FilterHTMLRule(); - filterRule.restrictedTags.tags = [tag]; - // @todo Neither Drupal.FilterHtmlRule nor - // Drupal.EditorFeatureHTMLRule allow for generic attribute - // value restrictions, only for the "class" and "style" - // attribute's values to be restricted. The filter_html filter - // always disallows the "style" attribute, so we only need to - // support "class" attribute value restrictions. Fix once - // https://www.drupal.org/node/2567801 lands. - filterRule.restrictedTags.allowed.attributes = featureRule.required.attributes.slice(0); - filterRule.restrictedTags.allowed.classes = featureRule.required.classes.slice(0); - editorRequiredTags[tag] = filterRule; - } - // The tag is already allowed, add any additionally allowed - // attributes. - else { - filterRule = editorRequiredTags[tag]; - filterRule.restrictedTags.allowed.attributes = _.union(filterRule.restrictedTags.allowed.attributes, featureRule.required.attributes); - filterRule.restrictedTags.allowed.classes = _.union(filterRule.restrictedTags.allowed.classes, featureRule.required.classes); - } + Object.keys(newFeatures).forEach((featureName) => { + feature = newFeatures[featureName]; + for (let f = 0; f < feature.length; f++) { + featureRule = feature[f]; + for (let t = 0; t < featureRule.required.tags.length; t++) { + tag = featureRule.required.tags[t]; + if (!_.has(editorRequiredTags, tag)) { + filterRule = new Drupal.FilterHTMLRule(); + filterRule.restrictedTags.tags = [tag]; + // @todo Neither Drupal.FilterHtmlRule nor + // Drupal.EditorFeatureHTMLRule allow for generic attribute + // value restrictions, only for the "class" and "style" + // attribute's values to be restricted. The filter_html filter + // always disallows the "style" attribute, so we only need to + // support "class" attribute value restrictions. Fix once + // https://www.drupal.org/node/2567801 lands. + filterRule.restrictedTags.allowed.attributes = featureRule.required.attributes.slice(0); + filterRule.restrictedTags.allowed.classes = featureRule.required.classes.slice(0); + editorRequiredTags[tag] = filterRule; + } + // The tag is already allowed, add any additionally allowed + // attributes. + else { + filterRule = editorRequiredTags[tag]; + filterRule.restrictedTags.allowed.attributes = _.union(filterRule.restrictedTags.allowed.attributes, featureRule.required.attributes); + filterRule.restrictedTags.allowed.classes = _.union(filterRule.restrictedTags.allowed.classes, featureRule.required.classes); } } } - } + }); // Now compare userAllowedTags with editorRequiredTags, and build // autoAllowedTags, which contains: @@ -183,7 +181,7 @@ // - any tags in editorRequiredTags that already exists in userAllowedTags // but does not allow all attributes or attribute values const autoAllowedTags = {}; - for (tag in editorRequiredTags) { + Object.keys(editorRequiredTags).forEach((tag) => { // If userAllowedTags does not contain a rule for this editor-required // tag, then add it to the list of automatically allowed tags. if (!_.has(userAllowedTags, tag)) { @@ -209,7 +207,7 @@ autoAllowedTags[tag].restrictedTags.allowed.classes = _.union(allowedClasses, requiredClasses); } } - } + }); return autoAllowedTags; }, diff --git a/core/modules/filter/filter.filter_html.admin.js b/core/modules/filter/filter.filter_html.admin.js index 773f35a9d8..ca3347d0cf 100644 --- a/core/modules/filter/filter.filter_html.admin.js +++ b/core/modules/filter/filter.filter_html.admin.js @@ -81,32 +81,30 @@ var tag = void 0; var editorRequiredTags = {}; - for (featureName in newFeatures) { - if (newFeatures.hasOwnProperty(featureName)) { - feature = newFeatures[featureName]; - for (var f = 0; f < feature.length; f++) { - featureRule = feature[f]; - for (var t = 0; t < featureRule.required.tags.length; t++) { - tag = featureRule.required.tags[t]; - if (!_.has(editorRequiredTags, tag)) { - filterRule = new Drupal.FilterHTMLRule(); - filterRule.restrictedTags.tags = [tag]; - - filterRule.restrictedTags.allowed.attributes = featureRule.required.attributes.slice(0); - filterRule.restrictedTags.allowed.classes = featureRule.required.classes.slice(0); - editorRequiredTags[tag] = filterRule; - } else { - filterRule = editorRequiredTags[tag]; - filterRule.restrictedTags.allowed.attributes = _.union(filterRule.restrictedTags.allowed.attributes, featureRule.required.attributes); - filterRule.restrictedTags.allowed.classes = _.union(filterRule.restrictedTags.allowed.classes, featureRule.required.classes); - } - } + Object.keys(newFeatures).forEach(function (featureName) { + feature = newFeatures[featureName]; + for (var f = 0; f < feature.length; f++) { + featureRule = feature[f]; + for (var t = 0; t < featureRule.required.tags.length; t++) { + tag = featureRule.required.tags[t]; + if (!_.has(editorRequiredTags, tag)) { + filterRule = new Drupal.FilterHTMLRule(); + filterRule.restrictedTags.tags = [tag]; + + filterRule.restrictedTags.allowed.attributes = featureRule.required.attributes.slice(0); + filterRule.restrictedTags.allowed.classes = featureRule.required.classes.slice(0); + editorRequiredTags[tag] = filterRule; + } else { + filterRule = editorRequiredTags[tag]; + filterRule.restrictedTags.allowed.attributes = _.union(filterRule.restrictedTags.allowed.attributes, featureRule.required.attributes); + filterRule.restrictedTags.allowed.classes = _.union(filterRule.restrictedTags.allowed.classes, featureRule.required.classes); + } } } - } + }); var autoAllowedTags = {}; - for (tag in editorRequiredTags) { + Object.keys(editorRequiredTags).forEach(function (tag) { if (!_.has(userAllowedTags, tag)) { autoAllowedTags[tag] = editorRequiredTags[tag]; } else { @@ -126,7 +124,7 @@ autoAllowedTags[tag].restrictedTags.allowed.classes = _.union(allowedClasses, requiredClasses); } } - } + }); return autoAllowedTags; }, diff --git a/core/modules/history/js/history.es6.js b/core/modules/history/js/history.es6.js index c34a4adcee..456f64b984 100644 --- a/core/modules/history/js/history.es6.js +++ b/core/modules/history/js/history.es6.js @@ -45,11 +45,9 @@ data: { 'node_ids[]': nodeIDs }, dataType: 'json', success(results) { - for (const nodeID in results) { - if (results.hasOwnProperty(nodeID)) { - storage.setItem(`Drupal.history.${currentUserID}.${nodeID}`, results[nodeID]); - } - } + Object.keys(results).forEach((nodeID) => { + storage.setItem(`Drupal.history.${currentUserID}.${nodeID}`, results[nodeID]); + }); callback(); }, }); diff --git a/core/modules/history/js/history.js b/core/modules/history/js/history.js index 6dbd15cb99..4bed86d3e2 100644 --- a/core/modules/history/js/history.js +++ b/core/modules/history/js/history.js @@ -29,11 +29,9 @@ data: { 'node_ids[]': nodeIDs }, dataType: 'json', success: function success(results) { - for (var nodeID in results) { - if (results.hasOwnProperty(nodeID)) { - storage.setItem('Drupal.history.' + currentUserID + '.' + nodeID, results[nodeID]); - } - } + Object.keys(results).forEach(function (nodeID) { + storage.setItem('Drupal.history.' + currentUserID + '.' + nodeID, results[nodeID]); + }); callback(); } }); diff --git a/core/modules/menu_ui/menu_ui.admin.es6.js b/core/modules/menu_ui/menu_ui.admin.es6.js index fabcec048d..3ae28f4613 100644 --- a/core/modules/menu_ui/menu_ui.admin.es6.js +++ b/core/modules/menu_ui/menu_ui.admin.es6.js @@ -47,14 +47,12 @@ $select.children().remove(); // Add new options to dropdown. Keep a count of options for testing later. let totalOptions = 0; - for (const machineName in options) { - if (options.hasOwnProperty(machineName)) { - $select.append( - $(``).val(machineName).text(options[machineName]), - ); - totalOptions++; - } - } + Object.keys(options).forEach((machineName) => { + $select.append( + $(``).val(machineName).text(options[machineName]), + ); + totalOptions++; + }); // Hide the parent options if there are no options for it. $select.closest('div').toggle(totalOptions > 0).attr('hidden', totalOptions === 0); diff --git a/core/modules/menu_ui/menu_ui.admin.js b/core/modules/menu_ui/menu_ui.admin.js index 324b567a07..f59a457d26 100644 --- a/core/modules/menu_ui/menu_ui.admin.js +++ b/core/modules/menu_ui/menu_ui.admin.js @@ -38,12 +38,10 @@ $select.children().remove(); var totalOptions = 0; - for (var machineName in options) { - if (options.hasOwnProperty(machineName)) { - $select.append($('').val(machineName).text(options[machineName])); - totalOptions++; - } - } + Object.keys(options).forEach(function (machineName) { + $select.append($('').val(machineName).text(options[machineName])); + totalOptions++; + }); $select.closest('div').toggle(totalOptions > 0).attr('hidden', totalOptions === 0); } diff --git a/core/modules/quickedit/js/theme.es6.js b/core/modules/quickedit/js/theme.es6.js index b2fa17c901..b9355b13aa 100644 --- a/core/modules/quickedit/js/theme.es6.js +++ b/core/modules/quickedit/js/theme.es6.js @@ -144,11 +144,9 @@ // Attributes. const attributes = []; const attrMap = settings.buttons[i].attributes || {}; - for (const attr in attrMap) { - if (attrMap.hasOwnProperty(attr)) { - attributes.push(attr + ((attrMap[attr]) ? `="${attrMap[attr]}"` : '')); - } - } + Object.keys(attrMap).forEach((attr) => { + attributes.push(attr + ((attrMap[attr]) ? `="${attrMap[attr]}"` : '')); + }); html += ``; } return html; diff --git a/core/modules/quickedit/js/theme.js b/core/modules/quickedit/js/theme.js index c1d1cfadfd..8b12cd7651 100644 --- a/core/modules/quickedit/js/theme.js +++ b/core/modules/quickedit/js/theme.js @@ -53,7 +53,8 @@ Drupal.theme.quickeditButtons = function (settings) { var html = ''; - for (var i = 0; i < settings.buttons.length; i++) { + + var _loop = function _loop(i) { var button = settings.buttons[i]; if (!button.hasOwnProperty('type')) { button.type = 'button'; @@ -61,12 +62,14 @@ var attributes = []; var attrMap = settings.buttons[i].attributes || {}; - for (var attr in attrMap) { - if (attrMap.hasOwnProperty(attr)) { - attributes.push(attr + (attrMap[attr] ? '="' + attrMap[attr] + '"' : '')); - } - } + Object.keys(attrMap).forEach(function (attr) { + attributes.push(attr + (attrMap[attr] ? '="' + attrMap[attr] + '"' : '')); + }); html += ''; + }; + + for (var i = 0; i < settings.buttons.length; i++) { + _loop(i); } return html; }; diff --git a/core/modules/quickedit/js/util.es6.js b/core/modules/quickedit/js/util.es6.js index f8873e2e35..036592485f 100644 --- a/core/modules/quickedit/js/util.es6.js +++ b/core/modules/quickedit/js/util.es6.js @@ -181,11 +181,11 @@ * The HTTP status code. */ success(response, status) { - for (const i in response) { - if (response.hasOwnProperty(i) && response[i].command && this.commands[response[i].command]) { + Object.keys(response).forEach((i) => { + if (response[i].command && this.commands[response[i].command]) { this.commands[response[i].command](this, response[i], status); } - } + }); }, base: $submit.attr('id'), element: $submit[0], diff --git a/core/modules/quickedit/js/util.js b/core/modules/quickedit/js/util.js index 16b524a9f3..986b9be1d5 100644 --- a/core/modules/quickedit/js/util.js +++ b/core/modules/quickedit/js/util.js @@ -85,11 +85,13 @@ }, success: function success(response, status) { - for (var i in response) { - if (response.hasOwnProperty(i) && response[i].command && this.commands[response[i].command]) { - this.commands[response[i].command](this, response[i], status); + var _this = this; + + Object.keys(response).forEach(function (i) { + if (response[i].command && _this.commands[response[i].command]) { + _this.commands[response[i].command](_this, response[i], status); } - } + }); }, base: $submit.attr('id'), diff --git a/core/modules/system/js/system.es6.js b/core/modules/system/js/system.es6.js index 18153b09ec..61a8b02aee 100644 --- a/core/modules/system/js/system.es6.js +++ b/core/modules/system/js/system.es6.js @@ -23,11 +23,7 @@ attach(context) { // List of fields IDs on which to bind the event listener. // Create an array of IDs to use with jQuery. - for (const sourceId in drupalSettings.copyFieldValue) { - if (drupalSettings.copyFieldValue.hasOwnProperty(sourceId)) { - ids.push(sourceId); - } - } + Object.keys(drupalSettings.copyFieldValue).forEach(ids.push); if (ids.length) { // Listen to value:copy events on all dependent fields. // We have to use body and not document because of the way jQuery events diff --git a/core/modules/system/js/system.js b/core/modules/system/js/system.js index d62cc07446..dc66b5c18a 100644 --- a/core/modules/system/js/system.js +++ b/core/modules/system/js/system.js @@ -10,11 +10,7 @@ Drupal.behaviors.copyFieldValue = { attach: function attach(context) { - for (var sourceId in drupalSettings.copyFieldValue) { - if (drupalSettings.copyFieldValue.hasOwnProperty(sourceId)) { - ids.push(sourceId); - } - } + Object.keys(drupalSettings.copyFieldValue).forEach(ids.push); if (ids.length) { $('body').once('copy-field-values').on('value:copy', this.valueTargetCopyHandler); diff --git a/core/modules/toolbar/js/toolbar.es6.js b/core/modules/toolbar/js/toolbar.es6.js index 4fdf090fbe..8fb4794071 100644 --- a/core/modules/toolbar/js/toolbar.es6.js +++ b/core/modules/toolbar/js/toolbar.es6.js @@ -54,18 +54,16 @@ // Attach a listener to the configured media query breakpoints. // Executes it before Drupal.toolbar.views to avoid extra rendering. - for (const label in options.breakpoints) { - if (options.breakpoints.hasOwnProperty(label)) { - const mq = options.breakpoints[label]; - const mql = Drupal.toolbar.mql[label] = window.matchMedia(mq); - // Curry the model and the label of the media query breakpoint to - // the mediaQueryChangeHandler function. - mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label)); - // Fire the mediaQueryChangeHandler for each configured breakpoint - // so that they process once. - Drupal.toolbar.mediaQueryChangeHandler.call(null, model, label, mql); - } - } + Object.keys(options.breakpoints).forEach((label) => { + const mq = options.breakpoints[label]; + const mql = Drupal.toolbar.mql[label] = window.matchMedia(mq); + // Curry the model and the label of the media query breakpoint to + // the mediaQueryChangeHandler function. + mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label)); + // Fire the mediaQueryChangeHandler for each configured breakpoint + // so that they process once. + Drupal.toolbar.mediaQueryChangeHandler.call(null, model, label, mql); + }); Drupal.toolbar.views.toolbarVisualView = new Drupal.toolbar.ToolbarVisualView({ el: this, diff --git a/core/modules/toolbar/js/toolbar.js b/core/modules/toolbar/js/toolbar.js index 4f4ff5943f..1bfb3b90ca 100644 --- a/core/modules/toolbar/js/toolbar.js +++ b/core/modules/toolbar/js/toolbar.js @@ -32,16 +32,14 @@ height: $('#toolbar-administration').outerHeight() }); - for (var label in options.breakpoints) { - if (options.breakpoints.hasOwnProperty(label)) { - var mq = options.breakpoints[label]; - var mql = Drupal.toolbar.mql[label] = window.matchMedia(mq); + Object.keys(options.breakpoints).forEach(function (label) { + var mq = options.breakpoints[label]; + var mql = Drupal.toolbar.mql[label] = window.matchMedia(mq); - mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label)); + mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label)); - Drupal.toolbar.mediaQueryChangeHandler.call(null, model, label, mql); - } - } + Drupal.toolbar.mediaQueryChangeHandler.call(null, model, label, mql); + }); Drupal.toolbar.views.toolbarVisualView = new Drupal.toolbar.ToolbarVisualView({ el: this, diff --git a/core/modules/toolbar/js/views/MenuVisualView.es6.js b/core/modules/toolbar/js/views/MenuVisualView.es6.js index e956112aaf..2095c8bfaa 100644 --- a/core/modules/toolbar/js/views/MenuVisualView.es6.js +++ b/core/modules/toolbar/js/views/MenuVisualView.es6.js @@ -23,14 +23,12 @@ render() { const subtrees = this.model.get('subtrees'); // Add subtrees. - for (const id in subtrees) { - if (subtrees.hasOwnProperty(id)) { - this.$el - .find(`#toolbar-link-${id}`) - .once('toolbar-subtrees') - .after(subtrees[id]); - } - } + Object.keys(subtrees).forEach((id) => { + this.$el + .find(`#toolbar-link-${id}`) + .once('toolbar-subtrees') + .after(subtrees[id]); + }); // Render the main menu as a nested, collapsible accordion. if ('drupalToolbarMenu' in $.fn) { this.$el diff --git a/core/modules/toolbar/js/views/MenuVisualView.js b/core/modules/toolbar/js/views/MenuVisualView.js index a9cd1a30f6..0e067afdac 100644 --- a/core/modules/toolbar/js/views/MenuVisualView.js +++ b/core/modules/toolbar/js/views/MenuVisualView.js @@ -11,13 +11,13 @@ this.listenTo(this.model, 'change:subtrees', this.render); }, render: function render() { + var _this = this; + var subtrees = this.model.get('subtrees'); - for (var id in subtrees) { - if (subtrees.hasOwnProperty(id)) { - this.$el.find('#toolbar-link-' + id).once('toolbar-subtrees').after(subtrees[id]); - } - } + Object.keys(subtrees).forEach(function (id) { + _this.$el.find('#toolbar-link-' + id).once('toolbar-subtrees').after(subtrees[id]); + }); if ('drupalToolbarMenu' in $.fn) { this.$el.children('.toolbar-menu').drupalToolbarMenu(); diff --git a/core/modules/tracker/js/tracker-history.es6.js b/core/modules/tracker/js/tracker-history.es6.js index 5df3494a9c..49cb08e737 100644 --- a/core/modules/tracker/js/tracker-history.es6.js +++ b/core/modules/tracker/js/tracker-history.es6.js @@ -103,13 +103,13 @@ data: { 'node_ids[]': nodeIDs }, dataType: 'json', success(results) { - for (const nodeID in results) { - if (results.hasOwnProperty(nodeID) && placeholdersToUpdate.hasOwnProperty(nodeID)) { + Object.keys(results).forEach((nodeID) => { + if (placeholdersToUpdate.hasOwnProperty(nodeID)) { const url = results[nodeID].first_new_comment_link; const text = Drupal.formatPlural(results[nodeID].new_comment_count, '1 new', '@count new'); $(placeholdersToUpdate[nodeID]).append(`
${text}`); } - } + }); }, }); } diff --git a/core/modules/tracker/js/tracker-history.js b/core/modules/tracker/js/tracker-history.js index c60f50d9be..be5e7e73fd 100644 --- a/core/modules/tracker/js/tracker-history.js +++ b/core/modules/tracker/js/tracker-history.js @@ -87,13 +87,13 @@ data: { 'node_ids[]': nodeIDs }, dataType: 'json', success: function success(results) { - for (var nodeID in results) { - if (results.hasOwnProperty(nodeID) && placeholdersToUpdate.hasOwnProperty(nodeID)) { + Object.keys(results).forEach(function (nodeID) { + if (placeholdersToUpdate.hasOwnProperty(nodeID)) { var url = results[nodeID].first_new_comment_link; var text = Drupal.formatPlural(results[nodeID].new_comment_count, '1 new', '@count new'); $(placeholdersToUpdate[nodeID]).append('
' + text + ''); } - } + }); } }); } diff --git a/core/modules/views/js/ajax_view.es6.js b/core/modules/views/js/ajax_view.es6.js index df2c4da639..d5ba47b690 100644 --- a/core/modules/views/js/ajax_view.es6.js +++ b/core/modules/views/js/ajax_view.es6.js @@ -16,11 +16,9 @@ Drupal.behaviors.ViewsAjaxView.attach = function () { if (drupalSettings && drupalSettings.views && drupalSettings.views.ajaxViews) { const ajaxViews = drupalSettings.views.ajaxViews; - for (const i in ajaxViews) { - if (ajaxViews.hasOwnProperty(i)) { - Drupal.views.instances[i] = new Drupal.views.ajaxView(ajaxViews[i]); - } - } + Object.keys(ajaxViews).forEach((i) => { + Drupal.views.instances[i] = new Drupal.views.ajaxView(ajaxViews[i]); + }); } }; diff --git a/core/modules/views/js/ajax_view.js b/core/modules/views/js/ajax_view.js index 67601a121f..979d5bbb84 100644 --- a/core/modules/views/js/ajax_view.js +++ b/core/modules/views/js/ajax_view.js @@ -10,11 +10,9 @@ Drupal.behaviors.ViewsAjaxView.attach = function () { if (drupalSettings && drupalSettings.views && drupalSettings.views.ajaxViews) { var ajaxViews = drupalSettings.views.ajaxViews; - for (var i in ajaxViews) { - if (ajaxViews.hasOwnProperty(i)) { - Drupal.views.instances[i] = new Drupal.views.ajaxView(ajaxViews[i]); - } - } + Object.keys(ajaxViews).forEach(function (i) { + Drupal.views.instances[i] = new Drupal.views.ajaxView(ajaxViews[i]); + }); } };