You are here

colorbox_swipe.module in Colorbox Swipe Gestures Support 7

Helper module to recognize swipe events in lightbox. Mini Module developed by DROWL.de

File

colorbox_swipe.module
View source
<?php

/**
 * @file Helper module to recognize swipe events in lightbox.
 * Mini Module developed by DROWL.de
 */

/**
 * Initialization of colorbox_swipe (on each page).
 */
function colorbox_swipe_page_build(&$page) {
  static $already_added = FALSE;
  if ($already_added) {
    return;

    // Don't add the JavaScript and CSS multiple times.
  }

  // Only add the swipe support if colorbox is added on the page.
  // Respect the lightbox settings.
  // Do not load colorbox swipe during the Drupal installation process, e.g. if part
  // of installation profiles.
  if (!drupal_installation_attempted() && _colorbox_active()) {
    if (($library_jquery_event_move = libraries_load('jquery.event.move')) && !empty($library_jquery_event_move['loaded']) && ($library_jquery_event_swipe = libraries_load('jquery.event.swipe')) && !empty($library_jquery_event_swipe['loaded'])) {

      // We need jQuery UI!
      drupal_add_library('system', 'ui');
      $module_path = drupal_get_path('module', 'colorbox_swipe');
      drupal_add_css($module_path . '/colorbox_swipe.css');
      drupal_add_js($module_path . '/colorbox_swipe.js', array(
        'scope' => 'footer',
      ));
    }
    $already_added = TRUE;
  }
}

/**
 * Implements hook_requirements().
 */
function colorbox_swipe_requirements($phase) {
  $requirements = array();

  // Check requirements during the runtime phase
  if ($phase == 'runtime') {
    if (($library = libraries_detect('jquery.event.move')) && !empty($library['installed'])) {
      $requirements['jquery.event.move'] = array(
        'title' => t('jquery.event.move'),
        'value' => t('Installed'),
        'severity' => REQUIREMENT_OK,
      );
    }
    else {
      $requirements['jquery.event.move'] = array(
        'title' => t('jquery.event.move'),
        'value' => t('Not installed'),
        'description' => $library['error message'],
        'severity' => REQUIREMENT_ERROR,
      );
    }
    if (($library = libraries_detect('jquery.event.swipe')) && !empty($library['installed'])) {
      $requirements['jquery.event.swipe'] = array(
        'title' => t('jquery.event.swipe'),
        'value' => t('Installed'),
        'severity' => REQUIREMENT_OK,
      );
    }
    else {
      $requirements['jquery.event.swipe'] = array(
        'title' => t('jquery.event.swipe'),
        'value' => t('Not installed'),
        'description' => $library['error message'],
        'severity' => REQUIREMENT_ERROR,
      );
    }

    // Check if the site is running >= jQuery 1.7
    if (($library = drupal_get_library('system', 'jquery')) && version_compare($library['version'], '1.7', '>=')) {
      $requirements['jquery.event.move-jquery'] = array(
        'title' => t('jquery.event.move'),
        'value' => t('jQuery @version', array(
          '@version' => $library['version'],
        )),
        'severity' => REQUIREMENT_OK,
      );
    }
    else {
      $destination = drupal_get_destination();
      $requirements['jquery.event.move-jquery'] = array(
        'title' => t('jquery.event.move'),
        'value' => t('jQuery @version', array(
          '@version' => $library['version'],
        )),
        'description' => t('jquery.event.move requires jQuery 1.7 or greater. Configure <a href="@jquery_update">jQuery Update</a>.', array(
          '@jquery_update' => url('admin/config/development/jquery_update', array(
            'query' => $destination,
          )),
        )),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    if (($library = drupal_get_library('system', 'ui')) && version_compare($library['version'], '1.8', '>=')) {
      $requirements['jquery.event.move-jqueryui'] = array(
        'title' => t('jquery.event.move'),
        'value' => t('jQuery UI @version', array(
          '@version' => $library['version'],
        )),
        'severity' => REQUIREMENT_OK,
      );
    }
    else {
      $destination = drupal_get_destination();
      $requirements['jquery.event.move-jqueryui'] = array(
        'title' => t('jquery.event.move'),
        'value' => t('jQuery UI @version', array(
          '@version' => $library['version'],
        )),
        'description' => t('jquery.event.move requires jQuery UI 1.8 or greater.'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
  }
  return $requirements;
}

/**
 * Implements hook_library().
 */
function colorbox_swipe_libraries_info() {
  $libraries = array();
  $libraries['jquery.event.move'] = array(
    'name' => 'jQuery Event Move',
    'vendor url' => 'https://github.com/stephband/jquery.event.move',
    'download url' => 'https://github.com/stephband/jquery.event.move/archive/master.zip',
    'version' => '1.0',
    'files' => array(
      'js' => array(
        'js/jquery.event.move.js' => array(
          'scope' => 'footer',
        ),
      ),
    ),
  );
  $libraries['jquery.event.swipe'] = array(
    'name' => 'jQuery Event Swipe',
    'vendor url' => 'https://github.com/stephband/jquery.event.swipe',
    'download url' => 'https://github.com/stephband/jquery.event.swipe/archive/master.zip',
    'version' => '1.0',
    'files' => array(
      'js' => array(
        'js/jquery.event.swipe.js' => array(
          'scope' => 'footer',
        ),
      ),
    ),
  );
  return $libraries;
}

Functions

Namesort descending Description
colorbox_swipe_libraries_info Implements hook_library().
colorbox_swipe_page_build Initialization of colorbox_swipe (on each page).
colorbox_swipe_requirements Implements hook_requirements().