Loading core/modules/navigation/js/admin-toolbar-wrapper.js +66 −80 Original line number Diff line number Diff line Loading @@ -28,19 +28,9 @@ */ const SIDEBAR_CONTENT_EVENT = 'toggle-admin-toolbar-content'; Drupal.behaviors.navigationProcessHtmlListener = { /** * Attaches the behavior to the context element. * * @param {HTMLElement} context The context element to attach the behavior to. */ attach: (context) => { if (context === document) { if ( once( 'admin-toolbar-document-triggers-listener', document.documentElement, ).length once('admin-toolbar-document-triggers-listener', document.documentElement) .length ) { const doc = document.documentElement; Loading @@ -48,7 +38,7 @@ // with animations and avoid layout shift. setTimeout(() => { doc.setAttribute('data-admin-toolbar-transitions', true); }, 200); }, 100); doc.addEventListener(HTML_TRIGGER_EVENT, (e) => { // Prevents multiple triggering while transitioning. Loading Loading @@ -103,17 +93,13 @@ const displaceElement = doc .querySelector('.admin-toolbar') ?.querySelector('.admin-toolbar__displace-placeholder'); const edge = document.documentElement.dir === 'rtl' ? 'right' : 'left'; const edge = document.documentElement.dir === 'rtl' ? 'right' : 'left'; displaceElement?.setAttribute(`data-offset-${edge}`, ''); Drupal.displace(true); }; initDisplace(); } } }, }; // Any triggers on page. Inside or outside sidebar. // For now button in sidebar + mobile header and background. Loading Loading @@ -146,7 +132,7 @@ localStorage.setItem('Drupal.navigation.sidebarExpanded', toState); }; if (context === document) { if (triggers.length) { let firstState = localStorage.getItem('Drupal.navigation.sidebarExpanded') !== 'false'; Loading core/modules/navigation/tests/src/Nightwatch/Tests/expandCollapseTest.js +4 −1 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ const selectors = { expanded: '[data-admin-toolbar="expanded"]', collapsed: '[data-admin-toolbar="collapsed"]', }, clearCacheButton: 'input[data-drupal-selector="edit-clear"]', }; module.exports = { Loading @@ -15,6 +16,7 @@ module.exports = { browser .drupalInstall() .drupalInstallModule('navigation', true) .drupalInstallModule('big_pipe') .setWindowSize(1220, 800); }, after(browser) { Loading @@ -24,7 +26,8 @@ module.exports = { 'Expand/Collapse': (browser) => { browser.drupalLoginAsAdmin(() => { browser .drupalRelativeURL('/') .drupalRelativeURL('/admin/config/development/performance') .click(selectors.clearCacheButton) .waitForElementPresent( '[data-once="admin-toolbar-document-triggers-listener"]', ) Loading Loading
core/modules/navigation/js/admin-toolbar-wrapper.js +66 −80 Original line number Diff line number Diff line Loading @@ -28,19 +28,9 @@ */ const SIDEBAR_CONTENT_EVENT = 'toggle-admin-toolbar-content'; Drupal.behaviors.navigationProcessHtmlListener = { /** * Attaches the behavior to the context element. * * @param {HTMLElement} context The context element to attach the behavior to. */ attach: (context) => { if (context === document) { if ( once( 'admin-toolbar-document-triggers-listener', document.documentElement, ).length once('admin-toolbar-document-triggers-listener', document.documentElement) .length ) { const doc = document.documentElement; Loading @@ -48,7 +38,7 @@ // with animations and avoid layout shift. setTimeout(() => { doc.setAttribute('data-admin-toolbar-transitions', true); }, 200); }, 100); doc.addEventListener(HTML_TRIGGER_EVENT, (e) => { // Prevents multiple triggering while transitioning. Loading Loading @@ -103,17 +93,13 @@ const displaceElement = doc .querySelector('.admin-toolbar') ?.querySelector('.admin-toolbar__displace-placeholder'); const edge = document.documentElement.dir === 'rtl' ? 'right' : 'left'; const edge = document.documentElement.dir === 'rtl' ? 'right' : 'left'; displaceElement?.setAttribute(`data-offset-${edge}`, ''); Drupal.displace(true); }; initDisplace(); } } }, }; // Any triggers on page. Inside or outside sidebar. // For now button in sidebar + mobile header and background. Loading Loading @@ -146,7 +132,7 @@ localStorage.setItem('Drupal.navigation.sidebarExpanded', toState); }; if (context === document) { if (triggers.length) { let firstState = localStorage.getItem('Drupal.navigation.sidebarExpanded') !== 'false'; Loading
core/modules/navigation/tests/src/Nightwatch/Tests/expandCollapseTest.js +4 −1 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ const selectors = { expanded: '[data-admin-toolbar="expanded"]', collapsed: '[data-admin-toolbar="collapsed"]', }, clearCacheButton: 'input[data-drupal-selector="edit-clear"]', }; module.exports = { Loading @@ -15,6 +16,7 @@ module.exports = { browser .drupalInstall() .drupalInstallModule('navigation', true) .drupalInstallModule('big_pipe') .setWindowSize(1220, 800); }, after(browser) { Loading @@ -24,7 +26,8 @@ module.exports = { 'Expand/Collapse': (browser) => { browser.drupalLoginAsAdmin(() => { browser .drupalRelativeURL('/') .drupalRelativeURL('/admin/config/development/performance') .click(selectors.clearCacheButton) .waitForElementPresent( '[data-once="admin-toolbar-document-triggers-listener"]', ) Loading