You are here

twitter_bootstrap_modal_carousel.module in Twitter Bootstrap Modal 7.3

Generates a Twitter Bootstrap Carousel with images carousel.

File

twitter_bootstrap_modal_carousel/twitter_bootstrap_modal_carousel.module
View source
<?php

/**
* @file
* Generates a Twitter Bootstrap Carousel with images carousel.
*
*/

/**
 * Implements hook_init().
 */
function twitter_bootstrap_modal_carousel_init() {
  $settings = variable_get('twitter_bootstrap_modal_carousel_settings');
  if (twitter_bootstrap_modal_carousel_check_path($settings['visibility']['visibility'], $settings['visibility']['pages'])) {
    $module_path = drupal_get_path('module', 'twitter_bootstrap_modal_carousel');
    drupal_add_js(array(
      'twitter_bootstrap_modal_carousel' => array(
        'module_path' => $module_path,
        'trigger' => $settings['trigger'],
        'caption' => $settings['images']['image_caption'],
        'pause_on_hover' => $settings['navigation']['pause_on_hover'],
        'directional_navigation' => $settings['navigation']['directional_navigation'],
        'image_navigation' => $settings['navigation']['image_navigation'],
        'next_text' => $settings['navigation']['next_text'],
        'previous_text' => $settings['navigation']['previous_text'],
        'control_navigation' => $settings['navigation']['control_navigation'],
        'control_nav_thumbs' => $settings['navigation']['control_nav_thumbs'],
        'wrap' => $settings['navigation']['wrap'],
        'pause_time' => $settings['navigation']['pause_time'],
      ),
    ), 'setting');
    drupal_add_js($module_path . '/twitter_bootstrap_modal_carousel.js');
    drupal_add_css($module_path . '/twitter_bootstrap_modal_carousel.css');
  }
}

/**
* Implementation of hook_menu().
*/
function twitter_bootstrap_modal_carousel_menu() {

  // Admin settings.
  $items['admin/config/development/twitter_bootstrap_modal/TB_carousel'] = array(
    'title' => 'Twitter Bootstrap Modal Carousel',
    'description' => 'Shows a carousel of images on a Twitter Boostrap Modal',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'twitter_bootstrap_modal_carousel_settings',
    ),
    'access arguments' => array(
      'administer site configuration',
    ),
    'type' => MENU_LOCAL_TASK,
  );

  // Prefix for AJAX requests, returns json
  $items['bs_modal/jquery_ajax_load/image/style'] = array(
    'page callback' => 'jquery_ajax_load_callback',
    'type' => MENU_CALLBACK,
    'access arguments' => array(
      'access content',
    ),
    'delivery callback' => 'twitter_bootstrap_modal_delivery_callback',
  );
  return $items;
}
function twitter_bootstrap_modal_carousel_check_path($visibility, $pages) {
  $pages = drupal_strtolower($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).
  $page_match = drupal_match_path($path, $pages);
  if ($path != $_GET['q']) {
    $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
  }

  // When $block->visibility has a value of 0 (BLOCK_VISIBILITY_NOTLISTED),
  // the block is displayed on all pages except those listed in $block->pages.
  // When set to 1 (BLOCK_VISIBILITY_LISTED), it is displayed only on those
  // pages listed in $block->pages.
  $page_match = !($visibility xor $page_match);
  return $page_match;
}

/**
 * Module settings form.
 */
