annotate core/modules/toolbar/js/models/ToolbarModel.es6.js @ 19:fa3358dc1485 tip

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