Problem

I want to modify the default behavior of the Admin Toolbar. On every page load I want

  • the toolbar on the left / in vertical mode if using an admin theme (no matter what screen size)
  • the toolbar minimized if using a frontend theme

Already tried, didn't work

I have already tried numerous variants of CSS checking and DOM triggers like

if ($('body').hasClass('toolbar-vertical') {
  $('.toolbar-toggle-orientation button').trigger('click');
}

None of them works reliably because of timing problems due to asynchronous loading or pre-existing toolbar settings.

What I'm looking for

I'm looking for a reliable (not CSS class/not DOM trigger toggle) solution that does uses internal toolbar functions and variables, in order to avoid the problems mentioned above. I'm looking for something like my pseudecode below:

$(document).on('toolbar.loaded', function () {
  if (isAdminTheme) {
    Drupal.toolbar.setOrientationLeft();
  }
  else {
    Drupal.toolbar.minimizeToolbar();
  }
});

I'm using Admin toolbar module, but it seems the toolbar placement is handled only by the core toolbar module, so that shouldn't make any difference. I've found some related code in ToolbarVisualView.js, but I don't know how to access functions from there or hot to set those localStorage options.

PS: There also is an open bounty on StackExchange for a reliable solution to this problem.

Comments

hudri created an issue. See original summary.

hudri’s picture

Status: Active » Closed (outdated)