You are here

equalheights.module in Equal Heights jQuery 6

Same filename and directory in other branches
  1. 7.2 equalheights.module
  2. 7 equalheights.module

Adds a jQuery plugin that sets the elements you specify to the same height.

This module implements a jQuery plugin that can equalize the height of the user specified elements with the same class. By default, the height of the tallest element is used, but minimum and maximum height can also be set. The format for the admin settings should be 'classname:minheight,maxheight'. To find out more about the plugin, go to http://www.cssnewbie.com/equalheights-jquery-plugin/

File

equalheights.module
View source
<?php

/**
 * @file
 * Adds a jQuery plugin that sets the elements you specify to the same height.
 *
 * This module implements a jQuery plugin that can equalize the height of the
 * user specified elements with the same class.
 * By default, the height of the tallest element is used, but minimum and
 * maximum height can also be set.
 * The format for the admin settings should be 'classname:minheight,maxheight'.
 * To find out more about the plugin, go to
 * http://www.cssnewbie.com/equalheights-jquery-plugin/
 */

/**
* Implementation of hook_help().
*/
function equalheights_help($path = '', $arg = NULL) {
  $output = '';
  switch ($path) {
    case 'admin/help#equalheights':
    case 'admin/settings/equalheights':
      $output = '<p>' . t("Implements a jQuery plugin that makes the height of the elements equal.") . '</p>';
      break;
  }
  return $output;
}

// function equalheights_help

/**
 * Implementation of hook_init().
 */
function equalheights_init() {
  $equalheightsclasses = variable_get('equalheights_css_classes', '');
  if (!empty($equalheightsclasses)) {

    // Using \R to account for the new line delimiter on all systems
    $classes = preg_split("/\\R\\s*/", $equalheightsclasses);
    $jqueryequalheightsjs = drupal_get_path('module', 'equalheights') . '/jquery.equalheights.js';
    drupal_add_js($jqueryequalheightsjs, 'module');
    $js = "\$(document).ready(function(){";
    foreach ($classes as $class) {
      if (!empty($class)) {

        // Check if there's a ":" inside the setting string to avoid notices
        if (strpos($class, ':') !== false) {
          list($class, $height) = explode(":", $class);
        }

        // Set the overflow value
        $overflow_value = variable_get('equalheights_overflow', 'visible');
        $js .= "\$('{$class}').equalHeights({$height}).css('overflow', '{$overflow_value}');";
      }
    }
    $js .= "});";
    drupal_add_js($js, 'inline');
  }
}

// function equalheights_init

/**
 * Implementation of hook_menu().
 */
function equalheights_menu() {
  $items = array();
  $items['admin/settings/equalheights'] = array(
    'title' => 'Equal Heights',
    'description' => 'Configure elements with equal heights.',
    'access arguments' => array(
      'administer site configuration',
    ),
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'equalheights_admin',
    ),
    'file' => 'equalheights.admin.inc',
  );
  return $items;
}

// function equalheights_menu

Functions

Namesort descending Description
equalheights_help Implementation of hook_help().
equalheights_init Implementation of hook_init().
equalheights_menu Implementation of hook_menu().