Added the Search API Synonym module to deal specifically with licence and license...
[yaffs-website] / web / core / misc / states.js
index 61bbf46c612eb9470d9d7fdb89429d8d6c84ffd0..7b451b07dec9c55526461602ac7860ae7738dee0 100644 (file)
@@ -6,27 +6,53 @@
 **/
 
 (function ($, Drupal) {
-  var states = Drupal.states = {
+  var states = {
     postponed: []
   };
 
+  Drupal.states = states;
+
+  function invert(a, invertState) {
+    return invertState && typeof a !== 'undefined' ? !a : a;
+  }
+
+  function _compare2(a, b) {
+    if (a === b) {
+      return typeof a === 'undefined' ? a : true;
+    }
+
+    return typeof a === 'undefined' || typeof b === 'undefined';
+  }
+
+  function ternary(a, b) {
+    if (typeof a === 'undefined') {
+      return b;
+    }
+    if (typeof b === 'undefined') {
+      return a;
+    }
+
+    return a && b;
+  }
+
   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.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];
 
         value = invert(value, this.state.invert);
 
-        this.element.trigger({ type: 'state:' + this.state, value: value, trigger: true });
+        this.element.trigger({
+          type: 'state:' + this.state,
+          value: value,
+          trigger: true
+        });
       }
     },
     verifyConstraints: function verifyConstraints(constraints, selector) {
 
   states.Trigger.prototype = {
     initialize: function initialize() {
+      var _this3 = 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) {
+          _this3.defaultTrigger(event, trigger[event]);
+        });
       }
 
       this.element.data('trigger:' + this.state, true);
         var value = valueFn.call(this.element, e);
 
         if (oldValue !== value) {
-          this.element.trigger({ type: 'state:' + this.state, value: value, oldValue: oldValue });
+          this.element.trigger({
+            type: 'state:' + this.state,
+            value: value,
+            oldValue: oldValue
+          });
           oldValue = value;
         }
       }, this));
 
       states.postponed.push($.proxy(function () {
-        this.element.trigger({ type: 'state:' + this.state, value: oldValue, oldValue: null });
+        this.element.trigger({
+          type: 'state:' + this.state,
+          value: oldValue,
+          oldValue: null
+        });
       }, this));
     }
   };
   };
 
   states.State = function (state) {
-    this.pristine = this.name = state;
+    this.pristine = state;
+    this.name = state;
 
     var process = true;
     do {
       }
     }
   });
-
-  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;
-  }
-
-  function _compare2(a, b) {
-    if (a === b) {
-      return typeof a === 'undefined' ? a : true;
-    }
-
-    return typeof a === 'undefined' || typeof b === 'undefined';
-  }
 })(jQuery, Drupal);
\ No newline at end of file