You are here

function mobile_navigation_page_build in Mobile Navigation 7.2

Same name and namespace in other branches
  1. 8 mobile_navigation.module \mobile_navigation_page_build()
  2. 7 mobile_navigation.module \mobile_navigation_page_build()

Implements hook_page_build().

File

./mobile_navigation.module, line 128
Mobile Navigation primary module file.

Code

function mobile_navigation_page_build(&$page) {
  global $theme_key;
  $current_theme = variable_get('theme_default', 'none');
  if ($current_theme == $theme_key) {
    drupal_add_js(drupal_get_path('module', 'mobile_navigation') . '/js/mobile_menu.js', array(
      'preprocess' => FALSE,
    ));
    drupal_add_js(drupal_get_path('module', 'mobile_navigation') . '/mobile_navigation.js', array(
      'preprocess' => FALSE,
    ));
    drupal_add_css(drupal_get_path('module', 'mobile_navigation') . '/mobile_navigation.css');
    drupal_add_library('system', 'effects.slide');
    $configurations = db_query('SELECT * FROM {mobile_navigation_configurations}');
    $mobile_navigation_configurations = array();
    $markup = array();
    $id = "";
    foreach ($configurations as $conf) {
      $menu_name = $conf->menu;
      $display_id = $conf->display;
      $display_name = get_display_name_from_id($display_id);

      // Render Menu
      $menu_tree = menu_tree_output(menu_tree_all_data($menu_name));
      $menu_tree['#cache'] = array(
        'cid' => 'mobile_navigation_' . $menu_name,
        'bin' => 'cache',
      );
      $menu = drupal_render($menu_tree);
      $id = $menu_name . '_' . $display_name;
      $markup[$id] = array(
        '#type' => 'markup',
        '#markup' => $menu,
        '#prefix' => '<div id="' . $id . '" class="mobile-navigation-menu">',
        '#suffix' => '</div>',
      );
      if ($conf->use_button) {
        $button_container = '#block-mobile-navigation-' . $menu_name . '-' . $display_name . ' .mobile-navigation-button-container';
      }
      else {
        $button_container = '';
      }

      // To be Added to Drupal JS settings
      $mobile_navigation_configurations[$id] = array(
        'menu' => $menu_name,
        'menu_selector' => $conf->menu_selector,
        'display' => $display_name,
        'plugin' => $conf->plugin,
        'show_items_policy' => $conf->show_items_policy,
        'expand_only_active_trail' => $conf->expand_only_active_trail,
        'show_hide_effect' => $conf->show_hide_effect,
        'collapse_by_default' => $conf->collapse_by_default,
        'menu_width' => $conf->menu_width,
        'use_button' => $conf->use_button,
        'button_title' => $conf->button_title,
        'use_handler' => $conf->use_handler,
        'handler_title' => $conf->handler_title,
        'use_mask' => $conf->use_mask,
        'use_classes' => $conf->use_classes,
        'button_container' => $button_container,
      );
    }

    // Wrap menus on a container
    $container[$id . "-container"] = array(
      '#type' => 'markup',
      '#markup' => drupal_render($markup),
      '#prefix' => '<div id="mobile-navigation-menus">',
      '#suffix' => '</div>',
    );

    // Place it on the page_bottom region
    $page['page_bottom']['mobile_navigation'] = array(
      '#markup' => drupal_render($container),
      '#weight' => 25,
    );

    // Add displays definitions to Drupal JS settings
    $displays = get_displays_list();
    $display_list = array();
    $first = true;
    foreach ($displays as $display) {
      if (!($mq = $display->media_query)) {
        $bottom = $display->bottom;
        $top = $display->top;
        if ($bottom and $top) {
          $mq = 'all and (min-width:' . $bottom . 'px) and (max-width:' . $top . 'px)';
        }
        else {
          if ($bottom) {
            $mq = 'all and (min-width:' . $bottom . 'px)';
          }
          else {
            if ($top) {
              $mq = 'all and (max-width:' . $top . 'px)';
            }
          }
        }
      }
      $display_list[$display->name] = $mq;
    }

    /*
    $display_list = array(
    	
    	"mobile" => "all and (min-width:0px) and (max-width:419px)",
    	"menu" => "all and (min-width:420px) and (max-width:959px)",
    	"normal" => "all and (min-width:960px)",
    );
    */

    // Add configurations and displays to Drupal JS settings
    drupal_add_js(array(
      'mobile_navigation' => array(
        'displays' => $display_list,
        'configurations' => $mobile_navigation_configurations,
        'module_path' => drupal_get_path('module', 'mobile_navigation'),
      ),
    ), 'setting');
  }
}