X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Fcontextual%2Fjs%2Ftoolbar%2Fmodels%2FStateModel.js;h=277dec0b010e84f1b44927e7b32469490b037c95;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=d9159e4e97f69762629120d56e6b1ce5855fdeba;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/modules/contextual/js/toolbar/models/StateModel.js b/web/core/modules/contextual/js/toolbar/models/StateModel.js index d9159e4e9..277dec0b0 100644 --- a/web/core/modules/contextual/js/toolbar/models/StateModel.js +++ b/web/core/modules/contextual/js/toolbar/models/StateModel.js @@ -1,119 +1,44 @@ /** - * @file - * A Backbone Model for the state of Contextual module's edit toolbar tab. - */ +* DO NOT EDIT THIS FILE. +* See the following change record for more information, +* https://www.drupal.org/node/2815083 +* @preserve +**/ (function (Drupal, Backbone) { - - 'use strict'; - - 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# */{ - - /** - * Indicates whether the toggle is currently in "view" or "edit" mode. - * - * @type {bool} - */ + Drupal.contextualToolbar.StateModel = Backbone.Model.extend({ + defaults: { 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 }, - /** - * 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: function (attrs, options) { - // Respond to new/removed contextual links. + initialize: function initialize(attrs, options) { 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', function (model, isViewing) { options.contextualCollection.each(function (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: function (contextualModel, contextualCollection) { + countContextualLinks: function 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: function (contextualModel, contextualCollection) { + lockNewContextualLinks: function lockNewContextualLinks(contextualModel, contextualCollection) { if (!this.get('isViewing')) { contextualModel.set('isLocked', true); } }, - - /** - * Automatically updates visibility of the view/edit mode toggle. - */ - updateVisibility: function () { + updateVisibility: function updateVisibility() { this.set('isVisible', this.get('contextualCount') > 0); } - }); - -})(Drupal, Backbone); +})(Drupal, Backbone); \ No newline at end of file