function image_hotspots_node_view in Image Hotspots 7.2
Implements hook_node_view().
File
- ./
image_hotspots.module, line 337 - Main function of module.
Code
function image_hotspots_node_view($node, $view_mode, $langcode) {
$hotspot_fields = variable_get('image_hotspot_fields', array());
$images = array();
if (!empty($hotspot_fields[$node->type])) {
foreach ($hotspot_fields[$node->type] as $field_settings) {
$field_name = $field_settings['field'];
if (empty($node->content[$field_name]) || $node->content[$field_name]['#formatter'] != 'image') {
continue;
}
$image_delta = element_children($node->content[$field_name]);
foreach ($image_delta as $delta) {
$fid = $node->content[$field_name][$delta]['#item']['fid'];
$images[$fid]['fid'] = $fid;
$node->content[$field_name][$delta]['#item']['attributes']['id'] = 'image-hotspot-' . $fid;
$node->content[$field_name][$delta]['#item']['attributes']['class'][] = 'image-hotspot';
}
}
if (!empty($images)) {
$language = entity_language('node', $node);
$hotspots_data = image_hotspots_db_get_coordinates(array_keys($images), $language);
$hotspots = array();
if (!empty($hotspots_data)) {
$scripts = drupal_add_js();
$settings = $scripts['settings']['data'];
foreach ($hotspots_data as $image_hotspots) {
foreach ($settings as $setting) {
if (isset($setting['imageHotspots']['fid' . $image_hotspots->fid])) {
continue 2;
}
}
$hotspots['fid' . $image_hotspots->fid] = drupal_json_decode($image_hotspots->coordinates);
}
$hotspot_color = variable_get('image_hotspots_settings');
if (!empty($hotspots)) {
drupal_add_js(array(
'imageHotspots' => $hotspots,
), 'setting');
drupal_add_js(array(
'imageHotspotsColor' => $hotspot_color,
), 'setting');
drupal_add_js(drupal_get_path('module', 'image_hotspots') . '/themes/tipTip/jquery.tipTip.min.js');
drupal_add_js(drupal_get_path('module', 'image_hotspots') . '/themes/image_hotspots.js');
drupal_add_css(drupal_get_path('module', 'image_hotspots') . '/themes/tipTip/tipTip.css');
drupal_add_css(drupal_get_path('module', 'image_hotspots') . '/themes/image_hotspots.css');
}
}
}
}
}