You are here

beautytips.module in BeautyTips 6.2

Same filename and directory in other branches
  1. 8 beautytips.module
  2. 6 beautytips.module
  3. 7.2 beautytips.module

Provides API for adding beautytips to pages. TODO: Add status about excanvas on status page.

File

beautytips.module
View source
<?php

/**
 * @file
 * Provides API for adding beautytips to pages.
 * TODO: Add status about excanvas on status page.
 */

/**
 * Implementation of hook_init().
 */
function beautytips_init() {
  if (variable_get('beautytips_always_add', 0)) {
    $options = array(
      '.beautytips' => array(
        'cssSelect' => '.beautytips',
        'trigger' => 'hover',
      ),
    );
    beautytips_add_beautytips($options);
  }
}

/**
 * Implementation of hook_menu().
 */
function beautytips_menu() {
  $items['admin/settings/beautytips'] = array(
    'title' => 'BeautyTips',
    'description' => 'Administer BeautyTips',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'beautytips_admin',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'beautytips.admin.inc',
  );
  $items['admin/settings/beautytips/settings'] = array(
    'title' => 'BeautyTips',
    'description' => 'Administer BeautyTips',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'beautytips_admin',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'beautytips.admin.inc',
    'type' => MENU_DEFAULT_LOCAL_TASK,
  );
  return $items;
}

/**
 * This is the API.  Call this function to add beautytips.
 *
 * @param array $options - See README.txt for details
 */
function beautytips_add_beautytips($options = NULL) {
  static $added = FALSE;
  static $hover_added = FALSE;
  $settings = array(
    'beautytips' => array(),
  );
  $js_added = drupal_add_js($data = NULL, 'setting');
  if (count($options)) {
    foreach ($options as $beautytip => $content) {

      // Ensure the js settings are not added more than once
      if (isset($js_added['setting']) && is_array($js_added['setting'])) {
        foreach ($js_added['setting'] as $setting) {
          if (isset($setting['beautytips']) && is_array($setting['beautytips'])) {
            if (array_key_exists($beautytip, $setting['beautytips'])) {
              unset($content);
            }
          }
        }
      }

      // Setup the settings array for adding js
      if (isset($content) && is_array($content)) {

        // Add hover intent js if specified
        if (isset($content['trigger'])) {
          if ($content['trigger'] == 'hover') {
            $content['hoverIntentOpts'] = array(
              'interval' => 0,
              'timeout' => 0,
            );
          }
          else {
            if ($content['trigger'] == 'hoverIntent' && !$hover_added) {
              $hover_added = TRUE;
              drupal_add_js(drupal_get_path('module', 'beautytips') . '/other_libs/jquery.hoverIntent.minified.js');
            }
          }
        }
        $style = isset($content['style']) ? $content['style'] : 'default';
        $settings['beautytips'][$beautytip] = array_merge(beautytips_get_style($style), $content);
        $keys_no_add = array(
          'cssSelect',
          'style',
          'list',
          'text',
          'preEval',
          'ajaxDisableLink',
          'animate',
        );
        foreach ($settings['beautytips'][$beautytip] as $key => $value) {
          if (!in_array($key, $keys_no_add)) {
            $settings['beautytips'][$beautytip]['list'][] = $key;
          }
        }
      }
    }
    if ($added && !empty($settings['beautytips'])) {
      drupal_add_js($settings, 'setting');
    }
  }

  // Add beautytips jQuery plugin
  if (!$added) {
    $path = drupal_get_path('module', 'beautytips');

    // Add excanvas for IE
    $expath = $path . '/other_libs/excanvas_r3';
    if (file_exists($expath . '/excanvas.compiled.js')) {
      drupal_add_js($expath . '/excanvas.compiled.js');
    }
    drupal_add_js($path . '/js/jquery.bt.min.js');
    drupal_add_js($path . '/js/beautytips.min.js');
    drupal_add_js($settings, 'setting');
    $added = TRUE;
  }
}

/**
 * Get all the defined beautytips styles
 */