function twitter_bootstrap_modal_carousel_settings($form, &$form_state) {
  $settings = variable_get('twitter_bootstrap_modal_carousel_settings');
  $options['trigger'] = array(
    '#type' => 'textarea',
    '#title' => t('Valid jQuery Classes/IDs to trigger TB carousel Modal (One per line)'),
    '#default_value' => $settings['trigger'] . "\n",
    '#description' => t('Specify the class/ID of links to load destination images in a TB Modal, one per line. For example by providing ".field-name-field-image a" will convert any link inside a class="field-name-field-image" element'),
  );

  // Display image style settings if the image module is available
  if (module_exists('image') == TRUE) {

    // Create a list of the currently available image styles
    $image_styles = image_styles();
    $available_themes = array();
    foreach ($image_styles as $style => $properties) {
      $available_image_styles[$style] = $properties['name'];
    }

    // Image Style
    $options['images'] = array(
      '#type' => 'fieldset',
      '#title' => t('Image Styles'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $options['images']['image_style'] = array(
      '#type' => 'checkbox',
      '#title' => t('Use image styles to generate carousel images'),
      '#default_value' => $settings['images']['image_style'],
      '#description' => t('Easily modify, scale, crop and apply various effects to carouselr images using <a href="@image-styles">Image styles</a>.', array(
        '@image-styles' => '/admin/config/media/image-styles',
      )),
    );
    $options['images']['image_style_carousel'] = array(
      '#type' => 'select',
      '#title' => t('carousel image style'),
      '#options' => $available_image_styles,
      '#default_value' => $settings['images']['image_style_carousel'],
      '#description' => t('Select an image style to apply to carousel images.'),
      '#states' => array(
        'visible' => array(
          ':input[name="carousel_carouselr_image_style"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $options['images']['image_style_thumb'] = array(
      '#type' => 'select',
      '#title' => t('Tumbnail image style'),
      '#options' => $available_image_styles,
      '#default_value' => $settings['images']['image_style_thumb'],
      '#description' => t('Select an image style to apply to carousel thumbnail images.'),
      '#states' => array(
        'visible' => array(
          ':input[name="carousel_carouselr_image_style"]' => array(
            'checked' => TRUE,
          ),
        ),
      ),
    );
    $options['images']['image_caption'] = array(
      '#type' => 'checkbox',
      '#title' => t('Show captions on carouselr images'),
      '#default_value' => $settings['images']['image_caption'],
      '#description' => t('Take de alt attribute from images and show them as captions on images'),
    );
  }

  // Navigation
  $options['navigation'] = array(
    '#type' => 'fieldset',
    '#title' => t('Navigation'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $options['navigation']['pause_on_hover'] = array(
    '#type' => 'select',
    '#title' => t('Pause animation when hovering over the carousel'),
    '#default_value' => $settings['navigation']['pause_on_hover'],
    '#description' => t('Disable carousel transitions while the user is hovering over the carousel.'),
    '#options' => array(
      'false' => t('No pause'),
      'hover' => t('Pause on hover'),
    ),
  );
  $options['navigation']['directional_navigation'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display directional navigation'),
    '#default_value' => $settings['navigation']['directional_navigation'],
    '#description' => t('Display navigation buttons to go back to the previous carousel and move forward to the next carousel.'),
  );
  $options['navigation']['image_navigation'] = array(
    '#type' => 'checkbox',
    '#title' => t('Replaces text navigation with arrows'),
    '#default_value' => $settings['navigation']['image_navigation'],
    '#description' => t('Overrides the text for previous/next navigation with arrows'),
    '#states' => array(
      'visible' => array(
        ':input[name="carousel_carouselr_directional_navigation"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $options['navigation']['previous_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Previous button text'),
    '#default_value' => $settings['navigation']['previous_text'],
    '#states' => array(
      'visible' => array(
        ':input[name="carousel_carouselr_directional_navigation"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $options['navigation']['next_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Next button text'),
    '#default_value' => $settings['navigation']['next_text'],
    '#states' => array(
      'visible' => array(
        ':input[name="carousel_carouselr_directional_navigation"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $options['navigation']['control_navigation'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display control navigation'),
    '#default_value' => $settings['navigation']['control_navigation'],
    '#description' => t('Display navigation buttons to select an individual carousel.'),
  );
  $options['navigation']['control_nav_thumbs'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use thumbnails for control navigation'),
    '#default_value' => $settings['navigation']['control_nav_thumbs'],
    '#description' => t('Use thumbnails of each carousel as control navigation buttons. In order for thumbnails to be displayed, a compatible theme is required.'),
    '#states' => array(
      'visible' => array(
        ':input[name="carousel_carouselr_control_navigation"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $options['navigation']['wrap'] = array(
    '#type' => 'checkbox',
    '#title' => t('Whether the carousel should cycle continuously or have hard stops.'),
    '#description' => t('If this option in checked, the corousel will continue on first carousel after reaching last and viceversa.'),
    '#default_value' => $settings['navigation']['wrap'],
  );
  $options['navigation']['pause_time'] = array(
    '#type' => 'textfield',
    '#title' => t('Pause time'),
    '#maxlength' => 6,
    '#size' => 6,
    '#default_value' => $settings['navigation']['pause_time'],
    '#description' => t('Enter a time in milliseconds. The pause time determines how long each carousel is displayed before transitioning to the next carousel.'),
    '#field_suffix' => t('ms'),
    '#states' => array(
      'visible' => array(
        ':input[name="carousel_carouselr_manual_advance"]' => array(
          'checked' => FALSE,
        ),
      ),
    ),
  );

  // Per-path visibility.
  $options['visibility'] = array(
    '#type' => 'fieldset',
    '#title' => t('Pages'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $options['visibility']['visibility'] = array(
    '#type' => 'radios',
    '#title' => t('Activate on specific pages'),
    '#options' => array(
      0 => t('All pages except those listed'),
      1 => t('Only the listed pages'),
    ),
    '#default_value' => $settings['visibility']['visibility'],
  );
  $options['visibility']['pages'] = array(
    '#type' => 'textarea',
    '#title' => 'List of pages to avtivate',
    '#default_value' => $settings['visibility']['pages'],
    '#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array(
      '%blog' => 'blog',
      '%blog-wildcard' => 'blog/*',
      '%front' => '<front>',
    )),
  );
  $options['#tree'] = TRUE;
  $form['twitter_bootstrap_modal_carousel_settings'] = $options;

  // Disable automatic defaults, which don't work with nested values.
  return system_settings_form($form, FALSE);
}