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