3 * A Backbone Model for the state of a contextual link's trigger, list & region.
6 (function (Drupal, Backbone) {
11 * Models the state of a contextual link's trigger, list & region.
15 * @augments Backbone.Model
17 Drupal.contextual.StateModel = Backbone.Model.extend(/** @lends Drupal.contextual.StateModel# */{
22 * @prop {string} title
23 * @prop {bool} regionIsHovered
24 * @prop {bool} hasFocus
26 * @prop {bool} isLocked
28 defaults: /** @lends Drupal.contextual.StateModel# */{
31 * The title of the entity to which these contextual links apply.
38 * Represents if the contextual region is being hovered.
42 regionIsHovered: false,
45 * Represents if the contextual trigger or options have focus.
52 * Represents if the contextual options for an entity are available to
53 * be selected (i.e. whether the list of options is visible).
60 * When the model is locked, the trigger remains active.
68 * Opens or closes the contextual link.
70 * If it is opened, then also give focus.
72 * @return {Drupal.contextual.StateModel}
73 * The current contextual state model.
75 toggleOpen: function () {
76 var newIsOpen = !this.get('isOpen');
77 this.set('isOpen', newIsOpen);
85 * Closes this contextual link.
87 * Does not call blur() because we want to allow a contextual link to have
88 * focus, yet be closed for example when hovering.
90 * @return {Drupal.contextual.StateModel}
91 * The current contextual state model.
94 this.set('isOpen', false);
99 * Gives focus to this contextual link.
101 * Also closes + removes focus from every other contextual link.
103 * @return {Drupal.contextual.StateModel}
104 * The current contextual state model.
107 this.set('hasFocus', true);
109 this.collection.each(function (model) {
110 if (model.cid !== cid) {
111 model.close().blur();
118 * Removes focus from this contextual link, unless it is open.
120 * @return {Drupal.contextual.StateModel}
121 * The current contextual state model.
124 if (!this.get('isOpen')) {
125 this.set('hasFocus', false);
132 })(Drupal, Backbone);