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