Commit f1e33ca3 authored by webchick's avatar webchick

Issue #2925064 by drpal, dawehner, droplet, xjm, webchick, justafish: [1/2] JS...

Issue #2925064 by drpal, dawehner, droplet, xjm, webchick, justafish: [1/2] JS codestyle: no-restricted-syntax
parent 9d552cad
......@@ -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",
......
......@@ -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
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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.
......
......@@ -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);
......
......@@ -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');
});
};
/**
......
......@@ -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];