twitter_bootstrap_modal_nivo.module in Twitter Bootstrap Modal 7.3
Generates a Twitter Bootstrap Modal with images slide.
Depends on the jQuery Ajax Load Modules
File
twitter_bootstrap_modal_nivo/twitter_bootstrap_modal_nivo.moduleView source
<?php
/**
* @file
* Generates a Twitter Bootstrap Modal with images slide.
*
* Depends on the jQuery Ajax Load Modules
*/
/**
* Implements hook_init().
*/
function twitter_bootstrap_modal_nivo_init() {
$settings = variable_get('twitter_bootstrap_modal_nivo_settings');
if (twitter_bootstrap_modal_nivo_check_path($settings['visibility']['visibility'], $settings['visibility']['pages'])) {
if (($library = libraries_load('nivo-slider')) && !empty($library['loaded'])) {
$module_path = drupal_get_path('module', 'twitter_bootstrap_modal_nivo');
drupal_add_js(array(
'twitter_bootstrap_modal_nivo' => array(
'module_path' => $module_path,
'trigger' => $settings['trigger'],
'caption' => $settings['images']['image_caption'],
'effect' => $settings['effects']['effect'],
'slices' => $settings['effects']['effect_properties']['slices'],
'box_columns' => $settings['effects']['effect_properties']['box_columns'],
'box_rows' => $settings['effects']['effect_properties']['box_rows'],
'speed' => $settings['effects']['speed'],
'pause_on_hover' => $settings['effects']['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'],
'manual_advance' => $settings['navigation']['manual_advance'],
'pause_time' => $settings['navigation']['pause_time'],
),
), 'setting');
drupal_add_js($module_path . '/twitter_bootstrap_modal_nivo.js');
drupal_add_css($module_path . '/twitter_bootstrap_modal_nivo.css');
}
else {
$error = $library['error'];
// This contains a detailed (localized) error message.
$error_message = $library['error message'];
drupal_set_message($error_message, 'warning');
}
}
}
/**
* Implementation of hook_menu().
*/
function twitter_bootstrap_modal_nivo_menu() {
// Admin settings.
$items['admin/config/development/twitter_bootstrap_modal/TB_Nivo'] = array(
'title' => 'Twitter Bootstrap Modal Nivo',
'description' => 'Shows a slide of images on a Twitter Boostrap AJAX Modal',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'twitter_bootstrap_modal_nivo_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_nivo_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_nivo_settings($form, &$form_state) {
$settings = variable_get('twitter_bootstrap_modal_nivo_settings');
$options['trigger'] = array(
'#type' => 'textarea',
'#title' => t('Valid jQuery Classes/IDs to trigger TB Nivo 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 ".twitter_bootstrap_modal_nivo" will convert any link with class="twitter_bootstrap_modal_nivo"'),
);
// 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 slider images'),
'#default_value' => $settings['images']['image_style'],
'#description' => t('Easily modify, scale, crop and apply various effects to slider images using <a href="@image-styles">Image styles</a>.', array(
'@image-styles' => '/admin/config/media/image-styles',
)),
);
$options['images']['image_style_slide'] = array(
'#type' => 'select',
'#title' => t('Slide image style'),
'#options' => $available_image_styles,
'#default_value' => $settings['images']['image_style_slide'],
'#description' => t('Select an image style to apply to slide images.'),
'#states' => array(
'visible' => array(
':input[name="nivo_slider_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 slide thumbnail images.'),
'#states' => array(
'visible' => array(
':input[name="nivo_slider_image_style"]' => array(
'checked' => TRUE,
),
),
),
);
$options['images']['image_caption'] = array(
'#type' => 'checkbox',
'#title' => t('Show captions on slider images'),
'#default_value' => $settings['images']['image_caption'],
'#description' => t('Take de alt attribute from images and show them as captions on images'),
);
}
// Effects
$options['effects'] = array(
'#type' => 'fieldset',
'#title' => t('Effects'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$options['effects']['effect'] = array(
'#type' => 'select',
'#title' => t('Effect'),
'#options' => array(
'sliceDown' => t('Slice Down'),
'sliceDownLeft' => t('Slice Down Left'),
'sliceUp' => t('Slice Up'),
'sliceUpLeft' => t('Slice Up Left'),
'sliceUpDown' => t('Slice Up Down'),
'sliceUpDownLeft' => t('Slice Up Down Left'),
'fold' => t('Fold'),
'fade' => t('Fade'),
'random' => t('Random'),
'slideInRight' => t('Slide In Right'),
'slideInLeft' => t('Slide in Left'),
'boxRandom' => t('Box Random'),
'boxRain' => t('Box Rain'),
'boxRainReverse' => t('Box Rain Reverse'),
'boxRainGrow' => t('Box Rain Grow'),
'boxRainGrowReverse' => t('Box Rain Grow Reverse'),
),
'#default_value' => $settings['effects']['effect'],
'#description' => t('Select an effect. The chosen effect will be used to transition between slides.'),
);
$options['effects']['effect_properties'] = array(
'#type' => 'fieldset',
'#title' => t('Effect properties'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$options['effects']['effect_properties']['slices'] = array(
'#type' => 'textfield',
'#title' => t('Slices'),
'#maxlength' => 3,
'#size' => 3,
'#default_value' => $settings['effects']['effect_properties']['slices'],
'#description' => t('Used for slice animations.'),
'#field_suffix' => t('Slices'),
'#states' => array(
'visible' => array(
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'sliceDown',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'sliceDownLeft',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'sliceUp',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'sliceUpLeft',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'sliceUpDown',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'sliceUpDownLeft',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'fold',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'fade',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'random',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'slideInRight',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'slideInLeft',
),
),
),
),
);
$options['effects']['effect_properties']['box_columns'] = array(
'#type' => 'textfield',
'#title' => t('Box columns'),
'#maxlength' => 3,
'#size' => 3,
'#default_value' => $settings['effects']['effect_properties']['box_columns'],
'#description' => t('Used for box animations.'),
'#field_suffix' => t('Columns'),
'#states' => array(
'visible' => array(
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'boxRandom',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'boxRain',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'boxRainReverse',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'boxRainGrow',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'boxRainGrowReverse',
),
),
),
),
);
$options['effects']['effect_properties']['box_rows'] = array(
'#type' => 'textfield',
'#title' => t('Box rows'),
'#maxlength' => 3,
'#size' => 3,
'#default_value' => $settings['effects']['effect_properties']['box_rows'],
'#description' => t('Used for box animations.'),
'#field_suffix' => t('Rows'),
'#states' => array(
'visible' => array(
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'boxRandom',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'boxRain',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'boxRainReverse',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'boxRainGrow',
),
),
array(
':input[name="nivo_slider_effect"]' => array(
'value' => 'boxRainGrowReverse',
),
),
),
),
);
$options['effects']['speed'] = array(
'#type' => 'textfield',
'#title' => t('Animation speed'),
'#maxlength' => 6,
'#size' => 6,
'#default_value' => $settings['effects']['speed'],
'#description' => t('Enter a time in milliseconds. The animation speed determines how long it takes to transition from one slide to the next.'),
'#field_suffix' => t('ms'),
);
$options['effects']['pause_on_hover'] = array(
'#type' => 'checkbox',
'#title' => t('Pause animation when hovering over the slide'),
'#default_value' => $settings['effects']['pause_on_hover'],
'#description' => t('Disable slide transitions while the user is hovering over the slide.'),
);
// Navigation
$options['navigation'] = array(
'#type' => 'fieldset',
'#title' => t('Navigation'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$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 slide and move forward to the next slide.'),
);
$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="nivo_slider_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="nivo_slider_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="nivo_slider_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 slide.'),
);
$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 slide as control navigation buttons. In order for thumbnails to be displayed, a compatible theme is required.'),
'#states' => array(
'visible' => array(
':input[name="nivo_slider_control_navigation"]' => array(
'checked' => TRUE,
),
),
),
);
$options['navigation']['manual_advance'] = array(
'#type' => 'checkbox',
'#title' => t('Disable automatic slide transitions'),
'#default_value' => $settings['navigation']['manual_advance'],
'#description' => t('For the use to manually navigate between slides.'),
);
$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 slide is displayed before transitioning to the next slide.'),
'#field_suffix' => t('ms'),
'#states' => array(
'visible' => array(
':input[name="nivo_slider_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_nivo_settings'] = $options;
// Disable automatic defaults, which don't work with nested values.
return system_settings_form($form, FALSE);
}Functions
|
Name |
Description |
|---|---|
| twitter_bootstrap_modal_nivo_check_path | |
| twitter_bootstrap_modal_nivo_init | Implements hook_init(). |
| twitter_bootstrap_modal_nivo_menu | Implementation of hook_menu(). |
| twitter_bootstrap_modal_nivo_settings | Module settings form. |