Commit b4064da7 authored by alexpott's avatar alexpott

Issue #2917234 by drpal, alexpott, dawehner, droplet: [2/2] JS codestyle: no-restricted-syntax

parent bd3893b3
......@@ -120,38 +120,30 @@
* dependee's compliance status.
*/
initializeDependee(selector, dependeeStates) {
let state;
const self = this;
function stateEventHandler(e) {
self.update(e.data.selector, e.data.state, e.value);
}
// Cache for the states of this dependee.
this.values[selector] = {};
// eslint-disable-next-line no-restricted-syntax
for (const i in dependeeStates) {
if (dependeeStates.hasOwnProperty(i)) {
state = dependeeStates[i];
// Make sure we're not initializing this selector/state combination
// twice.
if ($.inArray(state, dependeeStates) === -1) {
continue;
}
Object.keys(dependeeStates).forEach((i) => {
let state = dependeeStates[i];
// Make sure we're not initializing this selector/state combination
// twice.
if ($.inArray(state, dependeeStates) === -1) {
return;
}
state = states.State.sanitize(state);
state = states.State.sanitize(state);
// Initialize the value of this state.
this.values[selector][state.name] = null;
// Initialize the value of this state.
this.values[selector][state.name] = null;
// Monitor state changes of the specified state for this dependee.
$(selector).on(`state:${state}`, { selector, state }, stateEventHandler);
// Monitor state changes of the specified state for this dependee.
$(selector).on(`state:${state}`, { selector, state }, (e) => {
this.update(e.data.selector, e.data.state, e.value);
});
// Make sure the event we just bound ourselves to is actually fired.
new states.Trigger({ selector, state });
}
}
// Make sure the event we just bound ourselves to is actually fired.
new states.Trigger({ selector, state });
});
},
/**
......@@ -262,17 +254,18 @@
// bogus, we don't want to end up with an infinite loop.
else if ($.isPlainObject(constraints)) {
// This constraint is an object (AND).
// eslint-disable-next-line no-restricted-syntax
for (const n in constraints) {
if (constraints.hasOwnProperty(n)) {
result = ternary(result, this.checkConstraints(constraints[n], selector, n));
// False and anything else will evaluate to false, so return when
// any false condition is found.
if (result === false) {
return false;
}
}
}
result = Object.keys(constraints).every((constraint) => {
const check = this.checkConstraints(
constraints[constraint],
selector,
constraint,
);
/**
* The checkConstraints() function's return value can be undefined. If
* this so, consider it to have returned true.
*/
return typeof check === 'undefined' ? true : check;
});
}
return result;
},
......@@ -655,30 +648,6 @@
* implement any logic that is particular to states.
*/
/**
* Bitwise AND with a third undefined state.
*
* @function Drupal.states~ternary
*
* @param {*} a
* Value a.
* @param {*} b
* Value b
*
* @return {bool}
* The result.
*/
function ternary(a, b) {
if (typeof a === 'undefined') {
return b;
}
else if (typeof b === 'undefined') {
return a;
}
return a && b;
}
/**
* Inverts a (if it's not undefined) when invertState is true.
*
......
......@@ -63,32 +63,27 @@
states.Dependent.prototype = {
initializeDependee: function initializeDependee(selector, dependeeStates) {
var state = void 0;
var self = this;
function stateEventHandler(e) {
self.update(e.data.selector, e.data.state, e.value);
}
var _this2 = this;
this.values[selector] = {};
for (var i in dependeeStates) {
if (dependeeStates.hasOwnProperty(i)) {
state = dependeeStates[i];
Object.keys(dependeeStates).forEach(function (i) {
var state = dependeeStates[i];
if ($.inArray(state, dependeeStates) === -1) {
continue;
}
if ($.inArray(state, dependeeStates) === -1) {
return;
}
state = states.State.sanitize(state);
state = states.State.sanitize(state);
this.values[selector][state.name] = null;
_this2.values[selector][state.name] = null;
$(selector).on('state:' + state, { selector: selector, state: state }, stateEventHandler);
$(selector).on('state:' + state, { selector: selector, state: state }, function (e) {
_this2.update(e.data.selector, e.data.state, e.value);
});
new states.Trigger({ selector: selector, state: state });
}
}
new states.Trigger({ selector: selector, state: state });
});
},
compare: function compare(reference, selector, state) {
var value = this.values[selector][state.name];
......@@ -116,6 +111,8 @@
}
},
verifyConstraints: function verifyConstraints(constraints, selector) {
var _this3 = this;
var result = void 0;
if ($.isArray(constraints)) {
var hasXor = $.inArray('xor', constraints) === -1;
......@@ -131,15 +128,11 @@
}
}
} else if ($.isPlainObject(constraints)) {
for (var n in constraints) {
if (constraints.hasOwnProperty(n)) {
result = ternary(result, this.checkConstraints(constraints[n], selector, n));
result = Object.keys(constraints).every(function (constraint) {
var check = _this3.checkConstraints(constraints[constraint], selector, constraint);
if (result === false) {
return false;
}
}
}
return typeof check === 'undefined' ? true : check;
});
}
return result;
},
......@@ -188,7 +181,7 @@
states.Trigger.prototype = {
initialize: function initialize() {
var _this2 = this;
var _this4 = this;
var trigger = states.Trigger.states[this.state];
......@@ -196,7 +189,7 @@
trigger.call(window, this.element);
} else {
Object.keys(trigger || {}).forEach(function (event) {
_this2.defaultTrigger(event, trigger[event]);
_this4.defaultTrigger(event, trigger[event]);
});
}
......@@ -353,16 +346,6 @@
}
});
function ternary(a, b) {
if (typeof a === 'undefined') {
return b;
} else if (typeof b === 'undefined') {
return a;
}
return a && b;
}
function invert(a, invertState) {
return invertState && typeof a !== 'undefined' ? !a : a;
}
......
......@@ -260,17 +260,15 @@
let columnIndex;
Object.keys(this.tableSettings || {}).forEach((group) => {
// Find the first field in this group.
// eslint-disable-next-line no-restricted-syntax
for (const d in this.tableSettings[group]) {
if (this.tableSettings[group].hasOwnProperty(d)) {
const field = $table.find(`.${this.tableSettings[group][d].target}`).eq(0);
if (field.length && this.tableSettings[group][d].hidden) {
hidden = this.tableSettings[group][d].hidden;
cell = field.closest('td');
break;
}
Object.keys(this.tableSettings[group]).some((tableSetting) => {
const field = $table.find(`.${this.tableSettings[group][tableSetting].target}`).eq(0);
if (field.length && this.tableSettings[group][tableSetting].hidden) {
hidden = this.tableSettings[group][tableSetting].hidden;
cell = field.closest('td');
return true;
}
}
return false;
});
// Mark the column containing this field so it can be hidden.
if (hidden && cell[0]) {
......@@ -412,23 +410,18 @@
Drupal.tableDrag.prototype.rowSettings = function (group, row) {
const field = $(row).find(`.${group}`);
const tableSettingsGroup = this.tableSettings[group];
// eslint-disable-next-line no-restricted-syntax
for (const delta in tableSettingsGroup) {
if (tableSettingsGroup.hasOwnProperty(delta)) {
const targetClass = tableSettingsGroup[delta].target;
if (field.is(`.${targetClass}`)) {
// Return a copy of the row settings.
const rowSettings = {};
// eslint-disable-next-line no-restricted-syntax
for (const n in tableSettingsGroup[delta]) {
if (tableSettingsGroup[delta].hasOwnProperty(n)) {
rowSettings[n] = tableSettingsGroup[delta][n];
}
}
return rowSettings;
}
return Object.keys(tableSettingsGroup).map((delta) => {
const targetClass = tableSettingsGroup[delta].target;
let rowSettings;
if (field.is(`.${targetClass}`)) {
// Return a copy of the row settings.
rowSettings = {};
Object.keys(tableSettingsGroup[delta]).forEach((n) => {
rowSettings[n] = tableSettingsGroup[delta][n];
});
}
}
return rowSettings;
}).filter(rowSetting => rowSetting)[0];
};
/**
......@@ -879,11 +872,9 @@
if ((y > (rowY - rowHeight)) && (y < (rowY + rowHeight))) {
if (this.indentEnabled) {
// Check that this row is not a child of the row being dragged.
// eslint-disable-next-line no-restricted-syntax
for (n in this.rowObject.group) {
if (this.rowObject.group[n] === row) {
return null;
}
if (Object.keys(this.rowObject.group)
.some(o => (this.rowObject.group[o] === row))) {
return null;
}
}
// Do not allow a row to be swapped with itself.
......
......@@ -4,6 +4,7 @@
* https://www.drupal.org/node/2815083
* @preserve
**/
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
(function ($, Drupal, drupalSettings) {
var showWeight = JSON.parse(localStorage.getItem('Drupal.tableDrag.showWeight'));
......@@ -121,16 +122,15 @@
var cell = void 0;
var columnIndex = void 0;
Object.keys(this.tableSettings || {}).forEach(function (group) {
for (var d in _this2.tableSettings[group]) {
if (_this2.tableSettings[group].hasOwnProperty(d)) {
var field = $table.find('.' + _this2.tableSettings[group][d].target).eq(0);
if (field.length && _this2.tableSettings[group][d].hidden) {
hidden = _this2.tableSettings[group][d].hidden;
cell = field.closest('td');
break;
}
Object.keys(_this2.tableSettings[group]).some(function (tableSetting) {
var field = $table.find('.' + _this2.tableSettings[group][tableSetting].target).eq(0);
if (field.length && _this2.tableSettings[group][tableSetting].hidden) {
hidden = _this2.tableSettings[group][tableSetting].hidden;
cell = field.closest('td');
return true;
}
}
return false;
});
if (hidden && cell[0]) {
columnIndex = cell.parent().find('> td').index(cell.get(0)) + 1;
......@@ -213,22 +213,19 @@
Drupal.tableDrag.prototype.rowSettings = function (group, row) {
var field = $(row).find('.' + group);
var tableSettingsGroup = this.tableSettings[group];
for (var delta in tableSettingsGroup) {
if (tableSettingsGroup.hasOwnProperty(delta)) {
var targetClass = tableSettingsGroup[delta].target;
if (field.is('.' + targetClass)) {
var rowSettings = {};
for (var n in tableSettingsGroup[delta]) {
if (tableSettingsGroup[delta].hasOwnProperty(n)) {
rowSettings[n] = tableSettingsGroup[delta][n];
}
}
return rowSettings;
}
return Object.keys(tableSettingsGroup).map(function (delta) {
var targetClass = tableSettingsGroup[delta].target;
var rowSettings = void 0;
if (field.is('.' + targetClass)) {
rowSettings = {};
Object.keys(tableSettingsGroup[delta]).forEach(function (n) {
rowSettings[n] = tableSettingsGroup[delta][n];
});
}
}
return rowSettings;
}).filter(function (rowSetting) {
return rowSetting;
})[0];
};
Drupal.tableDrag.prototype.makeDraggable = function (item) {
......@@ -532,8 +529,11 @@
};
Drupal.tableDrag.prototype.findDropTargetRow = function (x, y) {
var _this3 = this;
var rows = $(this.table.tBodies[0].rows).not(':hidden');
for (var n = 0; n < rows.length; n++) {
var _loop = function _loop(n) {
var row = rows[n];
var $row = $(row);
var rowY = $row.offset().top;
......@@ -546,35 +546,49 @@
}
if (y > rowY - rowHeight && y < rowY + rowHeight) {
if (this.indentEnabled) {
for (n in this.rowObject.group) {
if (this.rowObject.group[n] === row) {
return null;
}
if (_this3.indentEnabled) {
if (Object.keys(_this3.rowObject.group).some(function (o) {
return _this3.rowObject.group[o] === row;
})) {
return {
v: null
};
}
} else if (row === this.rowObject.element) {
return null;
} else if (row === _this3.rowObject.element) {
return {
v: null
};
}
if (!this.rowObject.isValidSwap(row)) {
return null;
if (!_this3.rowObject.isValidSwap(row)) {
return {
v: null
};
}
while ($row.is(':hidden') && $row.prev('tr').is(':hidden')) {
$row = $row.prev('tr:first-of-type');
row = $row.get(0);
}
return row;
return {
v: row
};
}
};
for (var n = 0; n < rows.length; n++) {
var _ret = _loop(n);
if ((typeof _ret === 'undefined' ? 'undefined' : _typeof(_ret)) === "object") return _ret.v;
}
return null;
};
Drupal.tableDrag.prototype.updateFields = function (changedRow) {
var _this3 = this;
var _this4 = this;
Object.keys(this.tableSettings || {}).forEach(function (group) {
_this3.updateField(changedRow, group);
_this4.updateField(changedRow, group);
});
};
......@@ -926,10 +940,10 @@
};
Drupal.tableDrag.prototype.row.prototype.removeIndentClasses = function () {
var _this4 = this;
var _this5 = this;
Object.keys(this.children || {}).forEach(function (n) {
$(_this4.children[n]).find('.js-indentation').removeClass('tree-child').removeClass('tree-child-first').removeClass('tree-child-last').removeClass('tree-child-horizontal');
$(_this5.children[n]).find('.js-indentation').removeClass('tree-child').removeClass('tree-child-first').removeClass('tree-child-last').removeClass('tree-child-horizontal');
});
};
......
......@@ -567,17 +567,10 @@
// If any filter's current status forbids the editor feature, return
// false.
Drupal.filterConfiguration.update();
// eslint-disable-next-line no-restricted-syntax
for (const filterID in Drupal.filterConfiguration.statuses) {
if (Drupal.filterConfiguration.statuses.hasOwnProperty(filterID)) {
const filterStatus = Drupal.filterConfiguration.statuses[filterID];
if (!(filterStatusAllowsFeature(filterStatus, feature))) {
return false;
}
}
}
return true;
return Object.keys(Drupal.filterConfiguration.statuses)
.every(filterID => (
filterStatusAllowsFeature(Drupal.filterConfiguration.statuses[filterID], feature)
));
},
};
......
......@@ -256,17 +256,9 @@
}
Drupal.filterConfiguration.update();
for (var filterID in Drupal.filterConfiguration.statuses) {
if (Drupal.filterConfiguration.statuses.hasOwnProperty(filterID)) {
var filterStatus = Drupal.filterConfiguration.statuses[filterID];
if (!filterStatusAllowsFeature(filterStatus, feature)) {
return false;
}
}
}
return true;
return Object.keys(Drupal.filterConfiguration.statuses).every(function (filterID) {
return filterStatusAllowsFeature(Drupal.filterConfiguration.statuses[filterID], feature);
});
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment