// Process the administrative toolbar.
$(context).find('#toolbar-administration').once('toolbar').each(function () {
// Establish the toolbar models and views.
- const model = Drupal.toolbar.models.toolbarModel = new Drupal.toolbar.ToolbarModel({
+ const model = new Drupal.toolbar.ToolbarModel({
locked: JSON.parse(localStorage.getItem('Drupal.toolbar.trayVerticalLocked')),
activeTab: document.getElementById(JSON.parse(localStorage.getItem('Drupal.toolbar.activeTabID'))),
height: $('#toolbar-administration').outerHeight(),
});
+ Drupal.toolbar.models.toolbarModel = model;
+
// Attach a listener to the configured media query breakpoints.
// Executes it before Drupal.toolbar.views to avoid extra rendering.
- for (const label in options.breakpoints) {
- if (options.breakpoints.hasOwnProperty(label)) {
- const mq = options.breakpoints[label];
- const mql = Drupal.toolbar.mql[label] = window.matchMedia(mq);
- // Curry the model and the label of the media query breakpoint to
- // the mediaQueryChangeHandler function.
- mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label));
- // Fire the mediaQueryChangeHandler for each configured breakpoint
- // so that they process once.
- Drupal.toolbar.mediaQueryChangeHandler.call(null, model, label, mql);
- }
- }
+ Object.keys(options.breakpoints).forEach((label) => {
+ const mq = options.breakpoints[label];
+ const mql = window.matchMedia(mq);
+ Drupal.toolbar.mql[label] = mql;
+ // Curry the model and the label of the media query breakpoint to
+ // the mediaQueryChangeHandler function.
+ mql.addListener(Drupal.toolbar.mediaQueryChangeHandler.bind(null, model, label));
+ // Fire the mediaQueryChangeHandler for each configured breakpoint
+ // so that they process once.
+ Drupal.toolbar.mediaQueryChangeHandler.call(null, model, label, mql);
+ });
Drupal.toolbar.views.toolbarVisualView = new Drupal.toolbar.ToolbarVisualView({
el: this,
model.trigger('change:activeTray', model, model.get('activeTray'));
// Render collapsible menus.
- const menuModel = Drupal.toolbar.models.menuModel = new Drupal.toolbar.MenuModel();
+ const menuModel = new Drupal.toolbar.MenuModel();
+ Drupal.toolbar.models.menuModel = menuModel;
Drupal.toolbar.views.menuVisualView = new Drupal.toolbar.MenuVisualView({
el: $(this).find('.toolbar-menu-administration').get(0),
model: menuModel,