jq_maphilight.module in jQuery Map Hilight 6
Same filename and directory in other branches
Configurable javascript based image map hilighting using the jquery map hilight plugin.
File
jq_maphilight.moduleView source
<?php
/**
* @file
* Configurable javascript based image map hilighting using the jquery map hilight plugin.
*/
/**
* add the jquery map hilight plugin code to all pages
*/
function jq_maphilight_init() {
$available = _jq_maphilight_available();
if ($available !== FALSE) {
$script = "(function (\$) {\n" . "Drupal.behaviors.jq_maphilight = function(context, settings) {\n" . "\$.fn.maphilight.defaults = {\n" . "fill: " . variable_get('jq_maphilight_fill', 'true') . ",\n" . "fillColor: '" . variable_get('jq_maphilight_fillcolor', '000000') . "',\n" . "fillOpacity: " . variable_get('jq_maphilight_fillopacity', '2') / 10 . ",\n" . "stroke: " . variable_get('jq_maphilight_stroke', 'true') . ",\n" . "strokeColor: '" . variable_get('jq_maphilight_strokecolor', 'ff0000') . "',\n" . "strokeOpacity: " . variable_get('jq_maphilight_strokeopacity', '10') / 10 . ",\n" . "strokeWidth: " . variable_get('jq_maphilight_strokewidth', '2') . ",\n" . "fade: " . variable_get('jq_maphilight_fade', 'true') . ",\n" . "alwaysOn: " . variable_get('jq_maphilight_alwayson', 'false') . ",\n" . "neverOn: " . variable_get('jq_maphilight_neveron', 'false') . ",\n" . "groupBy: " . variable_get('jq_maphilight_groupby', 'false') . "};\n";
if (variable_get('jq_maphilight_allmaps_enabled', TRUE)) {
$script .= "\$('img[usemap]').maphilight();\n";
}
else {
$script .= "\$('.jq_maphilight').maphilight();\n";
}
$script .= "}})(jQuery);";
jquery_plugin_add('metadata');
drupal_add_js($available, 'module');
drupal_add_js($script, 'inline');
}
return '';
}
/**
* Implemention of hook_menu().
*/
function jq_maphilight_menu() {
$items = array();
$items['admin/settings/jq_maphilight'] = array(
'title' => 'JQuery Map Hilight',
'description' => 'Javascript image map highlighting using the jQuery Map Hilight plugin.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'jq_maphilight_admin_settings',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer site configuration',
),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* jq_maphilight admin/settings page; implements hook_form
*/
function jq_maphilight_admin_settings() {
$form['jq_maphilight_status'] = array(
'#type' => 'fieldset',
'#title' => t('jQuery Map Hilight Plugin Status'),
'#weight' => -10,
'#description' => _jq_maphilight_available() !== false ? t('The Map Hilight jQuery plugin is available at: /') . _jq_maphilight_available() : '<em><span style="color: #A50000;">' . t('The Map Hilight jQuery plugin is unavailable.') . '</span></em>',
);
$form['jq_maphilight_allmaps'] = array(
'#type' => 'fieldset',
'#title' => t('jQuery Map Hilight All Maps'),
'#weight' => -9,
);
$form['jq_maphilight_allmaps']['jq_maphilight_allmaps_enabled'] = array(
'#type' => 'radios',
'#title' => t('Enable highlighting for all image maps'),
'#default_value' => variable_get(jq_maphilight_allmaps_enabled, 1),
'#options' => array(
t('No'),
t('Yes'),
),
'#disabled' => !is_file(drupal_get_path('module', 'jquery_plugin') . '/jquery.maphilight.min.js'),
'#description' => 'If no, be sure to add <strong><em>class="jq_maphilight"</em></strong> to the <img> tag of all image maps you want highlighted.',
);
$form['jq_maphilight_settings'] = array(
'#type' => 'fieldset',
'#title' => t('jQuery Map Hilight Plugin Settings'),
'#description' => 'You can override the default settings on individual image maps by adding an additional class to the <img> tag. See the README.txt file for more information.',
);
$form['jq_maphilight_settings']['jq_maphilight_fill'] = array(
'#type' => 'select',
'#title' => t('Fill'),
'#default_value' => variable_get('jq_maphilight_fill', 'true'),
'#options' => array(
'true' => t('TRUE'),
'false' => t('FALSE'),
),
'#description' => 'Specify whether or not the hilighted area should be filled.',
);
$form['jq_maphilight_settings']['jq_maphilight_fillcolor'] = array(
'#type' => 'textfield',
'#title' => t('Fill Color'),
'#default_value' => variable_get('jq_maphilight_fillcolor', 'ff0000'),
'#size' => 8,
'#description' => 'Specify the color of the fill. Use HTML # notation without the #.',
);
$form['jq_maphilight_settings']['jq_maphilight_fillopacity'] = array(
'#type' => 'select',
'#title' => t('Fill Opacity'),
'#default_value' => variable_get('jq_maphilight_fillopacity', 2),
'#options' => drupal_map_assoc(array(
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
)),
'#description' => 'Specify the opacity of the fill (0 = lightest, 10 = darkest).',
);
$form['jq_maphilight_settings']['jq_maphilight_stroke'] = array(
'#type' => 'select',
'#title' => t('Stroke (outline)'),
'#options' => array(
'true' => t('TRUE'),
'false' => t('FALSE'),
),
'#default_value' => variable_get('jq_maphilight_stroke', 'true'),
'#description' => 'Specify whether or not the hilighted area will be outlined.',
);
$form['jq_maphilight_settings']['jq_maphilight_strokecolor'] = array(
'#type' => 'textfield',
'#title' => t('Stroke Color'),
'#default_value' => variable_get('jq_maphilight_strokecolor', 'D51910'),
'#size' => 8,
'#description' => 'Specify the color of the outline. Use HTML # notation without the #.',
);
$form['jq_maphilight_settings']['jq_maphilight_strokewidth'] = array(
'#type' => 'textfield',
'#title' => t('Stroke Width'),
'#default_value' => variable_get('jq_maphilight_strokewidth', 2),
'#size' => 8,
'#description' => 'Specify the width of the outline in pixels.',
);
$form['jq_maphilight_settings']['jq_maphilight_strokeopacity'] = array(
'#type' => 'select',
'#title' => t('Stroke Opacity'),
'#default_value' => variable_get('jq_maphilight_strokeopacity', 10),
'#options' => drupal_map_assoc(array(
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
)),
'#description' => 'Specify the opacity of the outline (0 = lightest, 10 = darkest).',
);
$form['jq_maphilight_settings']['jq_maphilight_fade'] = array(
'#type' => 'select',
'#title' => t('Fade'),
'#options' => array(
'true' => t('TRUE'),
'false' => t('FALSE'),
),
'#default_value' => variable_get('jq_maphilight_fade', 'true'),
'#description' => 'Specify whether or not the hilighting uses a fade transition.',
);
return system_settings_form($form);
}
/**
* check jquery_plugin directory for the jquery.maphilight.min.js file
*/
function _jq_maphilight_available() {
if (module_exists('libraries')) {
if (is_file($available = libraries_get_path('jquery.maphilight') . '/jquery.maphilight.min.js')) {
return $available;
}
}
if (is_file($available = 'sites/all/libraries/jquery.maphilight/jquery.maphilight.min.js')) {
return $available;
}
if (is_file($available = drupal_get_path('module', 'jq_maphilight') . '/jquery.maphilight.min.js')) {
return $available;
}
if (is_file($available = drupal_get_path('module', 'jquery_plugin') . '/jquery.maphilight.min.js')) {
return $available;
}
return FALSE;
}
Functions
Name![]() |
Description |
---|---|
jq_maphilight_admin_settings | jq_maphilight admin/settings page; implements hook_form |
jq_maphilight_init | add the jquery map hilight plugin code to all pages |
jq_maphilight_menu | Implemention of hook_menu(). |
_jq_maphilight_available | check jquery_plugin directory for the jquery.maphilight.min.js file |