Problem/Motivation
Since 7.x-3.0-rc7 (and 7.x-3.x-dev, which has the same admin_menu.js), CTools modals often open far off to the right of the screen, so most of the dialog is outside the window. Opening the browser's developer tools, or resizing the window in any other way, puts the modal back in the center. It happens in Chrome and Firefox.
Cause: Drupal.behaviors.adminMenu.attach() runs for every Drupal.attachBehaviors() call, including the ones for content added after the page has loaded (AJAX responses, the content of a CTools modal). In that context there is no #admin-menu, so with client-side caching enabled (the default) the behavior fetches the menu again via Drupal.admin.getCache(). When the request returns it calls $(window).triggerHandler('resize'). CTools binds modalContentResize() to the window's resize event; it measures #modalContent at that moment, while the modal's content is still being swapped in (around 50px wide in our case), and sets left to roughly half the window width. The full-size modal then extends past the right edge until the next real resize.
In 7.x-3.0-rc6, Drupal.admin.getCache() kept the result in Drupal.admin.hashes and returned early on later calls, so the menu was fetched once per page and the resize was triggered once. rc7 dropped that, so every later attach repeats the fetch and the resize. The fetched menu also has nowhere to go in such a context: $('body', context) is empty inside AJAX content.
Steps to reproduce
- Drupal 7 with admin_menu 7.x-3.0-rc7 or 7.x-3.x-dev, "Cache menu in client-side browser" enabled (the default), CTools and Panels (or any module that opens CTools modals).
- Edit a Panels display, e.g. a node's Panelizer content at
node/N/panel_content. - Click a region's gear and choose Style > Change.
- The modal opens with its left edge near the middle of the window and runs off-screen to the right. Resize the window and it is centered.
(The menu is only fetched by JavaScript when the browser has the has_js cookie, see #3271566, so whether a site shows the problem can vary.)
Proposed resolution
In Drupal.behaviors.adminMenu.attach(), return early when the context is not the document and does not contain the menu: there is nothing to attach to and nowhere to put a fetched menu, and the resize is not needed. The first attach on page load (context = document) is unchanged, so the menu still loads and attaches as before.
Patch attached (against 7.x-3.x-dev; applies to 7.x-3.0-rc7 too). Tested in Chromium and Firefox: Panels' Style > Change modal opens centered on the first and later opens, the admin menu loads once per page, submenus still open on hover, no JavaScript errors.
Remaining tasks
Review.
User interface changes
None (CTools modals are positioned correctly again).
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| admin_menu-modal-off-screen-refetch.patch | 848 bytes | philsward |
Comments