Active
Project:
fancyBox
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Feb 2011 at 04:34 UTC
Updated:
1 Dec 2011 at 16:32 UTC
Jump to comment: Most recent file
Hi,
I have added the possibility to group only the images of the views and not all the images on the page as in the settings.
Here are the modification I have done:
file: fanycbox.module
<?php
// $Id: fancybox.module,v 1.1.4.6 2010/10/25 23:24:19 sbacelic Exp $
/**
* @file
* Provides the Fancybox jQuery plugin for displaying images, HTML content and
* multimedia in an elegant box.
*
* Authors:
* Joakim Stai <http://drupal.org/user/88701> (Drupal 6 version)
* Nicola Sanino <http://drupal.org/user/72237> (Drupal 5 version)
*
* Sponsors:
* NodeOne <http://nodeone.se>
* Sony Ericsson <http://labs.sonyericsson.com>
*/
define('FANCYBOX_DEFAULT_PATH', 'sites/all/libraries/fancybox');
/**
* Implementation of hook_init().
*/
function fancybox_init() {
$settings = variable_get('fancybox_settings', array());
if (!empty($settings) && fancybox_active($settings)) {
fancybox_activate($settings);
}
}
/**
* Supported fancybox JS library events.
*/
function fancybox_supported_events() {
return array(
'onStart',
'onComplete',
'onClosed',
'onCleanup',
'onCancel',
);
}
/**
* Include the Fancybox JS.
*/
function fancybox_activate($settings = NULL) {
static $active = FALSE;
if (!$active) {
if ($settings == NULL) {
$settings = variable_get('fancybox_settings', array());
}
// Add Fancybox files.
$path = variable_get('fancybox_path', FANCYBOX_DEFAULT_PATH) . '/';
$files = variable_get('fancybox_files', array());
// TODO: add easing
//drupal_add_js($path .'jquery.easing-1.3.pack.js');
drupal_add_css($path . $files['css']);
drupal_add_js($path . $files['js']);
// Expose settings to the DOM.
$exposed_settings['options'] = $settings['options'];
$exposed_settings['selector'] = $settings['activation']['selector'];
// Proceed some final cleanup to avoid JS errors. If we give an JSON empty
// string to the fancybox library, it will fail trying to execute it.
foreach (fancybox_supported_events() as $event) {
if (empty($exposed_settings['options'][$event])) {
unset($exposed_settings['options'][$event]);
}
}
drupal_add_js(array('fancybox' => $exposed_settings), 'setting');
// Initialize Fancybox.
drupal_add_js(drupal_get_path('module', 'fancybox') . '/js/fancybox.js');
$active = TRUE;
}
}
/**
* Implementation of hook_perm().
*/
function fancybox_perm() {
return array('administer fancybox');
}
/**
* Implementation of hook_menu().
*/
function fancybox_menu() {
$items = array();
$base = array(
'access arguments' => array('administer fancybox'),
'file' => 'fancybox.admin.inc',
);
$items['admin/settings/fancybox'] = $base + array(
'title' => 'Fancybox',
'description' => 'Configure the settings for Fancybox.',
'page callback' => 'drupal_get_form',
'page arguments' => array('fancybox_admin_settings_form'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Implementation of hook_theme().
*/
function fancybox_theme() {
$theme = array();
$base = array('file' => 'fancybox.theme.inc');
$theme['imagefield_image_imagecache_fancybox'] = $base + array(
'arguments' => array(
'namespace' => NULL,
'field' => NULL,
'path' => NULL,
'alt' => NULL,
'title' => NULL,
'gid' => NULL,
'attributes' => NULL,
),
);
if (function_exists('imagecache_presets') && module_exists('imagefield')) {
foreach (imagecache_presets() as $preset) {
$theme['fancybox_formatter_'. $preset['presetname'] .'|fancybox'] = $base + array(
'function' => 'theme_fancybox_formatter_imagefield',
'arguments' => array('element' => NULL),
);
$theme['fancybox_formatter_'. $preset['presetname'] .'|fancybox-grouped'] = $base + array(
'function' => 'theme_fancybox_grouped_formatter_imagefield',
'arguments' => array('element' => NULL),
);
}
}
/* emvideo field support */
$theme['fancybox_formatter_emvideo_fancybox_video'] = array(
'arguments' => array('element' => NULL),
'file' => 'fancybox.theme.inc',
);
$theme['fancybox_emvideo'] = array(
'arguments' => array('field' => NULL, 'item' => NULL, 'formatter' => NULL, 'node' => NULL),
'file' => 'fancybox.theme.inc',
);
return $theme;
}
/**
* Check whether Fancybox should be initialized for the current URL.
*/
function fancybox_active($settings) {
// If PHP is selected, evaluate it.
if ($settings['activation']['activation_type'] == 'php') {
return drupal_eval($settings['activation']['activation_pages']);
}
// Compare defined paths with the current path.
$path = drupal_get_path_alias($_GET['q']);
$page_match = drupal_match_path($path, $settings['activation']['activation_pages']);
if ($path != $_GET['q']) {
$page_match = $page_match || drupal_match_path($_GET['q'], $settings['activation']['activation_pages']);
}
// Decide whether to include or exclude pages.
if ($settings['activation']['activation_type'] == 'exclude') {
return !$page_match;
}
else {
return $page_match;
}
}
/**
* Define form elements for the Fancybox plugin's options.
*/
function fancybox_options($values = array()) {
/*
Fancybox 1.3.1 options:
TODO: autoDimensions true For inline and ajax views, resizes the view to the element recieves. Make sure it has dimensions otherwise this will give unexpected results
TODO: modal false When true, 'overlayShow' is set to 'true' and 'hideOnOverlayClick', 'hideOnContentClick', 'enableEscapeButton', 'showCloseButton' are set to 'false'
TODO: ajax { } Ajax options (error, success will be overwritten)
TODO: swf {wmode: 'transparent'} Flashvars to put on the swf object
TODO: titleFormat null Callback to customize title area. You can set any html - custom image counter or even custom navigation
*/
$easing_options = array(
'none' => t('None'),
'swing' => t('Swing'),
'easeInQuad' => t('Quad in'),
'easeOutQuad' => t('Quad out'),
'easeInOutQuad' => t('Quad in/out'),
'easeInCubic' => t('Cubic in'),
'easeOutCubic' => t('Cubic out'),
'easeInOutCubic' => t('Cubic in/out'),
'easeInQuart' => t('Quart in'),
'easeOutQuart' => t('Quart out'),
'easeInOutQuart' => t('Quart in/out'),
'easeInQuint' => t('Quint in'),
'easeOutQuint' => t('Quint out'),
'easeInOutQuint' => t('Quint in/out'),
'easeInSine' => t('Sine in'),
'easeOutSine' => t('Sine out'),
'easeInOutSine' => t('Sine in/out'),
'easeInExpo' => t('Expo in'),
'easeOutExpo' => t('Expo out'),
'easeInOutExpo' => t('Expo in/out'),
'easeInCirc' => t('Circular in'),
'easeOutCirc' => t('Circular out'),
'easeInOutCirc' => t('Circular in/out'),
'easeInElastic' => t('Elastic in'),
'easeOutElastic' => t('Elastic out'),
'easeInOutElastic' => t('Elastic in/out'),
'easeInBack' => t('Back in'),
'easeOutBack' => t('Back out'),
'easeInOutBack' => t('Back in/out'),
'easeInBounce' => t('Bounce in'),
'easeOutBounce' => t('Bounce out'),
'easeInOutBounce' => t('Bounce in/out'),
);
for ($i = 0; $i <= 10; $i++) {
$float = (float) $i / 10;
$opacity_options[(string) $float] = ($i * 10) .'%';
}
$options = array();
$options['appearance'] = array(
'#type' => 'fieldset',
'#title' => t('Appearance'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$options['appearance']['width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#description' => t("Width for content types 'iframe' and 'swf'. Also set for inline content if 'autoDimensions' is set to 'false'"),
'#default_value' => isset($values['width']) ? $values['width'] : 425,
'#size' => 5
);
$options['appearance']['height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#description' => t("Height for content types 'iframe' and 'swf'. Also set for inline content if 'autoDimensions' is set to 'false'"),
'#default_value' => isset($values['height']) ? $values['height'] : 355,
'#size' => 5
);
$options['appearance']['padding'] = array(
'#type' => 'textfield',
'#title' => t('Padding'),
'#description' => t('Space between FancyBox wrapper and content'),
'#default_value' => isset($values['padding']) ? $values['padding'] : 10,
'#size' => 5
);
$options['appearance']['margin'] = array(
'#type' => 'textfield',
'#title' => t('Margin'),
'#description' => t('Space between viewport and FancyBox wrapper'),
'#default_value' => isset($values['margin']) ? $values['margin'] : 20,
'#size' => 5
);
$options['appearance']['titleShow'] = array(
'#type' => 'checkbox',
'#title' => t('Show title'),
'#description' => t('If checked, shows the title.'),
'#default_value' => isset($values['titleShow']) ? $values['titleShow'] : TRUE,
);
$options['appearance']['titlePosition'] = array(
'#type' => 'select',
'#title' => t('Title position'),
'#description' => t('The position of title.'),
'#options' => array(
'outside' => t('Outside'),
'inside' => t('Inside'),
'over' => t('Over')
),
'#default_value' => isset($values['titlePosition']) ? $values['titlePosition'] : 'outside',
);
$options['appearance']['scrolling'] = array(
'#type' => 'select',
'#title' => t('Content scrolling'),
'#description' => t('Set the overflow CSS property to create or hide scrollbars'),
'#options' => array(
'auto' => t('Auto'),
'yes' => t('Yes'),
'no' => t('No')
),
'#default_value' => isset($values['scrolling']) ? $values['scrolling'] : 'auto',
);
$options['appearance']['showCloseButton'] = array(
'#type' => 'checkbox',
'#title' => t('Show close button'),
'#description' => t('Toggle close button'),
'#default_value' => isset($values['showCloseButton']) ? $values['showCloseButton'] : TRUE,
);
$options['appearance']['showNavArrows'] = array(
'#type' => 'checkbox',
'#title' => t('Show navigation arrows'),
'#description' => t('Toggle navigation arrows'),
'#default_value' => isset($values['showNavArrows']) ? $values['showNavArrows'] : TRUE,
);
$options['appearance']['cyclic'] = array(
'#type' => 'checkbox',
'#title' => t('Cyclic'),
'#description' => t('When checked, galleries will be cyclic, allowing you to keep pressing next/back'),
'#default_value' => isset($values['cyclic']) ? $values['cyclic'] : FALSE,
);
$options['appearance']['opacity'] = array(
'#type' => 'checkbox',
'#title' => t('Opacity'),
'#description' => t('If checked, transparency of content is changed for elastic transitions'),
'#default_value' => isset($values['opacity']) ? $values['opacity'] : FALSE,
);
$options['appearance']['overlayShow'] = array(
'#type' => 'checkbox',
'#title' => t('Show overlay'),
'#description' => t('If checked, shows the overlay behind the item'),
'#default_value' => isset($values['overlayShow']) ? $values['overlayShow'] : TRUE,
);
$options['appearance']['overlayColor'] = array(
'#type' => 'textfield',
'#title' => t('Overlay color'),
'#description' => t('Color of the overlay (i.e. #666666)'),
'#default_value' => isset($values['overlayColor']) ? $values['overlayColor'] : '#666',
'#size' => 8
);
$options['appearance']['overlayOpacity'] = array(
'#type' => 'select',
'#title' => t('Overlay opacity'),
'#description' => t('Opacity of overlay (from 0% to 100%)'),
'#options' => $opacity_options,
'#default_value' => isset($values['overlayOpacity']) ? $values['overlayOpacity'] : 0.3,
);
$options['appearance']['hideOnOverlayClick'] = array(
'#type' => 'checkbox',
'#title' => t('Close on overlay click'),
'#description' => t('If checked, clicking the overlay closes FancyBox'),
'#default_value' => isset($values['hideOnOverlayClick']) ? $values['hideOnOverlayClick'] : FALSE,
);
$options['appearance']['hideOnContentClick'] = array(
'#type' => 'checkbox',
'#title' => t('Close on content click'),
'#description' => t('If checked, clicking the content closes FancyBox'),
'#default_value' => isset($values['hideOnContentClick']) ? $values['hideOnContentClick'] : TRUE,
);
$options['appearance']['enableEscapeButton'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Escape button'),
'#description' => t('If checked, pressing Esc button closes FancyBox'),
'#default_value' => isset($values['enableEscapeButton']) ? $values['enableEscapeButton'] : TRUE,
);
$options['appearance']['centerOnScroll'] = array(
'#type' => 'checkbox',
'#title' => t('Keep centered when scrolling'),
'#description' => t('If checked, item stays centered when user scrolls the page'),
'#default_value' => isset($values['centerOnScroll']) ? $values['centerOnScroll'] : TRUE,
);
$options['appearance']['autoScale'] = array(
'#type' => 'checkbox',
'#title' => t('Scale images'),
'#description' => t('If checked, FancyBox is scaled to fit in viewport'),
'#default_value' => isset($values['autoScale']) ? $values['autoScale'] : TRUE,
);
$options['effects'] = array(
'#type' => 'fieldset',
'#title' => t('Effects'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$options['effects']['easingIn'] = array(
'#type' => 'select',
'#title' => t('Easing effect on open'),
'#description' => t('Easing effect used when opening an item.'),
'#options' => $easing_options,
'#default_value' => isset($values['easingIn']) ? $values['easingIn'] : 'swing',
);
$options['effects']['easingOut'] = array(
'#type' => 'select',
'#title' => t('Easing effect on close'),
'#description' => t('Easing effect used when closing an item.'),
'#options' => $easing_options,
'#default_value' => isset($values['easingOut']) ? $values['easingOut'] : 'swing',
);
$options['effects']['changeFade'] = array(
'#type' => 'select',
'#title' => t('Change fade'),
'#description' => t('Speed of the content fading while changing gallery items'),
'#options' => array(
'fast' => t('Fast')
),
'#default_value' => isset($values['changeFade']) ? $values['changeFade'] : 'fast',
);
$options['effects']['changeSpeed'] = array(
'#type' => 'textfield',
'#title' => t('Change speed'),
'#description' => t('Speed of resizing when changing gallery items, in milliseconds'),
'#default_value' => isset($values['changeSpeed']) ? $values['changeSpeed'] : 300,
'#size' => 8
);
$options['effects']['transitionIn'] = array(
'#type' => 'select',
'#title' => t('Transition in'),
'#description' => t('The transition type'),
'#options' => array(
'elastic' => t('Elastic'),
'fade' => t('Fade'),
'none' => t('None')
),
'#default_value' => isset($values['transitionIn']) ? $values['transitionIn'] : 'fade',
);
$options['effects']['speedIn'] = array(
'#type' => 'textfield',
'#title' => t('Transition in speed'),
'#description' => t('Speed of the fade and elastic transitions, in milliseconds'),
'#default_value' => isset($values['speedIn']) ? $values['speedIn'] : 300,
'#size' => 8
);
$options['effects']['transitionOut'] = array(
'#type' => 'select',
'#title' => t('Transition out'),
'#description' => t('The transition type'),
'#options' => array(
'elastic' => t('Elastic'),
'fade' => t('Fade'),
'none' => t('None')
),
'#default_value' => isset($values['transitionOut']) ? $values['transitionOut'] : 'fade',
);
$options['effects']['speedOut'] = array(
'#type' => 'textfield',
'#title' => t('Transition out speed'),
'#description' => t('Speed of the fade and elastic transitions, in milliseconds'),
'#default_value' => isset($values['speedOut']) ? $values['speedOut'] : 300,
'#size' => 8
);
$options['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$options['advanced']['onStart'] = array(
'#type' => 'textfield',
'#title' => t('Callback on start'),
'#description' => t('Enter the name of a JavaScript function to be called right before attempting to load the content.'),
'#default_value' => isset($values['onStart']) ? $values['onStart'] : '',
);
$options['advanced']['onComplete'] = array(
'#type' => 'textfield',
'#title' => t('Callback on open'),
'#description' => t('Enter the name of a JavaScript function to be called once the content is displayed.'),
'#default_value' => isset($values['onComplete']) ? $values['onComplete'] : '',
);
$options['advanced']['onClosed'] = array(
'#type' => 'textfield',
'#title' => t('Callback on close'),
'#description' => t('Enter the name of a JavaScript function to be called once FancyBox is closed.'),
'#default_value' => isset($values['onClosed']) ? $values['onClosed'] : '',
);
$options['advanced']['onCleanup'] = array(
'#type' => 'textfield',
'#title' => t('Callback on cleanup'),
'#description' => t('Enter the name of a JavaScript function to be called just before closing.'),
'#default_value' => isset($values['onCleanup']) ? $values['onCleanup'] : '',
);
$options['advanced']['onCancel'] = array(
'#type' => 'textfield',
'#title' => t('Callback on cancel'),
'#description' => t('Enter the name of a JavaScript function to be called after loading is canceled.'),
'#default_value' => isset($values['onCancel']) ? $values['onCancel'] : '',
);
return $options;
}
/*****************************************************************************
* INTEGRATION WITH THIRD PARTY MODULES
*****************************************************************************/
/**
* Implementation of hook_field_formatter_info().
*
* Add Fancybox and ImageCache formatters to CCK image fields if Imagefield and
* ImageCache modules are enabled.
*/
function fancybox_field_formatter_info() {
$formatters = array();
if (module_exists('imagecache')) {
$presets = array();
foreach (imagecache_presets() as $preset) {
$presets[$preset['presetname'] .'|fancybox'] = array(
'label' => t('Fancybox: @preset image', array('@preset' => $preset['presetname'])),
'field types' => array('image', 'filefield'),
);
}
foreach (imagecache_presets() as $preset) {
$presets[$preset['presetname'] .'|fancybox-grouped'] = array(
'label' => t('Fancybox grouped image: @preset image', array('@preset' => $preset['presetname'])),
'field types' => array('image', 'filefield'),
);
}
if (is_array($presets)) {
$formatters = array_merge($presets);
}
}
if (module_exists('emvideo')) {
$formatters['emvideo_fancybox_video'] = array(
'label' => t('Fancybox: Image Thumbnail -> Full Size Video'),
'field types' => array('emvideo'),
);
}
return $formatters;
}
/**
* Implementation of hook_insert_styles().
*/
function fancybox_insert_styles() {
$insert_styles = array();
if (module_exists('imagecache')) {
foreach (imagecache_presets() as $preset) {
$insert_styles[$preset['presetname'].'|fancybox'] = array(
'label' => t('Fancybox: @preset image', array('@preset' => $preset['presetname']))
);
}
}
return $insert_styles;
}
/**
* Implementation of hook_insert_content().
*/
function fancybox_insert_content($item, $style, $widget) {
return fancybox_imagefield_image_imagecache(NULL, $item, $style['name'], NULL);
}
/**
* Implementation of hook_field_formatter().
*/
function fancybox_imagefield_image_imagecache($field, $item, $formatter, $node, $grouped = false) {
$settings = variable_get('fancybox_settings', array());
if ($settings['imagefield']['use_list_field'] && $item['list'] == 0) {
return null;
}
if (!isset($item['filepath']) && isset($item['fid'])) {
$file = field_file_load($item['fid']);
$item['filepath'] = $file['filepath'];
}
// Image caption.
$item_data = $item['data'];
$image_title = $item_data['description'];
$image_title = (!empty($image_title) ? $image_title : $item_data['title']);
$image_title = (!empty($image_title) ? $image_title : $item_data['alt']);
if ($settings['imagefield']['use_node_title']) {
$image_title = $node->title;
}
$loop_item = '';
$nid = $item['nid'] ? $item['nid'] : ($node->nid ? $node->nid : '');
if($grouped){
$loop_item = 'grouped';
}else{
switch ($settings['imagefield']['grouping']) {
case 1:
$loop_item = $nid .'-'. $field;
break;
case 2:
$loop_item = 'all';
break;
}
}
list($namespace, $presetname) = explode('|', $formatter, 2);
if ($preset = imagecache_preset_by_name($namespace)) {
return theme('imagefield_image_imagecache_fancybox', $namespace, $field, $item['filepath'], $image_title, $loop_item);
}
}
file: fancybox.theme.inc
<?php
// $Id: fancybox.theme.inc,v 1.1.2.4 2010/11/01 01:38:19 sbacelic Exp $
/**
* @file
* Theme functions for Fancybox module.
*/
/**
* Theme ImageCache + Imagefield CCK field formatter.
*/
function theme_fancybox_formatter_imagefield($element) {
if (module_exists('imagecache') && module_exists('imagefield')) {
$node = node_load($element['#item']['nid']);
return fancybox_imagefield_image_imagecache($element['#field_name'], $element['#item'], $element['#formatter'], $node);
}
}
/**
* Theme ImageCache + Imagefield CCK field formatter.
*/
function theme_fancybox_grouped_formatter_imagefield($element) {
if (module_exists('imagecache') && module_exists('imagefield')) {
$node = node_load($element['#item']['nid']);
return fancybox_imagefield_image_imagecache($element['#field_name'], $element['#item'], $element['#formatter'], $node, true);
}
}
/**
* Theme ImageCache + Imagefield CCK field.
*/
function theme_imagefield_image_imagecache_fancybox($namespace, $field, $path, $title = '', $loop = '', $attributes = NULL) {
if (!empty($path)) {
$image = theme('imagecache', $namespace, $path, $title, $title, $attributes);
$settings = variable_get('fancybox_settings', array());
if ($presetname = $settings['imagefield']['imagecache_preset']) {
$link_path = imagecache_create_url($presetname, $path);
}
else {
$link_path = file_create_url($path);
}
$options = array(
'html' => TRUE,
'attributes' => array(
'title' => $title,
'class' => "imagefield-fancybox",
)
);
if ($loop) {
$options['attributes']['rel'] = 'imagefield-fancybox-'. $loop;
}
return l($image, $link_path, $options);
}
}
/**
* Generate the HTML output to open a emvideo field in fancybox.
* Use the generic modal output from emvideo.
*
* Note: if you are implementing a custom AJAX callback make sure that
* you wrap the output into a div where you set its dimensions, fancybox sometimes
* fails to detect the size of the embedded video if its wrapped into multiple divs.
*
* @param $field
* The CCK field the action is being performed on.
* @param $item
* An array, keyed by column, of the data stored for this item in this field.
* @param $formatter
* The formatter to use for the field.
* @param $node
* The node object.
* @return
* Themed modal dialogue of the embedded media field video.
*/
function theme_fancybox_emvideo($field, $item, $formatter, $node) {
return theme('emvideo_modal_generic', $field, $item, $formatter, $node, array('modal' => 'fancybox'));
}
/**
* CCK formatter theme for the emfield. This will call theme_fancybox_emvideo.
*
* @param $element
* The CCK field element.
* @return
* HTML output for displaying the video and link.
*/
function theme_fancybox_formatter_emvideo_fancybox_video($element) {
$field = content_fields($element['#field_name'], $element['#type_name']);
$item = $element['#item'];
$formatter = "emvideo";
$node = node_load($element['#node']->nid);
return module_invoke('emfield', 'emfield_field_formatter', $field, $item, $formatter, $node, 'fancybox');
}
If this could be added to the release itd be great.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | fancybox.patch | 4.55 KB | webadpro |
Comments
Comment #1
webadpro commentedI wish I knew how to create a patch but i dont so I've added the changed files.
Comment #2
tevih commentedis this possible for Drupal 7.0, too?
Comment #3
webadpro commentedI'm not sure. I haven't tried it under d7.
Comment #4
webadpro commentedHeres what, I have attached a patch for D6. Although I think from the time that I have made this modification and by now, I think they have made some modification although by reviewing the patch im sure you could implement it in d7.
Comment #5
tevih commentedcool - thanks!