You are here

function stickynav_init in Sticky Navigation 7

Same name and namespace in other branches
  1. 6 stickynav.module \stickynav_init()

Implements hook_init().

File

./stickynav.module, line 11
Make a menu or some other element on the page stick on top when you scroll down

Code

function stickynav_init() {
  global $user, $theme;

  // Check if user has an exclusion role.
  $excluded_roles = array_filter(variable_get('stickynav-roles-' . $theme, array()));
  if (array_intersect_key($excluded_roles, $user->roles)) {
    return;
  }
  $selector = variable_get('stickynav-selector-' . $theme, '');
  $offset_selector = variable_get('stickynav-offset-selector-' . $theme, '');
  $custom_offset = variable_get('stickynav-custom-offset-' . $theme, '');

  // Will only add the sticky nav assets if the theme and selector are set.
  if (variable_get('stickynav-enabled-' . $theme, FALSE) && trim($selector)) {
    drupal_add_css(drupal_get_path('module', 'stickynav') . '/css/stickynav.css');
    drupal_add_js(drupal_get_path('module', 'stickynav') . '/js/stickynav.js');
    $settings = array(
      'stickynav' => array(
        'selector' => check_plain($selector),
        'offsets' => array(
          'selector' => check_plain($offset_selector),
          'custom_offset' => check_plain($custom_offset),
        ),
      ),
    );
    drupal_add_js($settings, 'setting');
  }
}