You are here

scroll_to_top.module in scroll to top 7.2

Provide scroll to top link.

File

scroll_to_top.module
View source
<?php

/**
 * @file
 * Provide scroll to top link.
 */

/**
 * Implementation of hook_init().
 */
function scroll_to_top_init() {
  global $theme;
  if (variable_get('scroll_to_top_enable_admin_theme', TRUE) == TRUE || variable_get('scroll_to_top_enable_admin_theme', TRUE) == FALSE && $theme != variable_get('admin_theme')) {
    drupal_add_css(drupal_get_path('module', 'scroll_to_top') . '/scroll_to_top.css', array(
      'group' => CSS_DEFAULT,
      'every_page' => TRUE,
    ));
    drupal_add_js(drupal_get_path('module', 'scroll_to_top') . '/scroll_to_top.js');
    drupal_add_js(array(
      'scroll_to_top' => array(
        'label' => t(check_plain(variable_get('scroll_to_top_label', 'Back to top'))),
      ),
    ), 'setting');

    //building the css style
    $position = "";

    // Button position
    if (variable_get('scroll_to_top_position', 1) == 1) {
      $position = "#back-top { right:40px; }";
    }
    if (variable_get('scroll_to_top_position', 1) == 3) {
      $position = "#back-top { left:50%;margin:0px;}";
    }

    // Display label
    if (variable_get('scroll_to_top_display_text', TRUE) == FALSE) {
      $display = "span#link {display : none;}";
    }
    else {
      $display = "";
    }

    // background color on hover
    $bgcolor = "#back-top span#button { background-color: " . variable_get('scroll_to_top_bg_color_out', '#CCCCCC') . ";}";
    $bgcolor .= " #back-top span#button:hover {opacity:1;filter:alpha(opacity = 1);background-color: " . variable_get('scroll_to_top_bg_color_hover', '#777777') . ";}";
    $css = $position;
    $css .= $bgcolor;
    $css .= $display;
    drupal_add_css($css, 'inline');
  }
}

/**
 * Implements hook_menu().
 */
function scroll_to_top_menu() {
  $items = array();
  $items['admin/config/user-interface/scrolltotop'] = array(
    'title' => 'Scroll to top',
    'description' => 'Scroll To Top settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'scroll_to_top_settings',
    ),
    'access arguments' => array(
      'administer scroll to top',
    ),
    'file' => 'scroll_to_top.admin.inc',
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}
function scroll_to_top_permission() {
  return array(
    'administer scroll to top' => array(
      'title' => t('Administer scroll to top'),
      'description' => t('Perform administration tasks for scroll to top.'),
    ),
  );
}

Functions