You are here

joyride.module in Joyride JQuery for Drupal Site Tours 7

File

joyride.module
View source
<?php

define('JOYRIDE_LIBRARY_VERSION', '2.0.3');

/**
 * Implements hook_libraries_info().
 * Return information about external libraries.
 *
 * @see http://drupal.org/documentation/modules/libraries
 */
function joyride_libraries_info() {
  $libraries['joyride'] = array(
    'name' => 'Joyride',
    'vendor url' => 'http://www.zurb.com/',
    'download url' => 'https://github.com/zurb/joyride',
    'version callback' => 'joyride_version',
    'version arguments' => array(
      'file' => 'jquery.joyride-' . JOYRIDE_LIBRARY_VERSION . '.js',
      // jQuery Foundation Joyride Plugin 2.0.2
      'pattern' => '/jQuery Foundation Joyride Plugin ([\\d][\\d\\.\\0]+)/',
      'lines' => 2,
    ),
    'files' => array(
      'js' => array(
        'jquery.joyride-' . JOYRIDE_LIBRARY_VERSION . '.js',
        'modernizr.mq.js',
      ),
      'css' => array(
        'joyride-' . JOYRIDE_LIBRARY_VERSION . '.css',
      ),
    ),
  );
  return $libraries;
}

/**
 * Library version callback. Make sure the library version is correct.
 */
function joyride_version($library, $options) {

  // Provide defaults.
  $options += array(
    'file' => '',
    'pattern' => '',
    'lines' => 20,
    'cols' => 200,
  );
  $file = DRUPAL_ROOT . '/' . $library['library path'] . '/' . $options['file'];
  if (empty($options['file']) || !file_exists($file)) {
    return;
  }
  $file = fopen($file, 'r');
  while ($options['lines'] && ($line = fgets($file, $options['cols']))) {
    if (preg_match($options['pattern'], $line, $version)) {
      if ($version[1] == JOYRIDE_LIBRARY_VERSION) {
        fclose($file);
        return $version[1];
      }
    }
    $options['lines']--;
  }
  fclose($file);
}

/**
 * Implements hook_context_plugins().
 * Let context know about plugin implementations.
 *
 * @see http://api.drupalize.me/api/drupal/function/hook_context_plugins/7
 */
function joyride_context_plugins() {
  $plugins = array();
  $plugins['joyride_context_reaction_add'] = array(
    'handler' => array(
      'path' => drupal_get_path('module', 'joyride') . '/plugins/context',
      'file' => 'joyride_context_reaction_add.inc',
      'class' => 'joyride_context_reaction_add',
      'parent' => 'context_reaction',
    ),
  );
  return $plugins;
}

/**
 * Implements hook_context_registry().
 * Registry hook for conditions & reactions.
 *
 * @see http://api.drupalize.me/api/drupal/function/hook_context_registry/7
 */
function joyride_context_registry() {
  return array(
    'reactions' => array(
      'joyride_add' => array(
        'title' => t('Joyride Tour'),
        'description' => t('Add Joyride code to the page.'),
        'plugin' => 'joyride_context_reaction_add',
      ),
    ),
  );
}

/**
 * Implements hook_ctools_plugin_api().
 * Tell CTools about our module.
 *
 */
function joyride_ctools_plugin_api($module, $api) {
  if ($module !== 'context') {
    return FALSE;
  }
  switch ($api) {
    case 'context':
      return array(
        'version' => 3,
      );
    case 'plugins':
      return array(
        'version' => 3,
        'path' => drupal_get_path('module', 'joyride') . '/plugins/context',
      );
    default:
      return FALSE;
  }
}

/**
 * Implements hook_init().
 * Perform setup tasks for non-cached page requests.
 *
 * @see http://api.drupalize.me/api/drupal/function/hook_init/7
 */
function joyride_init() {
  $plugin = context_get_plugin('reaction', 'joyride_add');
  if ($plugin) {
    $plugin
      ->execute();
  }
}

/**
 * Implements hook_theme().
 * Register a module (or theme's) theme implementations.
 *
 * @see http://api.drupalize.me/api/drupal/function/hook_theme/7
 */
function joyride_theme($existing, $type, $theme, $path) {
  return array(
    'joyride_tips' => array(
      'variables' => array(
        'tips_content' => NULL,
      ),
      'template' => 'templates/joyride-tips',
    ),
    'joyride_help' => array(
      'variables' => array(),
      'template' => 'templates/joyride-help',
    ),
    'joyride_demo' => array(
      'variables' => array(),
      'template' => 'templates/joyride-demo',
    ),
    'joyride_start_link' => array(
      'variables' => array(
        'link_title' => NULL,
        'options' => array(),
      ),
      'template' => 'templates/joyride-start-link',
      'file' => 'inc/joyride.theme.inc',
    ),
  );
}

/**
 * Implements hook_help().
 *
 * @see http://api.drupalize.me/api/drupal/function/hook_help/7
 */
