You are here

function smartmenus_block_view in Smartmenus.js 7

Implements hook_block_view().

File

./smartmenus.module, line 126
Integration with the Smartmenus jQuery plugin for responsive menus.

Code

function smartmenus_block_view($delta = '') {
  $block = array();

  // Load the menu and all it's data.
  $smartmenu = explode(':', variable_get('smartmenus_menu_' . $delta, 'main-menu:0'));
  $menu = menu_tree_all_data($smartmenu[0]);

  // Allow i18n module to translate strings where available.
  if (module_exists('i18n_menu')) {
    $menu = i18n_menu_localize_tree($menu);
  }
  $id = drupal_clean_css_identifier($delta);

  // Return a renderable array.
  $block['content'] = array(
    '#theme' => 'smartmenus_menu',
    '#tree' => $menu,
    '#toggle' => variable_get('smartmenus_toggle_' . $delta, TRUE),
    '#attributes' => array(
      'id' => $id,
      'class' => array(
        'sm',
      ),
    ),
    '#attached' => array(
      'css' => array(
        // Adjust the smartmenus to fall below contextual links.
        array(
          'data' => '.sm { z-index: 998; }',
          'type' => 'inline',
          'weight' => 1000,
        ),
      ),
      'js' => array(
        // Activate the menu.
        drupal_get_path('module', 'smartmenus') . '/js/smartmenus.js' => array(
          'type' => 'file',
        ),
      ),
      // Add the library.
      'libraries_load' => array(
        array(
          'smartmenus',
        ),
      ),
    ),
  );

  // Add theme class.
  $smtheme = variable_get('smartmenus_theme', FALSE);
  if ($smtheme && $smtheme !== '') {
    $path = libraries_get_path('smartmenus');
    $block['content']['#attached']['css'][$path . '/css/' . $smtheme . '/' . $smtheme . '.css'] = array(
      'type' => 'file',
    );
    $block['content']['#attributes']['class'][] = $smtheme;
  }

  // Add CSS for the menu toggle button.
  if (variable_get('smartmenus_toggle_' . $delta, TRUE)) {
    $path = drupal_get_path('module', 'smartmenus');
    $block['content']['#attached']['css'][$path . '/css/sm-menu-toggle.css'] = array(
      'type' => 'file',
    );
  }

  // Add orientaton class.
  if (variable_get('smartmenus_orient_' . $delta, 'horrizontal') === 'vertical') {
    $block['content']['#attributes']['class'][] = 'sm-vertical';
  }
  return $block;
}