Commit dcfee314 authored by xjm's avatar xjm

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

Revert "Issue #2925064 by drpal, dawehner, xjm, justafish, droplet: [1/2] JS codestyle: no-restricted-syntax"

This reverts commit b0a4d7e0.
parent f7e2d52e
......@@ -3,6 +3,7 @@
"rules": {
"no-use-before-define": "off",
"no-shadow": "off",
"no-restricted-syntax": "off",
"no-new": "off",
"no-continue": "off",
"new-cap": "off",
......
......@@ -40,7 +40,11 @@
}
// Load all Ajax behaviors specified in the settings.
Object.keys(settings.ajax || {}).forEach(base => loadAjaxBehavior(base));
for (const base in settings.ajax) {
if (settings.ajax.hasOwnProperty(base)) {
loadAjaxBehavior(base);
}
}
Drupal.ajax.bindAjaxLinks(document.body);
......@@ -865,14 +869,14 @@
// Track if any command is altering the focus so we can avoid changing the
// focus set by the Ajax command.
let focusChanged = false;
Object.keys(response).forEach((i) => {
if (response[i].command && this.commands[response[i].command]) {
for (const i in response) {
if (response.hasOwnProperty(i) && 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,9 +21,11 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
});
}
Object.keys(settings.ajax || {}).forEach(function (base) {
return loadAjaxBehavior(base);
});
for (var base in settings.ajax) {
if (settings.ajax.hasOwnProperty(base)) {
loadAjaxBehavior(base);
}
}
Drupal.ajax.bindAjaxLinks(document.body);
......@@ -393,8 +395,6 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
};
Drupal.Ajax.prototype.success = function (response, status) {
var _this = this;
if (this.progress.element) {
$(this.progress.element).remove();
}
......@@ -406,14 +406,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;
Object.keys(response).forEach(function (i) {
if (response[i].command && _this.commands[response[i].command]) {
_this.commands[response[i].command](_this, response[i], 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);
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.
Object.keys(behaviors).forEach((i) => {
if (typeof behaviors[i].attach === 'function') {
for (const i in behaviors) {
if (behaviors.hasOwnProperty(i) && 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.
Object.keys(behaviors).forEach((i) => {
if (typeof behaviors[i].detach === 'function') {
for (const i in behaviors) {
if (behaviors.hasOwnProperty(i) && 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,24 +269,26 @@ window.Drupal = { behaviors: {}, locale: {} };
// Keep args intact.
const processedArgs = {};
// Transform arguments before inserting them.
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;
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;
}
}
});
}
return Drupal.stringReplace(str, processedArgs, null);
};
......@@ -315,7 +317,11 @@ window.Drupal = { behaviors: {}, locale: {} };
// If the array of keys is not passed then collect the keys from the args.
if (!Array.isArray(keys)) {
keys = [];
Object.keys(args).forEach(key => keys.push(key));
for (const k in args) {
if (args.hasOwnProperty(k)) {
keys.push(k);
}
}
// 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;
Object.keys(behaviors).forEach(function (i) {
if (typeof behaviors[i].attach === 'function') {
for (var i in behaviors) {
if (behaviors.hasOwnProperty(i) && 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;
Object.keys(behaviors).forEach(function (i) {
if (typeof behaviors[i].detach === 'function') {
for (var i in behaviors) {
if (behaviors.hasOwnProperty(i) && typeof behaviors[i].detach === 'function') {
try {
behaviors[i].detach(context, settings, trigger);
} catch (e) {
Drupal.throwError(e);
}
}
});
}
};
Drupal.checkPlain = function (str) {
......@@ -55,21 +55,23 @@ window.Drupal = { behaviors: {}, locale: {} };
Drupal.formatString = function (str, args) {
var processedArgs = {};
Object.keys(args).forEach(function (key) {
switch (key.charAt(0)) {
case '@':
processedArgs[key] = Drupal.checkPlain(args[key]);
break;
for (var key in args) {
if (args.hasOwnProperty(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);
};
......@@ -81,9 +83,11 @@ window.Drupal = { behaviors: {}, locale: {} };
if (!Array.isArray(keys)) {
keys = [];
Object.keys(args).forEach(function (key) {
return keys.push(key);
});
for (var k in args) {
if (args.hasOwnProperty(k)) {
keys.push(k);
}
}
keys.sort(function (a, b) {
return a.length - b.length;
......
......@@ -38,13 +38,15 @@
const il = $states.length;
for (let i = 0; i < il; i++) {
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],
});
});
for (state in config) {
if (config.hasOwnProperty(state)) {
new states.Dependent({
element: $($states[i]),
state: states.State.sanitize(state),
constraints: config[state],
});
}
}
}
// Execute all postponed functions now.
......@@ -74,9 +76,11 @@
$.extend(this, { values: {}, oldValue: null }, args);
this.dependees = this.getDependees();
Object.keys(this.dependees).forEach((selector) => {
this.initializeDependee(selector, this.dependees[selector]);
});
for (const selector in this.dependees) {
if (this.dependees.hasOwnProperty(selector)) {
this.initializeDependee(selector, this.dependees[selector]);
}
}
};
/**
......@@ -132,7 +136,6 @@
// 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];
......@@ -264,7 +267,6 @@
// 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));
......@@ -389,9 +391,11 @@
trigger.call(window, this.element);
}
else {
Object.keys(trigger).forEach((event) => {
this.defaultTrigger(event, trigger[event]);
});
for (const event in trigger) {
if (trigger.hasOwnProperty(event)) {
this.defaultTrigger(event, trigger[event]);
}
}
}
// Mark this trigger as initialized for this element.
......
......@@ -18,20 +18,17 @@
var config = void 0;
var state = void 0;
var il = $states.length;
var _loop = function _loop(i) {
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++) {
_loop(i);
config = JSON.parse($states[i].getAttribute('data-drupal-states'));
for (state in config) {
if (config.hasOwnProperty(state)) {
new states.Dependent({
element: $($states[i]),
state: states.State.sanitize(state),
constraints: config[state]
});
}
}
}
while (states.postponed.length) {
......@@ -41,14 +38,14 @@
};
states.Dependent = function (args) {
var _this = this;
$.extend(this, { values: {}, oldValue: null }, args);
this.dependees = this.getDependees();
Object.keys(this.dependees).forEach(function (selector) {
_this.initializeDependee(selector, _this.dependees[selector]);
});
for (var selector in this.dependees) {
if (this.dependees.hasOwnProperty(selector)) {
this.initializeDependee(selector, this.dependees[selector]);
}
}
};
states.Dependent.comparisons = {
......@@ -190,16 +187,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 {
Object.keys(trigger).forEach(function (event) {
_this2.defaultTrigger(event, trigger[event]);
});
for (var event in trigger) {
if (trigger.hasOwnProperty(event)) {
this.defaultTrigger(event, trigger[event]);
}
}
}
this.element.data('trigger:' + this.state, true);
......
......@@ -41,9 +41,11 @@
}
}
Object.keys(settings.tableDrag).forEach((base) => {
initTableDrag($(context).find(`#${base}`).once('tabledrag'), base);
});
for (const base in settings.tableDrag) {
if (settings.tableDrag.hasOwnProperty(base)) {
initTableDrag($(context).find(`#${base}`).once('tabledrag'), base);
}
}
},
};
......@@ -170,16 +172,20 @@
* @type {bool}
*/
this.indentEnabled = false;
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;
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;
}
}
}
});
});
}
}
if (this.indentEnabled) {
/**
* Total width of indents, set in makeDraggable.
......@@ -258,29 +264,30 @@
let hidden;
let cell;
let columnIndex;
Object.keys(this.tableSettings).forEach((group) => {
// Find the first field in this group.
// eslint-disable-next-line no-restricted-syntax
for (const d in this.tableSettings[group]) {
if (this.tableSettings[group].hasOwnProperty(d)) {
const field = $table.find(`.${this.tableSettings[group][d].target}`).eq(0);
if (field.length && this.tableSettings[group][d].hidden) {
hidden = this.tableSettings[group][d].hidden;
cell = field.closest('td');
break;
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;
}
}
}
}
// 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);
};
......@@ -412,14 +419,12 @@
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];
......@@ -769,14 +774,18 @@
// If a setting exists for affecting the entire group, update all the
// fields in the entire dragged 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);
});
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);
}
}
}
}
});
}
self.rowObject.markChanged();
if (self.changed === false) {
......@@ -879,7 +888,6 @@
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;
......@@ -916,11 +924,13 @@
* DOM object for the row that was just dropped.
*/
Drupal.tableDrag.prototype.updateFields = function (changedRow) {
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);
});
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);
}
}
};
/**
......@@ -1476,13 +1486,15 @@
* Remove indentation helper classes from the current row group.
*/
Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () {
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');
});
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');
}
}
};
/**
......
......@@ -16,15 +16,15 @@
}
}
Object.keys(settings.tableDrag).forEach(function (base) {
initTableDrag($(context).find('#' + base).once('tabledrag'), base);
});
for (var base in settings.tableDrag) {
if (settings.tableDrag.hasOwnProperty(base)) {
initTableDrag($(context).find('#' + base).once('tabledrag'), base);
}
}
}
};
Drupal.tableDrag = function (table, tableSettings) {
var _this = this;
var self = this;
var $table = $(table);
......@@ -59,16 +59,20 @@
this.windowHeight = 0;
this.indentEnabled = false;
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;
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;
}
}
}
});
});
}
}
if (this.indentEnabled) {
this.indentCount = 1;
......@@ -114,29 +118,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;
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;
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;
}
}
}
}
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));
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));
}
}
});
}