2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function (Drupal, Backbone) {
9 Drupal.contextualToolbar.StateModel = Backbone.Model.extend({
20 initialize: function initialize(attrs, options) {
21 this.listenTo(options.contextualCollection, 'reset remove add', this.countContextualLinks);
22 this.listenTo(options.contextualCollection, 'add', this.lockNewContextualLinks);
24 this.listenTo(this, 'change:contextualCount', this.updateVisibility);
26 this.listenTo(this, 'change:isViewing', function (model, isViewing) {
27 options.contextualCollection.each(function (contextualModel) {
28 contextualModel.set('isLocked', !isViewing);
32 countContextualLinks: function countContextualLinks(contextualModel, contextualCollection) {
33 this.set('contextualCount', contextualCollection.length);
35 lockNewContextualLinks: function lockNewContextualLinks(contextualModel, contextualCollection) {
36 if (!this.get('isViewing')) {
37 contextualModel.set('isLocked', true);
40 updateVisibility: function updateVisibility() {
41 this.set('isVisible', this.get('contextualCount') > 0);