We have a specific use-case that required some enhancements to this module. We needed a way for one or more external modules to modify the display of custom tooltips to add a tip icon that the events would fire on. For example, they could create a custom tooltip that would apply to the My Account link in the header. Rather than having the tooltip showup on the link itself, we intercept the rendering of the tooltip to insert a tip icon into the page and attach the tooltip to that icon.

The attached patch is a very rough first pass at extending the beautytips module so that other modules can add configuration options to the custom tooltip admin screen and provide a javascript pre-process function to modify the page and/or tooltip instance prior to rendering.

NOTE: Currently this patch disables the minimized beautytips.js.

How to use:

mymodule.module:

/**
 * Implements hook_beautytips_external_options().
 */
function mymodule_beautytips_external_options() {
  $options = array(
    'mymodule_tip_icon' => array(
      'title' => t('Add tip icon'),
      'description' => t(''),
      'js_preprocess' => 'mymodule_preprocess',
      'default_value' => TRUE,
      'icon' => _mymodule_get_icon(),
    ),
  );

  return $options;
}

mymodule.js

(function($) {
  /**
   * Preprocess function to alter the display of
   * custom tooltip.
   *
   * @param tip
   * The tooltip currently being processed.
   */
  $.fn.mymodule_preprocess = function(tip) {
    var tip_id = "form_tooltip_" + Math.floor(Math.random() * 99999);
    var icon_html = tip['external_options']['form_tooltip_tip_icon']['icon'];

    var icon = $(tip['cssSelect']).parent().append(icon_html);
    $(tip['cssSelect']).parent().find('div.form-tooltip-wrapper img').addClass(tip_id);
    tip['original_cssSelect'] = tip['cssSelect'];
    tip['cssSelect'] = '.' + tip_id;

    return this;
  }
})(jQuery);

NOTE: The javascript preprocess function has to be implemented as a jQuery plugin.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

shawn_smiley’s picture

Status: Active » Needs review
FileSize
21.39 KB

Here is a slightly modified version of the patch that restored the minimized version of beautytips.min.js

dasjo’s picture

here is a reroll against the recent dev version of beautytips with just the relevant updates (removed code-style fixes)

dasjo’s picture

Issue summary: View changes

Fixed a typo in the example code.

pifagor’s picture

Status: Needs review » Closed (outdated)