annotate core/modules/toolbar/js/models/ToolbarModel.es6.js @ 9:1fc0ff908d1f

Add another data file
author Chris Cannam
date Mon, 05 Feb 2018 12:34:32 +0000
parents 4c8ae668cc8c
children 129ea1e6d783
rev   line source
Chris@0 1 /**
Chris@0 2 * @file
Chris@0 3 * A Backbone Model for the toolbar.
Chris@0 4 */
Chris@0 5
Chris@0 6 (function (Backbone, Drupal) {
Chris@0 7 /**
Chris@0 8 * Backbone model for the toolbar.
Chris@0 9 *
Chris@0 10 * @constructor
Chris@0 11 *
Chris@0 12 * @augments Backbone.Model
Chris@0 13 */
Chris@0 14 Drupal.toolbar.ToolbarModel = Backbone.Model.extend(/** @lends Drupal.toolbar.ToolbarModel# */{
Chris@0 15
Chris@0 16 /**
Chris@0 17 * @type {object}
Chris@0 18 *
Chris@0 19 * @prop activeTab
Chris@0 20 * @prop activeTray
Chris@0 21 * @prop isOriented
Chris@0 22 * @prop isFixed
Chris@0 23 * @prop areSubtreesLoaded
Chris@0 24 * @prop isViewportOverflowConstrained
Chris@0 25 * @prop orientation
Chris@0 26 * @prop locked
Chris@0 27 * @prop isTrayToggleVisible
Chris@0 28 * @prop height
Chris@0 29 * @prop offsets
Chris@0 30 */
Chris@0 31 defaults: /** @lends Drupal.toolbar.ToolbarModel# */{
Chris@0 32
Chris@0 33 /**
Chris@0 34 * The active toolbar tab. All other tabs should be inactive under
Chris@0 35 * normal circumstances. It will remain active across page loads. The
Chris@0 36 * active item is stored as an ID selector e.g. '#toolbar-item--1'.
Chris@0 37 *
Chris@0 38 * @type {string}
Chris@0 39 */
Chris@0 40 activeTab: null,
Chris@0 41
Chris@0 42 /**
Chris@0 43 * Represents whether a tray is open or not. Stored as an ID selector e.g.
Chris@0 44 * '#toolbar-item--1-tray'.
Chris@0 45 *
Chris@0 46 * @type {string}
Chris@0 47 */
Chris@0 48 activeTray: null,
Chris@0 49
Chris@0 50 /**
Chris@0 51 * Indicates whether the toolbar is displayed in an oriented fashion,
Chris@0 52 * either horizontal or vertical.
Chris@0 53 *
Chris@0 54 * @type {bool}
Chris@0 55 */
Chris@0 56 isOriented: false,
Chris@0 57
Chris@0 58 /**
Chris@0 59 * Indicates whether the toolbar is positioned absolute (false) or fixed
Chris@0 60 * (true).
Chris@0 61 *
Chris@0 62 * @type {bool}
Chris@0 63 */
Chris@0 64 isFixed: false,
Chris@0 65
Chris@0 66 /**
Chris@0 67 * Menu subtrees are loaded through an AJAX request only when the Toolbar
Chris@0 68 * is set to a vertical orientation.
Chris@0 69 *
Chris@0 70 * @type {bool}
Chris@0 71 */
Chris@0 72 areSubtreesLoaded: false,
Chris@0 73
Chris@0 74 /**
Chris@0 75 * If the viewport overflow becomes constrained, isFixed must be true so
Chris@0 76 * that elements in the trays aren't lost off-screen and impossible to
Chris@0 77 * get to.
Chris@0 78 *
Chris@0 79 * @type {bool}
Chris@0 80 */
Chris@0 81 isViewportOverflowConstrained: false,
Chris@0 82
Chris@0 83 /**
Chris@0 84 * The orientation of the active tray.
Chris@0 85 *
Chris@0 86 * @type {string}
Chris@0 87 */
Chris@0 88 orientation: 'horizontal',
Chris@0 89
Chris@0 90 /**
Chris@0 91 * A tray is locked if a user toggled it to vertical. Otherwise a tray
Chris@0 92 * will switch between vertical and horizontal orientation based on the
Chris@0 93 * configured breakpoints. The locked state will be maintained across page
Chris@0 94 * loads.
Chris@0 95 *
Chris@0 96 * @type {bool}
Chris@0 97 */
Chris@0 98 locked: false,
Chris@0 99
Chris@0 100 /**
Chris@0 101 * Indicates whether the tray orientation toggle is visible.
Chris@0 102 *
Chris@0 103 * @type {bool}
Chris@0 104 */
Chris@0 105 isTrayToggleVisible: true,
Chris@0 106
Chris@0 107 /**
Chris@0 108 * The height of the toolbar.
Chris@0 109 *
Chris@0 110 * @type {number}
Chris@0 111 */
Chris@0 112 height: null,
Chris@0 113
Chris@0 114 /**
Chris@0 115 * The current viewport offsets determined by {@link Drupal.displace}. The
Chris@0 116 * offsets suggest how a module might position is components relative to
Chris@0 117 * the viewport.
Chris@0 118 *
Chris@0 119 * @type {object}
Chris@0 120 *
Chris@0 121 * @prop {number} top
Chris@0 122 * @prop {number} right
Chris@0 123 * @prop {number} bottom
Chris@0 124 * @prop {number} left
Chris@0 125 */
Chris@0 126 offsets: {
Chris@0 127 top: 0,
Chris@0 128 right: 0,
Chris@0 129 bottom: 0,
Chris@0 130 left: 0,
Chris@0 131 },
Chris@0 132 },
Chris@0 133
Chris@0 134 /**
Chris@0 135 * @inheritdoc
Chris@0 136 *
Chris@0 137 * @param {object} attributes
Chris@0 138 * Attributes for the toolbar.
Chris@0 139 * @param {object} options
Chris@0 140 * Options for the toolbar.
Chris@0 141 *
Chris@0 142 * @return {string|undefined}
Chris@0 143 * Returns an error message if validation failed.
Chris@0 144 */
Chris@0 145 validate(attributes, options) {
Chris@0 146 // Prevent the orientation being set to horizontal if it is locked, unless
Chris@0 147 // override has not been passed as an option.
Chris@0 148 if (attributes.orientation === 'horizontal' && this.get('locked') && !options.override) {
Chris@0 149 return Drupal.t('The toolbar cannot be set to a horizontal orientation when it is locked.');
Chris@0 150 }
Chris@0 151 },
Chris@0 152 });
Chris@0 153 }(Backbone, Drupal));