diff --git a/core/modules/contextual/js/models/Model.js b/core/modules/contextual/js/models/Model.js new file mode 100644 index 0000000..4232051 --- /dev/null +++ b/core/modules/contextual/js/models/Model.js @@ -0,0 +1,33 @@ +/** + * @file + * Attaches behaviors for the Contextual module's edit toolbar tab. + */ + +(function (Drupal, Backbone) { + +"use strict"; + +/** + * Models the state of the edit mode toggle. + */ +Drupal.contextualToolbar.Model = Backbone.Model.extend({ + defaults: { + // Indicates whether the toggle is currently in "view" or "edit" mode. + isViewing: true, + // Indicates whether the toggle should be visible or hidden. Automatically + // calculated, depends on contextualCount. + isVisible: false, + // Tracks how many contextual links exist on the page. + contextualCount: 0, + // A TabbingContext object as returned by Drupal.TabbingManager: the set + // of tabbable elements when edit mode is enabled. + tabbingContext: null + }, + initialize: function () { + this.on('change:contextualCount', function (model) { + model.set('isVisible', model.get('contextualCount') > 0); + }); + } +}); + +})(Drupal, Backbone);