3 * A Backbone Model for the state of a contextual link's trigger, list & region.
6 (function (Drupal, Backbone) {
8 * Models the state of a contextual link's trigger, list & region.
12 * @augments Backbone.Model
14 Drupal.contextual.StateModel = Backbone.Model.extend(/** @lends Drupal.contextual.StateModel# */{
19 * @prop {string} title
20 * @prop {bool} regionIsHovered
21 * @prop {bool} hasFocus
23 * @prop {bool} isLocked
25 defaults: /** @lends Drupal.contextual.StateModel# */{
28 * The title of the entity to which these contextual links apply.
35 * Represents if the contextual region is being hovered.
39 regionIsHovered: false,
42 * Represents if the contextual trigger or options have focus.
49 * Represents if the contextual options for an entity are available to
50 * be selected (i.e. whether the list of options is visible).
57 * When the model is locked, the trigger remains active.
65 * Opens or closes the contextual link.
67 * If it is opened, then also give focus.
69 * @return {Drupal.contextual.StateModel}
70 * The current contextual state model.
73 const newIsOpen = !this.get('isOpen');
74 this.set('isOpen', newIsOpen);
82 * Closes this contextual link.
84 * Does not call blur() because we want to allow a contextual link to have
85 * focus, yet be closed for example when hovering.
87 * @return {Drupal.contextual.StateModel}
88 * The current contextual state model.
91 this.set('isOpen', false);
96 * Gives focus to this contextual link.
98 * Also closes + removes focus from every other contextual link.
100 * @return {Drupal.contextual.StateModel}
101 * The current contextual state model.
104 this.set('hasFocus', true);
105 const cid = this.cid;
106 this.collection.each((model) => {
107 if (model.cid !== cid) {
108 model.close().blur();
115 * Removes focus from this contextual link, unless it is open.
117 * @return {Drupal.contextual.StateModel}
118 * The current contextual state model.
121 if (!this.get('isOpen')) {
122 this.set('hasFocus', false);
128 }(Drupal, Backbone));