summaryrefslogtreecommitdiffstatshomepage
path: root/core/misc/states.es6.js
diff options
context:
space:
mode:
Diffstat (limited to 'core/misc/states.es6.js')
-rw-r--r--core/misc/states.es6.js42
1 files changed, 20 insertions, 22 deletions
diff --git a/core/misc/states.es6.js b/core/misc/states.es6.js
index ccf99937182e..b45e1e0504cd 100644
--- a/core/misc/states.es6.js
+++ b/core/misc/states.es6.js
@@ -3,7 +3,7 @@
* Drupal's states library.
*/
-(function($, Drupal) {
+(function ($, Drupal) {
/**
* The base States namespace.
*
@@ -99,7 +99,7 @@
const config = JSON.parse(
$states[i].getAttribute('data-drupal-states'),
);
- Object.keys(config || {}).forEach(state => {
+ Object.keys(config || {}).forEach((state) => {
new states.Dependent({
element: $($states[i]),
state: states.State.sanitize(state),
@@ -131,11 +131,11 @@
* element depends on. It can be nested and can contain
* arbitrary AND and OR clauses.
*/
- states.Dependent = function(args) {
+ states.Dependent = function (args) {
$.extend(this, { values: {}, oldValue: null }, args);
this.dependees = this.getDependees();
- Object.keys(this.dependees || {}).forEach(selector => {
+ Object.keys(this.dependees || {}).forEach((selector) => {
this.initializeDependee(selector, this.dependees[selector]);
});
};
@@ -187,7 +187,7 @@
// Cache for the states of this dependee.
this.values[selector] = {};
- Object.keys(dependeeStates).forEach(i => {
+ Object.keys(dependeeStates).forEach((i) => {
let state = dependeeStates[i];
// Make sure we're not initializing this selector/state combination
// twice.
@@ -201,7 +201,7 @@
this.values[selector][state.name] = null;
// Monitor state changes of the specified state for this dependee.
- $(selector).on(`state:${state}`, { selector, state }, e => {
+ $(selector).on(`state:${state}`, { selector, state }, (e) => {
this.update(e.data.selector, e.data.state, e.value);
});
@@ -403,7 +403,7 @@
// Swivel the lookup function so that we can record all available
// selector- state combinations for initialization.
const _compare = this.compare;
- this.compare = function(reference, selector, state) {
+ this.compare = function (reference, selector, state) {
(cache[selector] || (cache[selector] = [])).push(state.name);
// Return nothing (=== undefined) so that the constraint loops are not
// broken.
@@ -429,7 +429,7 @@
* @param {object} args
* Trigger arguments.
*/
- states.Trigger = function(args) {
+ states.Trigger = function (args) {
$.extend(this, args);
if (this.state in states.Trigger.states) {
@@ -454,7 +454,7 @@
// We have a custom trigger initialization function.
trigger.call(window, this.element);
} else {
- Object.keys(trigger || {}).forEach(event => {
+ Object.keys(trigger || {}).forEach((event) => {
this.defaultTrigger(event, trigger[event]);
});
}
@@ -477,7 +477,7 @@
// Attach the event callback.
this.element.on(
event,
- $.proxy(function(e) {
+ $.proxy(function (e) {
const value = valueFn.call(this.element, e);
// Only trigger the event if the value has actually changed.
if (oldValue !== value) {
@@ -492,7 +492,7 @@
);
states.postponed.push(
- $.proxy(function() {
+ $.proxy(function () {
// Trigger the event once for initialization purposes.
this.element.trigger({
type: `state:${this.state}`,
@@ -534,7 +534,7 @@
// support selectors matching multiple checkboxes, iterate over all and
// return whether any is checked.
let checked = false;
- this.each(function() {
+ this.each(function () {
// Use prop() here as we want a boolean of the checkbox state.
// @see http://api.jquery.com/prop/
checked = $(this).prop('checked');
@@ -582,7 +582,7 @@
* @param {string} state
* The name of the state.
*/
- states.State = function(state) {
+ states.State = function (state) {
/**
* Original unresolved name.
*/
@@ -618,7 +618,7 @@
* @return {Drupal.states.state}
* A state object.
*/
- states.State.sanitize = function(state) {
+ states.State.sanitize = function (state) {
if (state instanceof states.State) {
return state;
}
@@ -674,7 +674,7 @@
*/
const $document = $(document);
- $document.on('state:disabled', e => {
+ $document.on('state:disabled', (e) => {
// Only act when this change was triggered by a dependency and not by the
// element monitoring itself.
if (e.trigger) {
@@ -690,7 +690,7 @@
}
});
- $document.on('state:required', e => {
+ $document.on('state:required', (e) => {
if (e.trigger) {
if (e.value) {
const label = `label${e.target.id ? `[for=${e.target.id}]` : ''}`;
@@ -712,7 +712,7 @@
}
});
- $document.on('state:visible', e => {
+ $document.on('state:visible', (e) => {
if (e.trigger) {
$(e.target)
.closest('.js-form-item, .js-form-submit, .js-form-wrapper')
@@ -720,18 +720,16 @@
}
});
- $document.on('state:checked', e => {
+ $document.on('state:checked', (e) => {
if (e.trigger) {
$(e.target).prop('checked', e.value);
}
});
- $document.on('state:collapsed', e => {
+ $document.on('state:collapsed', (e) => {
if (e.trigger) {
if ($(e.target).is('[open]') === e.value) {
- $(e.target)
- .find('> summary')
- .trigger('click');
+ $(e.target).find('> summary').trigger('click');
}
}
});