diff --git a/core/.eslintrc.passing.json b/core/.eslintrc.passing.json index 7ed6508feb..3f42d326c6 100644 --- a/core/.eslintrc.passing.json +++ b/core/.eslintrc.passing.json @@ -3,7 +3,6 @@ "rules": { "no-use-before-define": "off", "no-shadow": "off", - "no-restricted-syntax": "off", "no-new": "off", "no-continue": "off", "new-cap": "off", diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js index fa4e3a55f0..c3633b4636 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(base => loadAjaxBehavior(base)); Drupal.ajax.bindAjaxLinks(document.body); @@ -877,14 +873,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 8ec175fee1..58759ac7a0 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -21,11 +21,9 @@ 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(function (base) { + return loadAjaxBehavior(base); + }); Drupal.ajax.bindAjaxLinks(document.body); @@ -397,6 +395,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(); } @@ -408,14 +408,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..48f0510346 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); }; @@ -316,12 +314,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); - } - } + keys = Object.keys(args || {}); // 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..e080caae65 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); }; @@ -82,12 +80,7 @@ window.Drupal = { behaviors: {}, locale: {} }; } if (!Array.isArray(keys)) { - keys = []; - for (var k in args) { - if (args.hasOwnProperty(k)) { - keys.push(k); - } - } + keys = Object.keys(args || {}); 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 ec7a4e7e3a..b47b90de57 100644 --- a/core/misc/states.es6.js +++ b/core/misc/states.es6.js @@ -33,20 +33,16 @@ Drupal.behaviors.states = { attach(context, settings) { const $states = $(context).find('[data-drupal-states]'); - let config; - let state; const il = $states.length; 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], - }); - } - } + const config = JSON.parse($states[i].getAttribute('data-drupal-states')); + Object.keys(config || {}).forEach((state) => { + new states.Dependent({ + element: $($states[i]), + state: states.State.sanitize(state), + constraints: config[state], + }); + }); } // Execute all postponed functions now. @@ -76,11 +72,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]); + }); }; /** @@ -136,6 +130,7 @@ // 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]; @@ -267,6 +262,7 @@ // 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)); @@ -391,11 +387,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 2b9d3b886a..4fd2052a43 100644 --- a/core/misc/states.js +++ b/core/misc/states.js @@ -15,20 +15,21 @@ Drupal.behaviors.states = { attach: function attach(context, settings) { var $states = $(context).find('[data-drupal-states]'); - var config = void 0; - var state = void 0; var il = $states.length; + + var _loop = function _loop(i) { + var config = JSON.parse($states[i].getAttribute('data-drupal-states')); + Object.keys(config || {}).forEach(function (state) { + new states.Dependent({ + element: $($states[i]), + state: states.State.sanitize(state), + constraints: config[state] + }); + }); + }; + for (var 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] - }); - } - } + _loop(i); } while (states.postponed.length) { @@ -38,14 +39,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 = { @@ -187,16 +188,16 @@ states.Trigger.prototype = { initialize: function initialize() { + var _this2 = 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) { + _this2.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 abbe193862..0a69deb2ca 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,16 @@ * @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) => { + Object.keys(tableSettings[group] || {}).forEach((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 +258,29 @@ 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. + // 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; } } + } - // 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); }; @@ -419,12 +412,14 @@ 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]; @@ -774,18 +769,14 @@ // If a setting exists for affecting the entire group, update all the // fields in the entire dragged group. - for (const group in self.tableSettings) { - if (self.tableSettings.hasOwnProperty(group)) { - const rowSettings = self.rowSettings(group, droppedRow); - if (rowSettings.relationship === 'group') { - for (const n in self.rowObject.children) { - if (self.rowObject.children.hasOwnProperty(n)) { - self.updateField(self.rowObject.children[n], group); - } - } - } + Object.keys(self.tableSettings || {}).forEach((group) => { + const rowSettings = self.rowSettings(group, droppedRow); + if (rowSettings.relationship === 'group') { + Object.keys(self.rowObject.children || {}).forEach((n) => { + self.updateField(self.rowObject.children[n], group); + }); } - } + }); self.rowObject.markChanged(); if (self.changed === false) { @@ -888,6 +879,7 @@ 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; @@ -924,13 +916,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); + }); }; /** @@ -1486,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 859b87e013..06dccfab06 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,16 @@ 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) { + Object.keys(tableSettings[group] || {}).forEach(function (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 +114,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); }; @@ -217,11 +213,13 @@ 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]; @@ -482,18 +480,14 @@ if (self.rowObject.changed === true) { self.updateFields(droppedRow); - for (var group in self.tableSettings) { - if (self.tableSettings.hasOwnProperty(group)) { - var rowSettings = self.rowSettings(group, droppedRow); - if (rowSettings.relationship === 'group') { - for (var n in self.rowObject.children) { - if (self.rowObject.children.hasOwnProperty(n)) { - self.updateField(self.rowObject.children[n], group); - } - } - } + Object.keys(self.tableSettings || {}).forEach(function (group) { + var rowSettings = self.rowSettings(group, droppedRow); + if (rowSettings.relationship === 'group') { + Object.keys(self.rowObject.children || {}).forEach(function (n) { + self.updateField(self.rowObject.children[n], group); + }); } - } + }); self.rowObject.markChanged(); if (self.changed === false) { @@ -577,11 +571,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) { @@ -932,11 +926,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..a6429e0b5e 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..becf7a19e7 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..8dddd2e184 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..d53f49a345 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..8eaeec0479 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..ca3c830370 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 109bfa1a2c..c4f923a02d 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((color) => { + reference[color] = farb.RGBToHSL(farb.unpack(reference[color])); + }); // 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 ee91e56274..5cc0b9be12 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 (color) { + reference[color] = farb.RGBToHSL(farb.unpack(reference[color])); + }); 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 f5988b382d..cfc5e76b78 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 colorStart; let colorEnd; - for (const i in settings.gradients) { - if (settings.gradients.hasOwnProperty(i)) { - colorStart = farb.unpack(form.find(`.color-palette input[name="palette[${settings.gradients[i].colors[0]}]"]`).val()); - colorEnd = farb.unpack(form.find(`.color-palette input[name="palette[${settings.gradients[i].colors[1]}]"]`).val()); - if (colorStart && colorEnd) { - delta = []; - for (const j in colorStart) { - if (colorStart.hasOwnProperty(j)) { - delta[j] = (colorEnd[j] - colorStart[j]) / (settings.gradients[i].vertical ? height[i] : width[i]); - } - } - accum = colorStart; - // Render gradient lines. - form.find(`#gradient-${i} > div`).each(gradientLineColor); - } + Object.keys(settings.gradients || {}).forEach((i) => { + colorStart = farb.unpack(form.find(`.color-palette input[name="palette[${settings.gradients[i].colors[0]}]"]`).val()); + colorEnd = farb.unpack(form.find(`.color-palette input[name="palette[${settings.gradients[i].colors[1]}]"]`).val()); + if (colorStart && colorEnd) { + delta = []; + Object.keys(colorStart || {}).forEach((colorStartKey) => { + delta[colorStartKey] = (colorEnd[colorStartKey] - colorStart[colorStartKey]) / (settings.gradients[i].vertical ? height[i] : width[i]); + }); + accum = colorStart; + // Render gradient lines. + form.find(`#gradient-${i} > div`).each(gradientLineColor); } - } + }); }, }; }(jQuery, Drupal)); diff --git a/core/modules/color/preview.js b/core/modules/color/preview.js index 6ca5e32891..557e7dbdce 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 colorStart = void 0; var colorEnd = void 0; - for (var i in settings.gradients) { - if (settings.gradients.hasOwnProperty(i)) { - colorStart = farb.unpack(form.find('.color-palette input[name="palette[' + settings.gradients[i].colors[0] + ']"]').val()); - colorEnd = farb.unpack(form.find('.color-palette input[name="palette[' + settings.gradients[i].colors[1] + ']"]').val()); - if (colorStart && colorEnd) { - delta = []; - for (var j in colorStart) { - if (colorStart.hasOwnProperty(j)) { - delta[j] = (colorEnd[j] - colorStart[j]) / (settings.gradients[i].vertical ? height[i] : width[i]); - } - } - accum = colorStart; + Object.keys(settings.gradients || {}).forEach(function (i) { + colorStart = farb.unpack(form.find('.color-palette input[name="palette[' + settings.gradients[i].colors[0] + ']"]').val()); + colorEnd = farb.unpack(form.find('.color-palette input[name="palette[' + settings.gradients[i].colors[1] + ']"]').val()); + if (colorStart && colorEnd) { + delta = []; + Object.keys(colorStart || {}).forEach(function (colorStartKey) { + delta[colorStartKey] = (colorEnd[colorStartKey] - colorStart[colorStartKey]) / (settings.gradients[i].vertical ? height[i] : width[i]); + }); + accum = colorStart; - form.find('#gradient-' + i + ' > div').each(gradientLineColor); - } + form.find('#gradient-' + i + ' > 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..a2bdc35b9d 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..1396018a56 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 6c5d0d9945..53ace084db 100644 --- a/core/modules/content_translation/content_translation.admin.es6.js +++ b/core/modules/content_translation/content_translation.admin.es6.js @@ -17,7 +17,6 @@ const $context = $(context); const options = drupalSettings.contentTranslationDependentOptions; let $fields; - let dependentColumns; function fieldsChangeHandler($fields, dependentColumns) { return function (e) { @@ -29,15 +28,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}"]`); - dependentColumns = options.dependent_selectors[field]; + Object.keys(options.dependent_selectors).forEach((field) => { + $fields = $context.find(`input[name^="${field}"]`); + const dependentColumns = options.dependent_selectors[field]; - $fields.on('change', fieldsChangeHandler($fields, dependentColumns)); - Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependentColumns); - } - } + $fields.on('change', fieldsChangeHandler($fields, dependentColumns)); + Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependentColumns); + }); } }, check($fields, dependentColumns, $changed) { @@ -50,23 +47,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 dependentColumns) { - if (dependentColumns.hasOwnProperty(index)) { - column = dependentColumns[index]; + Object.keys(dependentColumns || {}).forEach((index) => { + column = dependentColumns[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 5066438930..33e3fbd45b 100644 --- a/core/modules/content_translation/content_translation.admin.js +++ b/core/modules/content_translation/content_translation.admin.js @@ -11,7 +11,6 @@ var $context = $(context); var options = drupalSettings.contentTranslationDependentOptions; var $fields = void 0; - var dependentColumns = void 0; function fieldsChangeHandler($fields, dependentColumns) { return function (e) { @@ -20,15 +19,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 + '"]'); - dependentColumns = options.dependent_selectors[field]; + Object.keys(options.dependent_selectors).forEach(function (field) { + $fields = $context.find('input[name^="' + field + '"]'); + var dependentColumns = options.dependent_selectors[field]; - $fields.on('change', fieldsChangeHandler($fields, dependentColumns)); - Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependentColumns); - } - } + $fields.on('change', fieldsChangeHandler($fields, dependentColumns)); + Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependentColumns); + }); } }, check: function check($fields, dependentColumns, $changed) { @@ -39,21 +36,19 @@ return $(field).val() === column; } - for (var index in dependentColumns) { - if (dependentColumns.hasOwnProperty(index)) { - column = dependentColumns[index]; + Object.keys(dependentColumns || {}).forEach(function (index) { + column = dependentColumns[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..a9c040c72e 100644 --- a/core/modules/editor/js/editor.admin.es6.js +++ b/core/modules/editor/js/editor.admin.es6.js @@ -567,6 +567,7 @@ // 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]; @@ -879,17 +880,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'); + 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(); - } + // 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..9cec9ada6a 100644 --- a/core/modules/editor/js/editor.admin.js +++ b/core/modules/editor/js/editor.admin.js @@ -256,6 +256,7 @@ } Drupal.filterConfiguration.update(); + for (var filterID in Drupal.filterConfiguration.statuses) { if (Drupal.filterConfiguration.statuses.hasOwnProperty(filterID)) { var filterStatus = Drupal.filterConfiguration.statuses[filterID]; @@ -331,15 +332,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..965a2e4c36 100644 --- a/core/modules/field_ui/field_ui.es6.js +++ b/core/modules/field_ui/field_ui.es6.js @@ -212,13 +212,10 @@ // Separate keys and values. 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..d0e8a6d712 100644 --- a/core/modules/field_ui/field_ui.js +++ b/core/modules/field_ui/field_ui.js @@ -120,13 +120,10 @@ AJAXRefreshRows: function AJAXRefreshRows(rows) { 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..548088397c 100644 --- a/core/modules/filter/filter.filter_html.admin.es6.js +++ b/core/modules/filter/filter.filter_html.admin.es6.js @@ -135,46 +135,44 @@ * A list of new allowed tags. */ _calculateAutoAllowedTags(userAllowedTags, newFeatures) { - let featureName; - let feature; - let featureRule; - let filterRule; - let tag; 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) => { + const feature = newFeatures[featureName]; + let featureRule; + let filterRule; + let tag; + + 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..5f4c6ef9fa 100644 --- a/core/modules/filter/filter.filter_html.admin.js +++ b/core/modules/filter/filter.filter_html.admin.js @@ -74,39 +74,36 @@ } }, _calculateAutoAllowedTags: function _calculateAutoAllowedTags(userAllowedTags, newFeatures) { - var featureName = void 0; - var feature = void 0; - var featureRule = void 0; - var filterRule = void 0; - 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) { + var feature = newFeatures[featureName]; + var featureRule = void 0; + var filterRule = void 0; + var tag = void 0; + + 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 +123,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..dba78b12df 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..b9cb9fc5fb 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..3144d13dc1 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..03e0e22ae7 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..192cea6537 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..a9c0972861 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..51007662e3 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..4bcfe348ed 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 f715fc7fc9..4149d27da7 100644 --- a/core/modules/toolbar/js/toolbar.es6.js +++ b/core/modules/toolbar/js/toolbar.es6.js @@ -56,19 +56,17 @@ // 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 = window.matchMedia(mq); - Drupal.toolbar.mql[label] = mql; - // 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 = window.matchMedia(mq); + Drupal.toolbar.mql[label] = mql; + // 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 547bcd9bac..7246420f88 100644 --- a/core/modules/toolbar/js/toolbar.js +++ b/core/modules/toolbar/js/toolbar.js @@ -34,17 +34,15 @@ Drupal.toolbar.models.toolbarModel = model; - for (var label in options.breakpoints) { - if (options.breakpoints.hasOwnProperty(label)) { - var mq = options.breakpoints[label]; - var mql = window.matchMedia(mq); - Drupal.toolbar.mql[label] = mql; + Object.keys(options.breakpoints).forEach(function (label) { + var mq = options.breakpoints[label]; + var mql = window.matchMedia(mq); + Drupal.toolbar.mql[label] = mql; - 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..108f65c426 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..8156a8b11d 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..13090008d6 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..a147eb8a63 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 eb06da0ec1..0c8535890b 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 175126b83c..a10eb837eb 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]); + }); } };