function joyride_help($path, $arg) {
  switch ($path) {
    case 'admin/help#joyride':
      return theme('joyride_help');
    case 'admin/help#joyride#demo#default':
      return theme('joyride_demo');
    case 'admin/help#joyride#demo#manual-trigger':
      return theme('joyride_demo');
    case 'admin/help#joyride#demo#play-only-once':
      return theme('joyride_demo');
  }
}

/**
 * Implements hook_menu().
 *
 * @see
 */
function joyride_menu() {
  $items = array();
  $items['admin/config/user-interface/joyride'] = array(
    'title' => 'Joyride Demo',
    'page callback' => 'theme',
    'page arguments' => array(
      'joyride_demo',
    ),
    'access arguments' => array(
      'access administration pages',
    ),
    'type' => MENU_NORMAL_ITEM,
  );
  $items['admin/config/user-interface/joyride/auto-start'] = array(
    'title' => 'Joyride Demo (Start tour automatically)',
    'page callback' => 'theme',
    'page arguments' => array(
      'joyride_demo',
    ),
    'access arguments' => array(
      'access administration pages',
    ),
    'type' => MENU_DEFAULT_LOCAL_TASK,
    'weight' => -10,
  );
  $items['admin/config/user-interface/joyride/manual-trigger'] = array(
    'title' => 'Joyride Demo (Use manual trigger to start tour)',
    'page callback' => 'theme',
    'page arguments' => array(
      'joyride_demo',
    ),
    'access arguments' => array(
      'access administration pages',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 10,
  );
  $items['admin/config/user-interface/joyride/play-once'] = array(
    'title' => 'Joyride Demo (Play tour only once)',
    'page callback' => 'theme',
    'page arguments' => array(
      'joyride_demo',
    ),
    'access arguments' => array(
      'access administration pages',
    ),
    'type' => MENU_LOCAL_TASK,
    'weight' => 20,
  );
  return $items;
}

/**
 * Implements hook_context_default_contexts().
 * Provide default module's contexts.
 *
 * @return array
 */
function joyride_context_default_contexts() {
  $export = array();
  $context = new stdClass();
  $context->disabled = FALSE;

  /* Edit this to true to make a default context disabled initially */
  $context->api_version = 3;
  $context->name = 'joyride_demo_default';
  $context->description = '';
  $context->tag = 'joyride';
  $context->conditions = array(
    'path' => array(
      'values' => array(
        'admin/config/user-interface/joyride' => 'admin/config/user-interface/joyride',
        'admin/config/user-interface/joyride/auto-start' => 'admin/config/user-interface/joyride/auto-start',
      ),
    ),
  );
  $context->reactions = array(
    'joyride_add' => array(
      'joyride_auto_start' => 1,
      'joyride_play_once' => 0,
      'joyride_tour_content' => '<li data-class="so-awesome" data-text="Next" class="custom">
  <h2>Stop #1</h2>
  <p>You can control all the details for you tour stop. Any valid HTML will work inside of Joyride.</p>
</li>
<li data-id="numero2" data-button="Next" data-options="tipLocation:top;tipAnimation:fade">
  <h2>Stop #2</h2>
  <p>Get the details right by styling Joyride with a custom stylesheet!</p>
</li>
<li data-id="numero3" data-button="Next" data-options="tipLocation:right">
  <h2>Stop #3</h2>
  <p>It works right aligned.</p>
</li>
<li data-button="Next">
  <h2>Stop #4</h2>
  <p>It works as a modal too!</p>
</li>
<li data-id="numero5" data-button="Close">
  <h2>Stop #5</h2>
  <p>Now what are you waiting for? Add this to your projects and get the most out of your apps!</p>
</li>',
    ),
  );
  $context->condition_mode = 0;

  // Translatables
  // Included for use with string extractors like potx.
  t('joyride');
  $export[$context->name] = $context;
  $context = new stdClass();
  $context->disabled = FALSE;

  /* Edit this to true to make a default context disabled initially */
  $context->api_version = 3;
  $context->name = 'joyride_demo_manual_trigger';
  $context->description = '';
  $context->tag = 'joyride';
  $context->conditions = array(
    'path' => array(
      'values' => array(
        'admin/config/user-interface/joyride/manual-trigger' => 'admin/config/user-interface/joyride/manual-trigger',
      ),
    ),
  );
  $context->reactions = array(
    'joyride_add' => array(
      'joyride_auto_start' => 0,
      'joyride_play_once' => FALSE,
      'joyride_tour_content' => '<li data-class="so-awesome" data-text="Next" class="custom">
  <h2>Stop #1</h2>
  <p>You can control all the details for you tour stop. Any valid HTML will work inside of Joyride.</p>
</li>
<li data-id="numero2" data-button="Next" data-options="tipLocation:top;tipAnimation:fade">
  <h2>Stop #2</h2>
  <p>Get the details right by styling Joyride with a custom stylesheet!</p>
</li>
<li data-id="numero3" data-button="Next" data-options="tipLocation:right">
  <h2>Stop #3</h2>
  <p>It works right aligned.</p>
</li>
<li data-button="Next">
  <h2>Stop #4</h2>
  <p>It works as a modal too!</p>
</li>
<li data-id="numero5" data-button="Close">
  <h2>Stop #5</h2>
  <p>Now what are you waiting for? Add this to your projects and get the most out of your apps!</p>
</li>',
    ),
  );
  $context->condition_mode = 0;

  // Translatables
  // Included for use with string extractors like potx.
  t('joyride');
  $export[$context->name] = $context;
  $context = new stdClass();
  $context->disabled = FALSE;

  /* Edit this to true to make a default context disabled initially */
  $context->api_version = 3;
  $context->name = 'joyride_demo_play_once';
  $context->description = '';
  $context->tag = 'joyride';
  $context->conditions = array(
    'path' => array(
      'values' => array(
        'admin/config/user-interface/joyride/play-once' => 'admin/config/user-interface/joyride/play-once',
      ),
    ),
  );
  $context->reactions = array(
    'joyride_add' => array(
      'joyride_auto_start' => 1,
      'joyride_play_once' => 1,
      'joyride_tour_content' => '<li data-class="so-awesome" data-text="Next" class="custom">
  <h2>Stop #1</h2>
  <p>You can control all the details for you tour stop. Any valid HTML will work inside of Joyride.</p>
</li>
<li data-id="numero2" data-button="Next" data-options="tipLocation:top;tipAnimation:fade">
  <h2>Stop #2</h2>
  <p>Get the details right by styling Joyride with a custom stylesheet!</p>
</li>
<li data-id="numero3" data-button="Next" data-options="tipLocation:right">
  <h2>Stop #3</h2>
  <p>It works right aligned.</p>
</li>
<li data-button="Next">
  <h2>Stop #4</h2>
  <p>It works as a modal too!</p>
</li>
<li data-id="numero5" data-button="Close">
  <h2>Stop #5</h2>
  <p>Now what are you waiting for? Add this to your projects and get the most out of your apps!</p>
</li>',
    ),
  );
  $context->condition_mode = 0;

  // Translatables
  // Included for use with string extractors like potx.
  t('joyride');
  $export[$context->name] = $context;
  return $export;
}

/**
 * Implements hook_enable().
 * Perform necessary actions after module is enabled.
 *
 * @see http://api.drupalize.me/api/drupal/function/hook_enable/7
 */
function joyride_enable() {

  // We need this to make context detect new reaction handler
  drupal_flush_all_caches();
}

/**
 * Implements hook_block_info().
 * Define all blocks provided by the module.
 *
 * @see http://api.drupalize.me/api/drupal/function/hook_block_info/7
 */
function joyride_block_info() {
  $blocks['joyride_start_link'] = array(
    'info' => t('Joyride Start Link'),
    'cache' => DRUPAL_NO_CACHE,
  );
  return $blocks;
}

/**
 * Implements hook_block_view().
 * Return a rendered or renderable view of a block.
 *
 * @see http://api.drupalize.me/api/drupal/function/hook_block_view/7
 */
function joyride_block_view($delta = '') {
  $block = array();
  switch ($delta) {
    case 'joyride_start_link':
      $block['subject'] = '<none>';
      $block['content'] = array(
        '#theme' => 'joyride_start_link',
      );
      break;
  }
  return $block;
}

/**
 * Implements hook_context_page_reaction().
 */
function joyride_context_page_reaction() {
  if ($plugin = context_get_plugin('reaction', 'joyride_add')) {
    $plugin
      ->execute();
  }
}

Functions

Namesort descending Description
joyride_block_info Implements hook_block_info(). Define all blocks provided by the module.
joyride_block_view Implements hook_block_view(). Return a rendered or renderable view of a block.
joyride_context_default_contexts Implements hook_context_default_contexts(). Provide default module's contexts.
joyride_context_page_reaction Implements hook_context_page_reaction().
joyride_context_plugins Implements hook_context_plugins(). Let context know about plugin implementations.
joyride_context_registry Implements hook_context_registry(). Registry hook for conditions & reactions.
joyride_ctools_plugin_api Implements hook_ctools_plugin_api(). Tell CTools about our module.
joyride_enable Implements hook_enable(). Perform necessary actions after module is enabled.
joyride_help Implements hook_help().
joyride_init Implements hook_init(). Perform setup tasks for non-cached page requests.
joyride_libraries_info Implements hook_libraries_info(). Return information about external libraries.
joyride_menu Implements hook_menu().
joyride_theme Implements hook_theme(). Register a module (or theme's) theme implementations.
joyride_version Library version callback. Make sure the library version is correct.

Constants