You are here

function menu_minipanels_init in Menu Minipanels 6

Implements hook_init().

File

./menu_minipanels.module, line 28
Allows an administrator to specify a minipanel to be associated with a Drupal menu item. When that menu item is hovered or clicked (as per config), the minipanel content will be shown using the qTip javascript library.

Code

function menu_minipanels_init() {

  // Optionally ignore certain pages.
  if (menu_minipanels_excluded_path()) {
    return;
  }

  // The main qTip script file should be stored in sites/all/libraries/qtip.
  $qtip_path = menu_minipanels_get_qtip_path();

  // If the qTip script isn't found, no point in continuing.
  if ($qtip_path === FALSE) {
    return;
  }

  // Load each of the menus that are configured for menu_minipanels. This
  // happens during hook_init() due to needing to work around the execution
  // path of Drupal 6.
  $load_requirements = FALSE;
  $enabled_menus = array();
  foreach (menu_get_names() as $menu) {
    if (variable_get('menu_minipanels_' . $menu . '_enabled', FALSE)) {
      $enabled_menus[] = $menu;

      // Loop through each level of the menu tree and see whether qTip needs to
      // be loaded.
      $level = 0;
      while ($items = menu_navigation_links($menu, $level)) {
        if (menu_minipanels_prepare_links($items)) {
          $load_requirements = TRUE;
        }
        $level++;
      }
    }
  }

  // If the main menu is enabled and the main & secondary menus both point to
  // the same menu, load the second level of that menu.
  $primary_menu = variable_get('menu_primary_links_source', 'primary-links');
  $secondary_menu = variable_get('menu_secondary_links_source', 'secondary-links');
  if (in_array($primary_menu, $enabled_menus) && $primary_menu == $secondary_menu) {
    if (menu_minipanels_prepare_links(menu_navigation_links($primary_menu, 1))) {
      $load_requirements = TRUE;
    }
  }

  // If menus are actually needed, load the required scripts & CSS.
  if ($load_requirements) {

    // The path to this module.
    $path = drupal_get_path('module', 'menu_minipanels');

    // Load the module's custom CSS.
    drupal_add_css($path . '/css/menu_minipanels.css');

    // This module's custom JS.
    drupal_add_js($path . '/js/menu_minipanels.js');

    // Optional callbacks.
    if (variable_get('menu_minipanels_default_callbacks', TRUE)) {
      drupal_add_js($path . '/js/menu_minipanels.callbacks.js');
    }

    // Load the qTip script.
    drupal_add_js($qtip_path);
  }
}