You are here

fractionslider.module in Views FractionSlider 7.2

Same filename and directory in other branches
  1. 8 fractionslider.module

Module file.

File

fractionslider.module
View source
<?php

/**
 * @file
 * Module file.
 */

/**
 * Implements hook_libraries_info().
 */
function fractionslider_libraries_info() {
  $libraries['fractionslider'] = array(
    'name' => 'FractionSlider',
    'vendor url' => 'http://jacksbox.de/stuff/jquery-fractionslider/',
    'download url' => 'http://jacksbox.de/downloads/fractionslider.zip',
    'library path' => drupal_get_path('module', 'fractionslider') . '/library/FractionSlider',
    'version arguments' => array(
      'file' => 'jquery.fractionslider.js',
      'pattern' => '@(?:Fraction Slider)?([0-9\\.]+)@',
    ),
    'files' => array(
      'js' => array(
        'jquery.fractionslider.js',
      ),
    ),
  );
  return $libraries;
}

/**
 * Implements hook_init().
 */
function fractionslider_init() {
  if (fractionslider_exclude_these_paths() != 1) {
    libraries_load('fractionslider');
  }
}

/**
 * Helper function to get pages to load JS plugin.
 */
function fractionslider_exclude_these_paths() {
  $action = variable_get('fractionslider_page_init_action', 'page_enable');
  $page_list = variable_get('fractionslider_page_list', '');
  if (!empty($page_list) && $action != 'page_enable') {

    // Retrieve Drupal alias for the current path (if exists).
    $alias = drupal_get_path_alias($_GET['q']);
    if (drupal_match_path($_GET['q'], $page_list) || drupal_match_path($alias, $page_list)) {
      return $action == 'page_enable' ? 1 : 0;
    }
  }
  return $action == 'page_enable' ? 0 : 1;
}

/**
 * Implements hook_menu().
 */
