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