You are here

stickynav.module in Sticky Navigation 7

Same filename and directory in other branches
  1. 8 stickynav.module
  2. 6 stickynav.module

Make a menu or some other element on the page stick on top when you scroll down

File

stickynav.module
View source
<?php

/**
 * @file
 * Make a menu or some other element on the page stick on top when you scroll
 * down
 */

/**
 * Implements hook_init().
 */
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');
  }
}

/**
 * Implements hook_permission().
 */
function stickynav_permission() {
  return array(
    'administer stickynav' => array(
      'title' => t('Administer Sticky Nav'),
      'description' => t('Permission to activate and manage Sticky Nav.'),
    ),
  );
}

/**
 * Implements hook_menu().
 */
function stickynav_menu() {
  $items['admin/config/user-interface/stickynav'] = array(
    'title' => 'Sticky Nav Settings',
    'description' => 'Settings of sticky navigation on your website',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'stickynav_admin_form',
    ),
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer stickynav',
    ),
    'file' => 'admin/stickynav.admin.inc',
  );
  return $items;
}

Functions

Namesort descending Description
stickynav_init Implements hook_init().
stickynav_menu Implements hook_menu().
stickynav_permission Implements hook_permission().