function fractionslider_menu() {
  $items = array();
  $items['admin/config/user-interface/fractionslider'] = array(
    'title' => 'FractionSlider',
    'description' => 'Configuration for FractionSlider',
    'page callback' => 'drupal_get_form',
    'page arguments' => array(
      'fractionslider_form',
    ),
    'access arguments' => array(
      'access fractionslider content',
    ),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}

/**
 * Implements hook_permission().
 */
function fractionslider_permission() {
  return array(
    'access fractionslider content' => array(
      'title' => t('Access FractionSlider for Customize.'),
    ),
  );
}

/**
 * Fractionslider configuration form.
 */
function fractionslider_form($form, &$form_state) {
  $page_options = array(
    'page_enable' => t('Load on all pages of site.'),
    'page_disable' => t('Load on only the listed pages.'),
  );
  $form['fractionslider_page_init_action'] = array(
    '#type' => 'radios',
    '#options' => $page_options,
    '#title' => t('Enable fractionslider on specific pages'),
    '#default_value' => variable_get('fractionslider_page_init_action', 'page_enable'),
  );
  $form['fractionslider_page_list'] = array(
    '#type' => 'textarea',
    '#title' => t('Pages'),
    '#description' => t('List one page per line as Drupal paths.  The * character is a wildcard.  Example paths are "node/add/page" and "node/add/*".  Use &lt;front&gt; to match the front page. Empty value will be considered sitewide.'),
    '#default_value' => variable_get('fractionslider_page_list', ''),
    '#states' => array(
      'invisible' => array(
        ':input[name="fractionslider_page_init_action"]' => array(
          'value' => 'page_enable',
        ),
      ),
    ),
  );
  return system_settings_form($form);
}

/**
 * Implements hook_block_info().
 */
function fractionslider_block_info() {
  $blocks['fractionslider'] = array(
    'info' => t('FractionSlider'),
    'cache' => DRUPAL_NO_CACHE,
  );
  return $blocks;
}

/**
 * Implements hook_block_configure().
 */
function fractionslider_block_configure($delta = '') {
  $form = array();
  if ($delta == 'fractionslider') {
    $path = '/' . drupal_get_path('module', 'fractionslider');
    $slider = '<div class="slider-wrapper">
    <div class="responisve-container">
      <div class="slider">
        <div class="fs_loader"></div>
        <div class="slide"> <img src="' . $path . '/images/01_box_top.png" width="361" height="354" data-position="-152,142" data-in="left" data-delay="200" data-out="right"> <img src="' . $path . '/images/01_box_bottom.png"  width="422" height="454"  data-position="138,-152" data-in="bottomRight" data-delay="200"> <img src="' . $path . '/images/01_waves.png"  width="1449" height="115" data-position="240,17" data-in="left" data-delay="" data-out="left"> <img src="' . $path . '/images/01_outofthebox.png"  data-position="20,330" data-in="bottomLeft" data-delay="500" data-out="fade" style="width:auto; height:auto">
          <p class="claim light-green" data-position="30,30" data-in="top" data-step="1" data-out="top">jQuery FractionSlider</p>
          <p class="teaser orange" data-position="90,30" data-in="left" data-step="2" data-delay="500">animate multiple elements</p>
          <p class="teaser green" data-position="90,30" data-in="left" data-step="2" data-special="cycle" data-delay="3000">full control over each element</p>
          <p class="teaser turky" data-position="90,30" data-in="left" data-step="2" data-special="cycle" data-delay="5500" data-out="none">opensource and free</p>
        </div>
        <div class="slide" data-in="slideLeft"> <img src="' . $path . '/images/02_big_boxes.png"  data-fixed data-position="25,445" data-in="fade" data-delay="0" data-out="right"> <img src="' . $path . '/images/02_small_boxes.png" data-position="80,220" data-in="fade" data-delay="500" data-out="bottomRight"> <img src="' . $path . '/images/01_box_bottom.png"  data-position="138,-152" data-in="bottomRight" data-delay="200" data-out="bottomRight">
          <p class="claim light-green small"  data-position="30,30" data-in="top" data-step="1" data-out="top">What to expect</p>
          <p class="teaser turky small" data-position="90,30" data-in="bottom" data-step="2" data-delay="500">unlimited elements</p>
          <p class="teaser turky small" data-position="120,30" data-in="bottom" data-step="2" data-delay="1500">many transitions</p>
          <p class="teaser turky small" data-position="150,30" data-in="bottom" data-step="2" data-delay="2500">unlimited slides</p>
          <p class="teaser turky small" data-position="180,30" data-in="bottom" data-step="2" data-delay="3500">background animation</p>
          <p class="teaser turky small" data-position="210,30" data-in="bottom" data-step="2" data-delay="4500">easy to use</p>
        </div>
      </div>
    </div>
  </div>';
    $form['fractionslider_markup'] = array(
      '#title' => t('FractionSlider HTML'),
      '#type' => 'textarea',
      '#rows' => 25,
      '#description' => t('This is what HTML structure for FractionSlider. Change elements/text under < div class="slide"> to see changes.'),
      '#default_value' => variable_get('fractionslider_markup', $slider),
    );
    $form['fractionslider_controls'] = array(
      '#type' => 'select',
      '#title' => t('Controls'),
      '#options' => array(
        'false' => t('False'),
        'true' => t('True'),
      ),
      '#default_value' => variable_get('fractionslider_controls', 'true'),
      '#description' => t('Controls on/off'),
    );
    $form['fractionslider_pager'] = array(
      '#type' => 'select',
      '#title' => t('Pager'),
      '#options' => array(
        'false' => t('False'),
        'true' => t('True'),
      ),
      '#default_value' => variable_get('fractionslider_pager', 'true'),
      '#description' => t("Pager inside of the slider on/off."),
    );
    $form['fractionslider_dimensions'] = array(
      '#type' => 'textfield',
      '#title' => t('Dimensions'),
      '#default_value' => variable_get('fractionslider_dimensions', '1000, 400'),
      '#description' => t('Default: 1000, 400'),
    );
    $form['fractionslider_fullwidth'] = array(
      '#type' => 'select',
      '#title' => t('Full width'),
      '#options' => array(
        'false' => t('False'),
        'true' => t('True'),
      ),
      '#default_value' => variable_get('fractionslider_fullwidth', 'true'),
      '#description' => t('Transition over the full width of the window. Default: false'),
    );
    $form['fractionslider_responsive'] = array(
      '#type' => 'select',
      '#title' => t('Responsive'),
      '#options' => array(
        'false' => t('False'),
        'true' => t('True'),
      ),
      '#default_value' => variable_get('fractionslider_responsive', 'true'),
      '#description' => t('Default: true'),
    );
    $form['fractionslider_increase'] = array(
      '#type' => 'select',
      '#title' => t('Increase'),
      '#options' => array(
        'false' => t('False'),
        'true' => t('True'),
      ),
      '#default_value' => variable_get('fractionslider_increase', 'false'),
      '#description' => t('If set, slider is allowed to get bigger than basic dimensions. Default: false'),
    );
    $form['fractionslider_autochange'] = array(
      '#type' => 'select',
      '#title' => t('Auto Change'),
      '#options' => array(
        'true' => t('True'),
        'false' => t('False'),
      ),
      '#default_value' => variable_get('fractionslider_autochange', 'true'),
      '#description' => t('Auto change slides. Default: true'),
    );
  }
  return $form;
}

/**
 * Implements hook_block_save().
 */
function fractionslider_block_save($delta = '', $edit = array()) {
  if ($delta == 'fractionslider') {
    variable_set('fractionslider_markup', $edit['fractionslider_markup']);
    variable_set('fractionslider_controls', $edit['fractionslider_controls']);
    variable_set('fractionslider_pager', $edit['fractionslider_pager']);
    variable_set('fractionslider_dimensions', $edit['fractionslider_dimensions']);
    variable_set('fractionslider_fullwidth', $edit['fractionslider_fullwidth']);
    variable_set('fractionslider_responsive', $edit['fractionslider_responsive']);
    variable_set('fractionslider_increase', $edit['fractionslider_increase']);
    variable_set('fractionslider_autochange', $edit['fractionslider_autochange']);
  }
}

/**
 * Implements hook_block_view().
 */
function fractionslider_block_view($delta = '') {
  switch ($delta) {
    case 'fractionslider':
      $fraction = variable_get('fractionslider_markup');
      $control = variable_get('fractionslider_controls');
      $pager = variable_get('fractionslider_pager');
      $dimensions = variable_get('fractionslider_dimensions');
      $fullwidth = variable_get('fractionslider_fullwidth');
      $responsive = variable_get('fractionslider_responsive');
      $increase = variable_get('fractionslider_increase');
      $autochange = variable_get('fractionslider_autochange');
      libraries_load('fractionslider');
      drupal_add_js(array(
        'fractionslider' => array(
          'controls' => $control,
          'pager' => $pager,
          'dimensions' => $dimensions,
          'fullwidth' => $fullwidth,
          'responsive' => $responsive,
          'increase' => $increase,
          'autochange' => $autochange,
        ),
      ), 'setting');
      $block['subject'] = t('FractionSlider');
      $block['content'] = $fraction;
      return $block;
  }
}