Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / misc / states.js
index 61bbf46c612eb9470d9d7fdb89429d8d6c84ffd0..4fd2052a4398ac58a46b241a1a484686285bfe70 100644 (file)
@@ -6,27 +6,30 @@
 **/
 
 (function ($, Drupal) {
-  var states = Drupal.states = {
+  var states = {
     postponed: []
   };
 
+  Drupal.states = states;
+
   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) {
   };
 
   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 = {
 
   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);
   };
 
   states.State = function (state) {
-    this.pristine = this.name = state;
+    this.pristine = state;
+    this.name = state;
 
     var process = true;
     do {