function beautytips_get_styles($reload = FALSE) {
  $cache = cache_get('beautytips:beautytips-styles');
  if (!$cache || $reload) {
    $styles = module_invoke_all('define_beautytips_styles');

    // Save the beautytips style registry in the cache.
    cache_set('beautytips:beautytips-styles', $styles);
  }
  else {
    $styles = $cache->data;
  }
  return $styles;
}

/**
 * Get an array of options that defines a particular style
 */
function beautytips_get_style($style = 'default') {
  $styles = beautytips_get_styles();
  return isset($styles[$style]) ? $styles[$style] : array();
}

/**
 * Implementation of hook_define_beautytips_styles().
 *
 * @return $styles - an array of different styles
 */
function beautytips_define_beautytips_styles() {
  $styles['default'] = variable_get('beautytips_defaults', array());
  $styles['plain'] = array();
  $styles['netflix'] = array(
    'positions' => array(
      'right',
      'left',
    ),
    'fill' => '#FFF',
    'padding' => 5,
    'shadow' => TRUE,
    'shadowBlur' => 12,
    'strokeStyle' => '#B9090B',
    'spikeLength' => 50,
    'spikeGirth' => 60,
    'cornerRadius' => 10,
    'centerPointY' => 0.1,
    'overlap' => -8,
    'cssStyles' => array(
      'fontSize' => '12px',
      'fontFamily' => 'arial,helvetica,sans-serif',
    ),
  );
  $styles['facebook'] = array(
    'fill' => '#F7F7F7',
    'padding' => 8,
    'strokeStyle' => '#B7B7B7',
    'cornerRadius' => 0,
    'cssStyles' => array(
      'fontFamily' => '"lucida grande",tahoma,verdana,arial,sans-serif',
      'fontSize' => '11px',
    ),
  );
  $styles['transparent'] = array(
    'fill' => 'rgba(0, 0, 0, .8)',
    'padding' => 20,
    'strokeStyle' => '#CC0',
    'strokeWidth' => 3,
    'spikeLength' => 40,
    'spikeGirth' => 40,
    'cornerRadius' => 40,
    'cssStyles' => array(
      'color' => '#FFF',
      'fontWeight' => 'bold',
    ),
  );
  $styles['big-green'] = array(
    'fill' => '#00FF4E',
    'padding' => 20,
    'strokeWidth' => 0,
    'spikeLength' => 40,
    'spikeGirth' => 40,
    'cornerRadius' => 15,
    'cssStyles' => array(
      'fontFamily' => '"lucida grande",tahoma,verdana,arial,sans-serif',
      'fontSize' => '14px',
    ),
  );
  $styles['google-maps'] = array(
    'positions' => array(
      0 => 'top',
      1 => 'bottom',
    ),
    'fill' => '#FFF',
    'padding' => 15,
    'strokeStyle' => '#ABABAB',
    'strokeWidth' => 1,
    'spikeLength' => 65,
    'spikeGirth' => 40,
    'cornerRadius' => 25,
    'centerPointX' => 0.9,
    'cssStyles' => array(),
  );
  $styles['hulu'] = array(
    'fill' => '#F4F4F4',
    'strokeStyle' => '#666666',
    'spikeLength' => 20,
    'spikeGirth' => 10,
    'width' => 350,
    'overlap' => 0,
    'centerPointY' => 1,
    'cornerRadius' => 0,
    'cssStyles' => array(
      'fontFamily' => '"Lucida Grande",Helvetica,Arial,Verdana,sans-serif',
      'fontSize' => '12px',
      'padding' => '10px 14px',
    ),
    'shadow' => TRUE,
    'shadowColor' => 'rgba(0,0,0,.5)',
    'shadowBlur' => 8,
    'shadowOffsetX' => 4,
    'shadowOffsetY' => 4,
  );
  return $styles;
}

Functions

Namesort descending Description
beautytips_add_beautytips This is the API. Call this function to add beautytips.
beautytips_define_beautytips_styles Implementation of hook_define_beautytips_styles().
beautytips_get_style Get an array of options that defines a particular style
beautytips_get_styles Get all the defined beautytips styles
beautytips_init Implementation of hook_init().
beautytips_menu Implementation of hook_menu().