You are here

jquery_touchpunch.module in jQuery UI Touch Punch 7

File

jquery_touchpunch.module
View source
<?php

/**
 * @file
 * jquery_touchpunch.module
 */
define('JQUERY_TOUCHPUNCH_ENABLED', 1);

/**
 * Implements hook_menu().
 */
function jquery_touchpunch_menu() {
  $items['admin/config/development/touchpunch'] = array(
    'title' => 'jQuery Touch Punch Settings',
    'description' => 'Configuration page for jQuery Touch Punch.',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'jquery_touchpunch_settings_form',
    ),
    'type' => MENU_NORMAL_ITEM,
    'access arguments' => array(
      'administer site configuration',
    ),
    'file' => 'jquery_touchpunch.admin.inc',
  );
  return $items;
}

/**
 * Implements hook_libraries_info().
 */
function jquery_touchpunch_libraries_info() {
  $libraries['jquery.ui.touch-punch'] = array(
    'name' => 'jQuery UI Touch Punch',
    'vendor url' => 'http://touchpunch.furf.com/',
    'download url' => 'https://raw.githubusercontent.com/furf/jquery-ui-touch-punch/master/jquery.ui.touch-punch.min.js',
    'version arguments' => array(
      'file' => 'jquery.ui.touch-punch.min.js',
      'pattern' => '/jQuery UI Touch Punch (\\d+\\.+\\d+.+\\d+)/',
    ),
    'files' => array(
      'js' => array(
        'jquery.ui.touch-punch.min.js',
      ),
    ),
    'variants' => array(
      'minified' => array(
        'files' => array(
          'js' => array(
            'jquery.ui.touch-punch.min.js',
          ),
        ),
        'variant callback' => 'jquery_touchpunch_check_variant',
        'variant arguments' => array(
          'file' => 'jquery.ui.touch-punch.min.js',
        ),
      ),
      'source' => array(
        'files' => array(
          'js' => array(
            'jquery.ui.touch-punch.js',
          ),
        ),
        'variant callback' => 'jquery_touchpunch_check_variant',
        'variant arguments' => array(
          'file' => 'jquery.ui.touch-punch.js',
        ),
      ),
    ),
  );
  return $libraries;
}

/**
 * Implements hook_js_alter().
 */
function jquery_touchpunch_js_alter(&$javascript) {
  if (variable_get('jquery_touchpunch_enabled', JQUERY_TOUCHPUNCH_ENABLED)) {

    // Attach plugin only if it needs (only if ui.widget is available in the
    // js array). Such ugly approach is used because of modules
    // that attach jQuery.ui libraries by using drupal_add_js function. Of
    // course, adding of a dependency in hook_libraries_alter would be more
    // prefer, but this will not work with some contrib modules.
    foreach ($javascript as $name => $js) {
      if (strpos($name, 'ui.widget') !== FALSE) {
        $variant = variable_get('jquery_touchpunch_compression_type', 'minified');
        libraries_load('jquery.ui.touch-punch', $variant);
        break;
      }
    }
  }
}

/**
 * Library variant callback.
 */
function jquery_touchpunch_check_variant($library, $variant_name, $variant_arguments) {
  if (file_exists($library['library path'] . '/' . $variant_arguments['file'])) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}

/**
 * Helper function. Generatss an error message.
 */
function jquery_touchpunch_error_message($error_message, $library) {

  // Use this variable for t() function because this function
  // may be called in .install file.
  $t = get_t();
  return $t('!error You need to download the !library ' . 'and place to \'jquery.ui.touch-punch\' directory in the %path ' . 'directory on your server.', array(
    '!error' => $error_message,
    '!library' => l($library['name'], $library['download url']),
    '%path' => 'sites/all/libraries',
  ));
}

Functions

Namesort descending Description
jquery_touchpunch_check_variant Library variant callback.
jquery_touchpunch_error_message Helper function. Generatss an error message.
jquery_touchpunch_js_alter Implements hook_js_alter().
jquery_touchpunch_libraries_info Implements hook_libraries_info().
jquery_touchpunch_menu Implements hook_menu().

Constants