/** * @file * A Backbone Model for the toolbar. */ (function (Backbone, Drupal) { "use strict"; /** * Backbone model for the toolbar. */ Drupal.toolbar.ToolbarModel = Backbone.Model.extend({ defaults: { // 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'. activeTab: null, // Represents whether a tray is open or not. Stored as an ID selector e.g. // '#toolbar-item--1-tray'. activeTray: null, // Indicates whether the toolbar is displayed in an oriented fashion, // either horizontal or vertical. isOriented: false, // Indicates whether the toolbar is positioned absolute (false) or fixed // (true). isFixed: false, // Menu subtrees are loaded through an AJAX request only when the Toolbar // is set to a vertical orientation. 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. isViewportOverflowConstrained: false, // The orientation of the active tray. orientation: 'vertical', // 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. locked: false, // Indicates whether the tray orientation toggle is visible. isTrayToggleVisible: false, // The height of the toolbar. height: null, // The current viewport offsets determined by Drupal.displace(). The // offsets suggest how a module might position is components relative to // the viewport. offsets: { top: 0, right: 0, bottom: 0, left: 0 } }, /** * {@inheritdoc} */ validate: function (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));