View source
<?php
define("FLEXSLIDER_COMPATIBLE_MAJOR_VERSION", '2');
define("FLEXSLIDER_DEBUG", variable_get('flexslider_debug', FALSE));
function flexslider_libraries_info() {
$libraries['flexslider'] = array(
'name' => 'FlexSlider',
'vendor url' => 'http://www.woothemes.com/flexslider/',
'download url' => 'https://github.com/woothemes/FlexSlider',
'version arguments' => array(
'file' => 'jquery.flexslider.js',
'pattern' => '/jQuery FlexSlider v([0-9a-zA-Z\\.-]+)/',
'lines' => 2,
),
'files' => array(
'js' => array(
'jquery.flexslider-min.js',
),
'css' => array(
'flexslider.css',
),
),
'integration files' => array(
'flexslider' => array(
'css' => array(
'assets/css/flexslider_img.css',
),
),
),
);
return $libraries;
}
function flexslider_libraries_info_alter(&$libraries) {
$debug = variable_get('flexslider_debug', FALSE);
if ($debug) {
if (isset($libraries['flexslider'])) {
$libraries['flexslider']['files']['js'] = array(
'jquery.flexslider.js',
);
}
}
if (module_exists('jqeasing')) {
$libraries['flexslider']['dependencies'][] = 'easing (>=1.3)';
}
}
function flexslider_library() {
$module_path = drupal_get_path('module', 'flexslider');
$library = libraries_detect('flexslider');
$libraries['flexslider'] = array(
'title' => $library['name'],
'website' => $library['vendor url'],
'version' => $library['version'],
'js' => array(
$library['library path'] . '/' . key($library['files']['js']) => array(
'scope' => 'footer',
),
),
'css' => array(
$library['library path'] . '/' . key($library['files']['css']) => array(
'type' => 'file',
'media' => 'screen',
),
$module_path . key($library['integration files']['flexslider']['css']) => array(
'type' => 'file',
'media' => 'screen',
),
),
);
return $libraries;
}
function flexslider_library_alter(&$libraries, $module) {
if (FLEXSLIDER_DEBUG) {
if ($module == 'flexslider' and isset($libraries['flexslider'])) {
$libraries['flexslider']['js'] = array(
libraries_get_path() . '/jquery.flexslider.js' => array(
'scope' => 'footer',
),
);
}
}
}
function flexslider_permission() {
return array(
'administer flexslider' => array(
'title' => t('Administer the FlexSlider module'),
),
);
}
function flexslider_menu() {
$items = array();
$items['admin/config/media/flexslider/advanced'] = array(
'title' => 'Advanced settings',
'description' => 'Configure the advanced flexslider module settings.',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'flexslider_form_settings',
),
'access arguments' => array(
'administer flexslider',
),
'type' => MENU_LOCAL_TASK,
'weight' => 2,
'file' => 'flexslider.admin.inc',
);
return $items;
}
function flexslider_help($path, $arg) {
switch ($path) {
case 'admin/config/media/flexslider/edit/%':
return '<p>' . t('An <em>option set</em> defines exactly how a flexslider image gallery looks like on your site. ' . 'It is s a combination of <a href="@styles">image styles</a> for the various image sizes and FlexSlider library options.', array(
'@styles' => url('admin/config/media/image-styles'),
)) . '<br />' . t('For a full documentation of all options, refer to the official @docs.', array(
'@docs' => l(t('FlexSlider documentation'), 'http://www.woothemes.com/flexslider/'),
)) . '</p>';
}
}
function flexslider_theme() {
return array(
'flexslider' => array(
'variables' => array(
'items' => array(),
'settings' => array(),
),
'template' => 'theme/flexslider',
'file' => 'theme/flexslider.theme.inc',
),
'flexslider_list' => array(
'variables' => array(
'items' => array(),
'settings' => array(),
),
'file' => 'theme/flexslider.theme.inc',
),
'flexslider_list_item' => array(
'variables' => array(
'item' => array(),
'settings' => array(),
'caption' => '',
),
'file' => 'theme/flexslider.theme.inc',
),
);
}
function flexslider_image_default_styles() {
$styles = array();
$styles['flexslider_full'] = array(
'effects' => array(
array(
'name' => 'image_scale_and_crop',
'data' => array(
'width' => 800,
'height' => 500,
),
'weight' => 0,
),
),
);
$styles['flexslider_thumbnail'] = array(
'effects' => array(
array(
'name' => 'image_scale_and_crop',
'data' => array(
'width' => 160,
'height' => 100,
),
'weight' => 0,
),
),
);
return $styles;
}
function flexslider_ctools_plugin_api($owner, $api) {
if ($owner == 'flexslider' && $api == 'flexslider_default_preset') {
return array(
'version' => 1,
);
}
}
function flexslider_ctools_plugin_directory($module, $type) {
if ($type == 'export_ui') {
return 'plugins/export_ui';
}
}
function flexslider_optionset_create($values = array()) {
ctools_include('export');
$optionset = ctools_export_crud_new('flexslider_optionset');
$optionset->options = array();
if (isset($values['name'])) {
$optionset->name = $values['name'];
}
if (isset($values['title'])) {
$optionset->title = $values['title'];
}
if (isset($values['options']) and is_array($values['options'])) {
$optionset->options = $values['options'];
}
$optionset_defaults = _flexslider_optionset_defaults();
$optionset->options = $optionset->options + $optionset_defaults;
return $optionset;
}
function flexslider_optionset_load_all() {
ctools_include('export');
$optionsets = ctools_export_crud_load_all('flexslider_optionset');
foreach ($optionsets as $optionset) {
_flexslider_typecast_optionset($optionset->options);
}
return $optionsets;
}
function flexslider_optionset_load($optionset_name) {
ctools_include('export');
$optionset = ctools_export_crud_load('flexslider_optionset', $optionset_name);
_flexslider_typecast_optionset($optionset->options);
return $optionset;
}
function flexslider_optionset_exists($optionset_name) {
ctools_include('export');
$optionset = ctools_export_crud_load('flexslider_optionset', $optionset_name);
return isset($optionset->name);
}
function flexslider_optionset_save($optionset, $new = FALSE) {
if (empty($optionset->name) or FALSE != flexslider_optionset_exists($optionset->name) and $new) {
return FALSE;
}
if (isset($optionset->options) and !is_array($optionset->options)) {
return FALSE;
}
if (empty($optionset->title)) {
$optionset->title = $optionset->name;
}
$optionset_defaults = _flexslider_optionset_defaults();
$optionset->options = $optionset->options + $optionset_defaults;
_flexslider_typecast_optionset($optionset->options);
$db_values = array(
'name' => $optionset->name,
'title' => $optionset->title,
'options' => $optionset->options,
);
if ($new) {
$result = drupal_write_record('flexslider_optionset', $db_values);
}
else {
$result = drupal_write_record('flexslider_optionset', $db_values, 'name');
}
if ($new and SAVED_NEW == $result or !$new and SAVED_UPDATED == $result) {
return $optionset;
}
return FALSE;
}
function flexslider_optionset_delete($optionset) {
if (!$optionset) {
return;
}
elseif (!isset($optionset->name)) {
$optionset = flexslider_optionset_load($optionset);
}
ctools_include('export');
ctools_export_crud_delete('flexslider_optionset', $optionset);
ctools_export_load_object_reset('flexslider_optionset');
}
function flexslider_add($id = NULL, $optionset = NULL) {
if (is_string($optionset)) {
$name = $optionset;
$optionset = flexslider_optionset_load($name);
if (empty($optionset)) {
watchdog('flexslider', 'Invalid optionset name supplied to flexslider_add: @name', array(
'@name' => $name,
), WATCHDOG_WARNING);
return;
}
}
$cache =& drupal_static(__FUNCTION__, array());
libraries_load('flexslider');
if (!empty($optionset) && !in_array($optionset->name, $cache)) {
$cache[] = $optionset->name;
$js_setting['optionsets'] = array(
$optionset->name => $optionset->options,
);
drupal_add_js(array(
'flexslider' => $js_setting,
), 'setting');
}
if (!empty($id)) {
$js_settings = array(
'instances' => array(
$id => $optionset->name,
),
);
drupal_add_js(array(
'flexslider' => $js_settings,
), 'setting');
}
drupal_add_js(drupal_get_path('module', 'flexslider') . '/assets/js/flexslider.load.js', array(
'type' => 'file',
'scope' => 'footer',
));
}
function _flexslider_optionset_defaults($key = NULL) {
$defaults = array(
'namespace' => 'flex-',
'selector' => '.slides > li',
'easing' => 'swing',
'direction' => 'horizontal',
'reverse' => FALSE,
'smoothHeight' => FALSE,
'startAt' => 0,
'animationSpeed' => 600,
'initDelay' => 0,
'useCSS' => TRUE,
'touch' => TRUE,
'video' => FALSE,
'keyboard' => TRUE,
'multipleKeyboard' => FALSE,
'mousewheel' => FALSE,
'controlsContainer' => '.flex-control-nav-container',
'sync' => '',
'asNavFor' => '',
'itemWidth' => 0,
'itemMargin' => 0,
'minItems' => 0,
'maxItems' => 0,
'move' => 0,
'animation' => 'fade',
'slideshow' => TRUE,
'slideshowSpeed' => 7000,
'directionNav' => TRUE,
'controlNav' => TRUE,
'prevText' => t('Previous'),
'nextText' => t('Next'),
'pausePlay' => FALSE,
'pauseText' => t('Pause'),
'playText' => t('Play'),
'randomize' => FALSE,
'thumbCaptions' => FALSE,
'thumbCaptionsBoth' => FALSE,
'animationLoop' => TRUE,
'pauseOnAction' => TRUE,
'pauseOnHover' => FALSE,
'manualControls' => '',
);
_flexslider_typecast_optionset($defaults);
if (isset($key) and array_key_exists($key, $defaults)) {
return $defaults[$key];
}
return $defaults;
}
function _flexslider_typecast_optionset(&$options) {
if (isset($options) && !empty($options)) {
foreach ($options as $key => $value) {
switch ($key) {
case 'namespace':
case 'selector':
case 'easing':
case 'direction':
case 'controlsContainer':
case 'sync':
case 'asNavFor':
case 'fade':
case 'prevText':
case 'nextText':
case 'pauseText':
case 'playText':
case 'manualControls':
$options[$key] = (string) $value;
break;
case 'startAt':
case 'animationSpeed':
case 'initDelay':
case 'itemWidth':
case 'itemMargin':
case 'minItems':
case 'maxItems':
case 'move':
$options[$key] = (int) $value;
break;
case 'controlNav':
if ($value == 'thumbnails') {
$options[$key] = (string) $value;
break;
}
case 'reverse':
case 'smoothHeight':
case 'useCSS':
case 'touch':
case 'video':
case 'keyboard':
case 'multipleKeyboard':
case 'mouseWheel':
case 'slideshow':
case 'directionNav':
case 'pausePlay':
case 'randomize':
case 'thumbCaptions':
case 'thumbCaptionsBoth':
case 'animationLoop':
case 'pauseOnAction':
case 'pauseOnHover':
$options[$key] = (bool) $value;
break;
}
}
}
}
function _flexslider_jqeasing_options() {
return array(
"jswing" => "jswing",
"def" => "def",
"easeInQuad" => "easeInQuad",
"easeOutQuad" => "easeOutQuad",
"easeInOutQuad" => "easeInOutQuad",
"easeInCubic" => "easeInCubic",
"easeOutCubic" => "easeOutCubic",
"easeInOutCubic" => "easeInOutCubic",
"easeInQuart" => "easeInQuart",
"easeOutQuart" => "easeOutQuart",
"easeInOutQuart" => "easeInOutQuart",
"easeInQuint" => "easeInQuint",
"easeOutQuint" => "easeOutQuint",
"easeInOutQuint" => "easeInOutQuint",
"easeInSine" => "easeInSine",
"easeOutSine" => "easeOutSine",
"easeInOutSine" => "easeInOutSine",
"easeInExpo" => "easeInExpo",
"easeOutExpo" => "easeOutExpo",
"easeInOutExpo" => "easeInOutExpo",
"easeInCirc" => "easeInCirc",
"easeOutCirc" => "easeOutCirc",
"easeInOutCirc" => "easeInOutCirc",
"easeInElastic" => "easeInElastic",
"easeOutElastic" => "easeOutElastic",
"easeInOutElastic" => "easeInOutElastic",
"easeInBack" => "easeInBack",
"easeOutBack" => "easeOutBack",
"easeInOutBack" => "easeInOutBack",
"easeInBounce" => "easeInBounce",
"easeOutBounce" => "easeOutBounce",
"easeInOutBounce" => "easeInOutBounce",
);
}