123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- /**
- * @file
- * A Backbone Model for the toolbar.
- */
- (function (Backbone, Drupal) {
- /**
- * Backbone model for the toolbar.
- *
- * @constructor
- *
- * @augments Backbone.Model
- */
- Drupal.toolbar.ToolbarModel = Backbone.Model.extend(/** @lends Drupal.toolbar.ToolbarModel# */{
- /**
- * @type {object}
- *
- * @prop activeTab
- * @prop activeTray
- * @prop isOriented
- * @prop isFixed
- * @prop areSubtreesLoaded
- * @prop isViewportOverflowConstrained
- * @prop orientation
- * @prop locked
- * @prop isTrayToggleVisible
- * @prop height
- * @prop offsets
- */
- defaults: /** @lends Drupal.toolbar.ToolbarModel# */{
- /**
- * The active toolbar tab. All other tabs should be inactive under
- * normal circumstances. It will remain active across page loads. The
- * active item is stored as an ID selector e.g. '#toolbar-item--1'.
- *
- * @type {string}
- */
- activeTab: null,
- /**
- * Represents whether a tray is open or not. Stored as an ID selector e.g.
- * '#toolbar-item--1-tray'.
- *
- * @type {string}
- */
- activeTray: null,
- /**
- * Indicates whether the toolbar is displayed in an oriented fashion,
- * either horizontal or vertical.
- *
- * @type {bool}
- */
- isOriented: false,
- /**
- * Indicates whether the toolbar is positioned absolute (false) or fixed
- * (true).
- *
- * @type {bool}
- */
- isFixed: false,
- /**
- * Menu subtrees are loaded through an AJAX request only when the Toolbar
- * is set to a vertical orientation.
- *
- * @type {bool}
- */
- areSubtreesLoaded: false,
- /**
- * If the viewport overflow becomes constrained, isFixed must be true so
- * that elements in the trays aren't lost off-screen and impossible to
- * get to.
- *
- * @type {bool}
- */
- isViewportOverflowConstrained: false,
- /**
- * The orientation of the active tray.
- *
- * @type {string}
- */
- orientation: 'horizontal',
- /**
- * A tray is locked if a user toggled it to vertical. Otherwise a tray
- * will switch between vertical and horizontal orientation based on the
- * configured breakpoints. The locked state will be maintained across page
- * loads.
- *
- * @type {bool}
- */
- locked: false,
- /**
- * Indicates whether the tray orientation toggle is visible.
- *
- * @type {bool}
- */
- isTrayToggleVisible: true,
- /**
- * The height of the toolbar.
- *
- * @type {number}
- */
- height: null,
- /**
- * The current viewport offsets determined by {@link Drupal.displace}. The
- * offsets suggest how a module might position is components relative to
- * the viewport.
- *
- * @type {object}
- *
- * @prop {number} top
- * @prop {number} right
- * @prop {number} bottom
- * @prop {number} left
- */
- offsets: {
- top: 0,
- right: 0,
- bottom: 0,
- left: 0,
- },
- },
- /**
- * @inheritdoc
- *
- * @param {object} attributes
- * Attributes for the toolbar.
- * @param {object} options
- * Options for the toolbar.
- *
- * @return {string|undefined}
- * Returns an error message if validation failed.
- */
- validate(attributes, options) {
- // Prevent the orientation being set to horizontal if it is locked, unless
- // override has not been passed as an option.
- if (attributes.orientation === 'horizontal' && this.get('locked') && !options.override) {
- return Drupal.t('The toolbar cannot be set to a horizontal orientation when it is locked.');
- }
- },
- });
- }(Backbone, Drupal));
|