You are here

function _simplemenu_add_js in SimpleMenu 7

Same name and namespace in other branches
  1. 6 simplemenu.module \_simplemenu_add_js()

\brief Add the JavaScript that makes it all work.

This function adds the Simplemenu JavaScript, the Superfish JavaScript and settings from the user.

1 call to _simplemenu_add_js()
simplemenu_init in ./simplemenu.module
Implements hook_init().

File

./simplemenu.module, line 210
Creates a simplemenu.

Code

function _simplemenu_add_js() {
  $simplemenu_path = drupal_get_path('module', 'simplemenu');

  // Settings
  $fix = variable_get('simplemenu_fix', 'scroll');
  switch ($fix) {
    case 'top':
      $element = 'body';
      $placement = 'prepend';
      break;
    case 'bottom':
      $element = 'body';
      $placement = 'append';
      break;
    default:

      // 'scroll'
      // let user defined other elements when not fixed
      $element = variable_get('simplemenu_element', 'body');
      $placement = variable_get('simplemenu_element_method', 'prepend');
      break;
  }
  $settings = array(
    'effect' => variable_get('simplemenu_effect', 'opacity'),
    'effectSpeed' => variable_get('simplemenu_effect_speed', 'fast'),
    'element' => $element,
    'placement' => $placement,
    'hideDelay' => variable_get('simplemenu_hide_delay', 800),
    'detectPopup' => variable_get('simplemenu_detect_popup', 1),
  );
  drupal_add_js(array(
    'simplemenu' => $settings,
  ), array(
    'type' => 'setting',
  ));

  // Simplemenu
  drupal_add_js($simplemenu_path . '/simplemenu.js', array(
    'version' => '1.2',
  ));

  // Superfish
  $superfish = variable_get('simplemenu_superfish_version', 'superfish-1.4.1.js');
  if ($superfish != 'custom') {
    $sf_version = str_replace(array(
      'superfish-',
      '.js',
    ), '', $superfish);
    drupal_add_js($simplemenu_path . '/' . $superfish, array(
      'version' => $sf_version,
    ));
  }
}