Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / contextual / js / toolbar / models / StateModel.es6.js
index 0a1b1614687f1cc350654d66dd974433f8cda688..73781534ce096f506d31ede86fb058589e261a4d 100644 (file)
  * A Backbone Model for the state of Contextual module's edit toolbar tab.
  */
 
-(function (Drupal, Backbone) {
-  Drupal.contextualToolbar.StateModel = Backbone.Model.extend(/** @lends Drupal.contextualToolbar.StateModel# */{
-
-    /**
-     * @type {object}
-     *
-     * @prop {bool} isViewing
-     * @prop {bool} isVisible
-     * @prop {number} contextualCount
-     * @prop {Drupal~TabbingContext} tabbingContext
-     */
-    defaults: /** @lends Drupal.contextualToolbar.StateModel# */{
-
+(function(Drupal, Backbone) {
+  Drupal.contextualToolbar.StateModel = Backbone.Model.extend(
+    /** @lends Drupal.contextualToolbar.StateModel# */ {
       /**
-       * Indicates whether the toggle is currently in "view" or "edit" mode.
+       * @type {object}
        *
-       * @type {bool}
+       * @prop {bool} isViewing
+       * @prop {bool} isVisible
+       * @prop {number} contextualCount
+       * @prop {Drupal~TabbingContext} tabbingContext
        */
-      isViewing: true,
+      defaults: /** @lends Drupal.contextualToolbar.StateModel# */ {
+        /**
+         * Indicates whether the toggle is currently in "view" or "edit" mode.
+         *
+         * @type {bool}
+         */
+        isViewing: true,
+
+        /**
+         * Indicates whether the toggle should be visible or hidden. Automatically
+         * calculated, depends on contextualCount.
+         *
+         * @type {bool}
+         */
+        isVisible: false,
+
+        /**
+         * Tracks how many contextual links exist on the page.
+         *
+         * @type {number}
+         */
+        contextualCount: 0,
+
+        /**
+         * A TabbingContext object as returned by {@link Drupal~TabbingManager}:
+         * the set of tabbable elements when edit mode is enabled.
+         *
+         * @type {?Drupal~TabbingContext}
+         */
+        tabbingContext: null,
+      },
 
       /**
-       * Indicates whether the toggle should be visible or hidden. Automatically
-       * calculated, depends on contextualCount.
+       * Models the state of the edit mode toggle.
+       *
+       * @constructs
        *
-       * @type {bool}
+       * @augments Backbone.Model
+       *
+       * @param {object} attrs
+       *   Attributes for the backbone model.
+       * @param {object} options
+       *   An object with the following option:
+       * @param {Backbone.collection} options.contextualCollection
+       *   The collection of {@link Drupal.contextual.StateModel} models that
+       *   represent the contextual links on the page.
        */
-      isVisible: false,
+      initialize(attrs, options) {
+        // Respond to new/removed contextual links.
+        this.listenTo(
+          options.contextualCollection,
+          'reset remove add',
+          this.countContextualLinks,
+        );
+        this.listenTo(
+          options.contextualCollection,
+          'add',
+          this.lockNewContextualLinks,
+        );
+
+        // Automatically determine visibility.
+        this.listenTo(this, 'change:contextualCount', this.updateVisibility);
+
+        // Whenever edit mode is toggled, lock all contextual links.
+        this.listenTo(this, 'change:isViewing', (model, isViewing) => {
+          options.contextualCollection.each(contextualModel => {
+            contextualModel.set('isLocked', !isViewing);
+          });
+        });
+      },
 
       /**
-       * Tracks how many contextual links exist on the page.
+       * Tracks the number of contextual link models in the collection.
        *
-       * @type {number}
+       * @param {Drupal.contextual.StateModel} contextualModel
+       *   The contextual links model that was added or removed.
+       * @param {Backbone.Collection} contextualCollection
+       *    The collection of contextual link models.
        */
-      contextualCount: 0,
+      countContextualLinks(contextualModel, contextualCollection) {
+        this.set('contextualCount', contextualCollection.length);
+      },
 
       /**
-       * A TabbingContext object as returned by {@link Drupal~TabbingManager}:
-       * the set of tabbable elements when edit mode is enabled.
+       * Lock newly added contextual links if edit mode is enabled.
        *
-       * @type {?Drupal~TabbingContext}
+       * @param {Drupal.contextual.StateModel} contextualModel
+       *   The contextual links model that was added.
+       * @param {Backbone.Collection} [contextualCollection]
+       *    The collection of contextual link models.
        */
-      tabbingContext: null,
-    },
-
-    /**
-     * Models the state of the edit mode toggle.
-     *
-     * @constructs
-     *
-     * @augments Backbone.Model
-     *
-     * @param {object} attrs
-     *   Attributes for the backbone model.
-     * @param {object} options
-     *   An object with the following option:
-     * @param {Backbone.collection} options.contextualCollection
-     *   The collection of {@link Drupal.contextual.StateModel} models that
-     *   represent the contextual links on the page.
-     */
-    initialize(attrs, options) {
-      // Respond to new/removed contextual links.
-      this.listenTo(options.contextualCollection, 'reset remove add', this.countContextualLinks);
-      this.listenTo(options.contextualCollection, 'add', this.lockNewContextualLinks);
+      lockNewContextualLinks(contextualModel, contextualCollection) {
+        if (!this.get('isViewing')) {
+          contextualModel.set('isLocked', true);
+        }
+      },
 
-      // Automatically determine visibility.
-      this.listenTo(this, 'change:contextualCount', this.updateVisibility);
-
-      // Whenever edit mode is toggled, lock all contextual links.
-      this.listenTo(this, 'change:isViewing', (model, isViewing) => {
-        options.contextualCollection.each((contextualModel) => {
-          contextualModel.set('isLocked', !isViewing);
-        });
-      });
-    },
-
-    /**
-     * Tracks the number of contextual link models in the collection.
-     *
-     * @param {Drupal.contextual.StateModel} contextualModel
-     *   The contextual links model that was added or removed.
-     * @param {Backbone.Collection} contextualCollection
-     *    The collection of contextual link models.
-     */
-    countContextualLinks(contextualModel, contextualCollection) {
-      this.set('contextualCount', contextualCollection.length);
-    },
-
-    /**
-     * Lock newly added contextual links if edit mode is enabled.
-     *
-     * @param {Drupal.contextual.StateModel} contextualModel
-     *   The contextual links model that was added.
-     * @param {Backbone.Collection} [contextualCollection]
-     *    The collection of contextual link models.
-     */
-    lockNewContextualLinks(contextualModel, contextualCollection) {
-      if (!this.get('isViewing')) {
-        contextualModel.set('isLocked', true);
-      }
-    },
-
-    /**
-     * Automatically updates visibility of the view/edit mode toggle.
-     */
-    updateVisibility() {
-      this.set('isVisible', this.get('contextualCount') > 0);
+      /**
+       * Automatically updates visibility of the view/edit mode toggle.
+       */
+      updateVisibility() {
+        this.set('isVisible', this.get('contextualCount') > 0);
+      },
     },
-
-  });
-}(Drupal, Backbone));
+  );
+})(Drupal, Backbone);