You are here

responsive_imagemaps.module in Responsive Image Maps 7

File

responsive_imagemaps.module
View source
<?php

/**
 * Shows this block on every page except the listed pages.
 */
define('RESPONSIVE_IMAGEMAPS_ALWAYS', 1);

/**
 * Shows this block on only the listed pages.
 */
define('RESPONSIVE_IMAGEMAPS_LISTED', 0);

/**
 * Implements hook_menu().
 */
function responsive_imagemaps_menu() {
  $items = array();
  $items['admin/config/media/responsive-imagemaps'] = array(
    'title' => 'Responsive Image Maps',
    'description' => 'Configure responsive image map settings',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'responsive_imagemaps_admin_settings',
    ),
    'access arguments' => array(
      'administer responsive image maps',
    ),
    'type' => MENU_NORMAL_ITEM,
    'file' => 'responsive_imagemaps.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_permission().
 */
function responsive_imagemaps_permission() {
  return array(
    'administer responsive image maps' => array(
      'title' => t('Administer Responsive Image Maps'),
      'description' => t('Allows a user to configure Responsive Image Maps.'),
    ),
  );
}

/**
 * Implements hook_requirements().
 */
function responsive_imagemaps_requirements($phase) {

  // Create an array to hold requirements
  $requirements = array();

  // Check requirements during the runtime phase
  if ($phase == 'runtime') {

    // Check if the jQuery RWD Image Maps plugin library is installed
    if (($library = libraries_detect('responsive-imagemaps')) && !empty($library['installed'])) {
      $requirements['responsive_imagemaps_library'] = array(
        'title' => t('Responsive Image Maps jQuery RWD Image Maps plugin'),
        'value' => t('Installed'),
        'severity' => REQUIREMENT_OK,
      );
    }
    else {
      $requirements['responsive_imagemaps_library'] = array(
        'title' => t('Responsive Image Maps jQuery RWD Image Maps plugin'),
        'value' => t('Not installed'),
        'description' => $library['error message'],
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $requirements;
}

/**
 * Implements hook_libraries_info().
 */
function responsive_imagemaps_libraries_info() {
  $libraries['responsive-imagemaps'] = array(
    'name' => 'jQuery RWD Image Maps',
    'vendor url' => 'https://github.com/stowball/jQuery-rwdImageMaps',
    'download url' => 'https://github.com/stowball/jQuery-rwdImageMaps/archive/master.zip',
    'version arguments' => array(
      'file' => 'jquery.rwdImageMaps.min.js',
      'pattern' => '/rwdImageMaps jQuery plugin v(\\d+\\.+\\d+)/',
      'lines' => 2,
    ),
    'files' => array(
      'js' => array(
        'jquery.rwdImageMaps.min.js',
      ),
    ),
  );
  return $libraries;
}

/**
 * Implements hook_init().
 */
function responsive_imagemaps_init() {
  $load_responsive_imagemaps = variable_get('responsive_imagemaps_visibility', RESPONSIVE_IMAGEMAPS_ALWAYS);

  // Match path if necessary.
  if ($load_responsive_imagemaps == RESPONSIVE_IMAGEMAPS_LISTED) {

    // Convert path to lowercase. This allows comparison of the same path
    // with different case. Ex: /Page, /page, /PAGE.
    $pages = drupal_strtolower(variable_get('responsive_imagemaps_pages', ''));

    // Convert the Drupal path to lowercase
    $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));

    // Compare the lowercase internal and lowercase path alias (if any).
    $load_responsive_imagemaps = drupal_match_path($path, $pages);
    if ($path != $_GET['q']) {
      $load_responsive_imagemaps = $load_responsive_imagemaps || drupal_match_path($_GET['q'], $pages);
    }
  }
  if ($load_responsive_imagemaps) {
    libraries_load('responsive-imagemaps');
    drupal_add_js(drupal_get_path('module', 'responsive_imagemaps') . '/responsive_imagemaps.js', array(
      'scope' => 'footer',
    ));
  }
}

Functions

Constants

Namesort descending Description
RESPONSIVE_IMAGEMAPS_ALWAYS Shows this block on every page except the listed pages.
RESPONSIVE_IMAGEMAPS_LISTED Shows this block on only the listed pages.