You are here

tipsy.module in Tipsy 7

Same filename and directory in other branches
  1. 8 tipsy.module

File

tipsy.module
View source
<?php

/**
 * Implements hook_page_build().
 */
function tipsy_page_build(&$page) {
  drupal_add_library('tipsy', 'tipsy', TRUE);
}

/**
 * Implements hook_library().
 */
function tipsy_library() {
  $module_path = drupal_get_path('module', 'tipsy');
  $libraries = array();
  $libraries['tipsy'] = array(
    'title' => 'Tipsy',
    'website' => 'http://onehackoranother.com/projects/jquery/tipsy/',
    'version' => '0.1.7',
    'js' => array(
      $module_path . '/javascripts/jquery.tipsy.js' => array(),
      $module_path . '/javascripts/tipsy.js' => array(),
    ),
    'css' => array(
      $module_path . '/stylesheets/tipsy.css' => array(
        'type' => 'file',
      ),
    ),
  );
  $settings = _tipsy_get_settings();
  if ($settings['drupal_forms']['forms'] == 0) {
    unset($settings['drupal_forms']);
  }
  drupal_add_js(array(
    'tipsy' => $settings,
  ), 'setting');
  return $libraries;
}

/**
 * Implements hook_menu().
 */
function tipsy_menu() {
  $items = array();
  $items['admin/config/user-interface/tipsy'] = array(
    'title' => 'Tipsy',
    'description' => 'Integrates tipsy tooltips with Drupal',
    'page callback' => 'drupal_get_form',
    'access callback' => 'user_access',
    'access arguments' => array(
      'administer tipsy',
    ),
    'page arguments' => array(
      'tipsy_admin',
    ),
    'file' => 'tipsy.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_perm().
 */
function tipsy_permission() {
  $permissions = array();
  $permissions['administer tipsy'] = array(
    'title' => t('Administer tipsy'),
    'description' => t('Allows users to configure tipsy.'),
  );
  return $permissions;
}

/**
 * Implements hook_theme().
 */
function tipsy_theme() {
  return array(
    'tipsy_custom_selectors_form' => array(
      'render element' => 'form',
      'file' => 'tipsy.admin.inc',
    ),
  );
}

/**
 * Helper function to retrieve all settings for tipsy.
 */
function _tipsy_get_settings($new_rule = FALSE) {
  if ($new_rule == TRUE) {
    $settings = array(
      'selector' => '',
      'options' => array(
        'fade' => 1,
        'gravity' => 'w',
        'delayIn' => 0,
        'delayOut' => 0,
        'trigger' => 'hover',
        'opacity' => '0.8',
        'offset' => 0,
        'html' => 0,
        'tooltip_content' => array(
          'source' => 'attribute',
          'selector' => 'title',
        ),
      ),
    );
  }
  else {
    $wide_settings = array(
      'drupal_forms' => array(
        'forms' => FALSE,
        'options' => array(
          'fade' => 1,
          'gravity' => 'autoWE',
          'delayIn' => 0,
          'delayOut' => 0,
          'trigger' => 'focus',
          'opacity' => '0.8',
          'offset' => 0,
        ),
      ),
      'custom_selectors' => array(
        0 => array(
          'selector' => '.tipsy',
          'options' => array(
            'fade' => 1,
            'gravity' => 'w',
            'delayIn' => 0,
            'delayOut' => 0,
            'trigger' => 'hover',
            'opacity' => '0.8',
            'offset' => 0,
            'html' => 0,
            'tooltip_content' => array(
              'source' => 'attribute',
              'selector' => 'title',
            ),
          ),
        ),
      ),
    );
    $settings = variable_get('tipsy', $wide_settings);

    // Convert settings for tipsy older than 7.x-1.0-beta2.
    $converted_settings = FALSE;
    foreach ($settings['custom_selectors'] as &$selector) {
      if (isset($selector['options']['title'])) {
        $selector['options']['tooltip_content']['source'] = 'attribute';
        $selector['options']['tooltip_content']['selector'] = $selector['options']['title'];
        unset($selector['options']['title']);
        $converted_settings = TRUE;
      }
    }
    if ($converted_settings) {
      variable_set('tipsy', $settings);
    }
  }
  return $settings;
}

Functions

Namesort descending Description
tipsy_library Implements hook_library().
tipsy_menu Implements hook_menu().
tipsy_page_build Implements hook_page_build().
tipsy_permission Implements hook_perm().
tipsy_theme Implements hook_theme().
_tipsy_get_settings Helper function to retrieve all settings for tipsy.