X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ftoolbar%2Fjs%2Fmodels%2FToolbarModel.es6.js;fp=web%2Fcore%2Fmodules%2Ftoolbar%2Fjs%2Fmodels%2FToolbarModel.es6.js;h=90c69d0bd0ad2e40d0c086e825eb88045d8dc4a6;hp=0000000000000000000000000000000000000000;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hpb=aea91e65e895364e460983b890e295aa5d5540a5 diff --git a/web/core/modules/toolbar/js/models/ToolbarModel.es6.js b/web/core/modules/toolbar/js/models/ToolbarModel.es6.js new file mode 100644 index 000000000..90c69d0bd --- /dev/null +++ b/web/core/modules/toolbar/js/models/ToolbarModel.es6.js @@ -0,0 +1,153 @@ +/** + * @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));