diff --git a/js/navbar.js b/js/navbar.js index b9cef4a..0a63f6d 100644 --- a/js/navbar.js +++ b/js/navbar.js @@ -17,7 +17,15 @@ */ Drupal.behaviors.navbar = { - attach: function (context) { + attach: function(context, settings) { + // Initialize settings. + settings.navbar = $.extend({ + suppress: false, + }, settings.navbar || {}); + // Check whether navbar should be suppressed. + if (settings.navbar.suppress) { + return; + } // Verify that the user agent understands media queries. Complex admin // navbar layouts require media query support. if (!window.matchMedia('only screen').matches) { diff --git a/navbar.module b/navbar.module index fba7486..448f4a7 100644 --- a/navbar.module +++ b/navbar.module @@ -190,6 +190,9 @@ function _navbar_initialize_page_cache() { * Add admin navbar to the page_top region automatically. */ function navbar_page_build(&$page) { + if (navbar_suppress(FALSE)) { + return; + } $page['page_top']['navbar'] = array( '#type' => 'navbar', '#access' => user_access('access navbar'), @@ -961,3 +964,26 @@ function navbar_convert_libraries_to_library($library, $options) { return $converted; } + +/** + * Implementation of hook_suppress() + * + * Allows other modules to suppress display of Navbar + * + * This function should be called from within another module's page callback + * (preferably using module_invoke()) when the menu should not be displayed. + * This is useful for modules that implement popup pages or other special + * pages where the chat would be distracting or break the layout. + * + * @param $set + * Defaults to TRUE. If called before hook_footer(), the navbar will not be + * displayed. If FALSE is passed, the suppression state is returned. + **/ +function navbar_suppress($set = TRUE) { + static $suppress = FALSE; + if (!empty($set) && $suppress === FALSE) { + $suppress = TRUE; + drupal_add_js(array('navbar' => array('suppress' => 1)), 'setting'); + } + return $suppress; +}