|
@@ -6,9 +6,9 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
/**
|
|
/**
|
|
- * The default path to the Colorbox directory.
|
|
|
|
|
|
+ * The minimum required version of the Colorbox plugin.
|
|
*/
|
|
*/
|
|
-define('COLORBOX_MIN_PLUGIN_VERSION', '1.3.21.1');
|
|
|
|
|
|
+define('COLORBOX_MIN_PLUGIN_VERSION', '1.6.1');
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -32,6 +32,7 @@ function colorbox_theme() {
|
|
'widget' => NULL,
|
|
'widget' => NULL,
|
|
),
|
|
),
|
|
'template' => 'colorbox-insert-image',
|
|
'template' => 'colorbox-insert-image',
|
|
|
|
+ 'pattern' => 'colorbox_insert_image__[a-z0-9_]+',
|
|
'file' => 'colorbox.theme.inc',
|
|
'file' => 'colorbox.theme.inc',
|
|
),
|
|
),
|
|
|
|
|
|
@@ -43,6 +44,7 @@ function colorbox_theme() {
|
|
'node' => NULL, // Left for legacy support.
|
|
'node' => NULL, // Left for legacy support.
|
|
'field' => array(),
|
|
'field' => array(),
|
|
'display_settings' => array(),
|
|
'display_settings' => array(),
|
|
|
|
+ 'delta' => null,
|
|
),
|
|
),
|
|
'file' => 'colorbox.theme.inc',
|
|
'file' => 'colorbox.theme.inc',
|
|
),
|
|
),
|
|
@@ -54,8 +56,8 @@ function colorbox_theme() {
|
|
*/
|
|
*/
|
|
function colorbox_init() {
|
|
function colorbox_init() {
|
|
// Do not load colorbox during the Drupal installation process, e.g. if part
|
|
// Do not load colorbox during the Drupal installation process, e.g. if part
|
|
- // of installation profiles.
|
|
|
|
- if (!drupal_installation_attempted()) {
|
|
|
|
|
|
+ // of installation profiles. Only add the JavaScript and CSS on specified paths.
|
|
|
|
+ if (!drupal_installation_attempted() && _colorbox_active()) {
|
|
_colorbox_doheader();
|
|
_colorbox_doheader();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -77,10 +79,10 @@ function colorbox_libraries_info() {
|
|
$libraries['colorbox'] = array(
|
|
$libraries['colorbox'] = array(
|
|
'name' => 'Colorbox plugin',
|
|
'name' => 'Colorbox plugin',
|
|
'vendor url' => 'http://www.jacklmoore.com/colorbox',
|
|
'vendor url' => 'http://www.jacklmoore.com/colorbox',
|
|
- 'download url' => 'http://www.jacklmoore.com/colorbox',
|
|
|
|
|
|
+ 'download url' => 'https://github.com/jackmoore/colorbox/archive/1.x.zip',
|
|
'version arguments' => array(
|
|
'version arguments' => array(
|
|
'file' => 'jquery.colorbox-min.js',
|
|
'file' => 'jquery.colorbox-min.js',
|
|
- 'pattern' => '@ColorBox v([0-9\.a-z]+)@',
|
|
|
|
|
|
+ 'pattern' => '@(?i:Colorbox)\sv?([0-9\.a-z]+)@',
|
|
'lines' => 5,
|
|
'lines' => 5,
|
|
),
|
|
),
|
|
'files' => array(
|
|
'files' => array(
|
|
@@ -130,7 +132,7 @@ function colorbox_menu() {
|
|
/**
|
|
/**
|
|
* Check if Colorbox should be active for the current URL.
|
|
* Check if Colorbox should be active for the current URL.
|
|
*
|
|
*
|
|
- * @return
|
|
|
|
|
|
+ * @return bool
|
|
* TRUE if Colorbox should be active for the current page.
|
|
* TRUE if Colorbox should be active for the current page.
|
|
*/
|
|
*/
|
|
function _colorbox_active() {
|
|
function _colorbox_active() {
|
|
@@ -140,7 +142,7 @@ function _colorbox_active() {
|
|
return FALSE;
|
|
return FALSE;
|
|
}
|
|
}
|
|
|
|
|
|
- // Code from the block_list funtion in block.module.
|
|
|
|
|
|
+ // Code from the block_list function in block.module.
|
|
$path = drupal_get_path_alias($_GET['q']);
|
|
$path = drupal_get_path_alias($_GET['q']);
|
|
$colorbox_pages = variable_get('colorbox_pages', "admin*\nimagebrowser*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit\nprint/*\nprintpdf/*\nsystem/ajax\nsystem/ajax/*");
|
|
$colorbox_pages = variable_get('colorbox_pages', "admin*\nimagebrowser*\nimg_assist*\nimce*\nnode/add/*\nnode/*/edit\nprint/*\nprintpdf/*\nsystem/ajax\nsystem/ajax/*");
|
|
// Compare with the internal and path alias (if any).
|
|
// Compare with the internal and path alias (if any).
|
|
@@ -150,6 +152,9 @@ function _colorbox_active() {
|
|
}
|
|
}
|
|
$page_match = variable_get('colorbox_visibility', 0) == 0 ? !$page_match : $page_match;
|
|
$page_match = variable_get('colorbox_visibility', 0) == 0 ? !$page_match : $page_match;
|
|
|
|
|
|
|
|
+ // Allow other modules to change the state of colorbox for the current URL.
|
|
|
|
+ drupal_alter('colorbox_active', $page_match);
|
|
|
|
+
|
|
return $page_match;
|
|
return $page_match;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -161,9 +166,6 @@ function _colorbox_doheader() {
|
|
if ($already_added) {
|
|
if ($already_added) {
|
|
return; // Don't add the JavaScript and CSS multiple times.
|
|
return; // Don't add the JavaScript and CSS multiple times.
|
|
}
|
|
}
|
|
- if (!_colorbox_active()) {
|
|
|
|
- return; // Don't add the JavaScript and CSS on specified paths.
|
|
|
|
- }
|
|
|
|
|
|
|
|
// Insert options and translated strings as javascript settings.
|
|
// Insert options and translated strings as javascript settings.
|
|
if (variable_get('colorbox_custom_settings_activate', 0)) {
|
|
if (variable_get('colorbox_custom_settings_activate', 0)) {
|
|
@@ -176,10 +178,10 @@ function _colorbox_doheader() {
|
|
'slideshowSpeed' => variable_get('colorbox_slideshowspeed', 2500),
|
|
'slideshowSpeed' => variable_get('colorbox_slideshowspeed', 2500),
|
|
'slideshowStart' => variable_get('colorbox_text_start', 'start slideshow'),
|
|
'slideshowStart' => variable_get('colorbox_text_start', 'start slideshow'),
|
|
'slideshowStop' => variable_get('colorbox_text_stop', 'stop slideshow'),
|
|
'slideshowStop' => variable_get('colorbox_text_stop', 'stop slideshow'),
|
|
- 'current' => variable_get('colorbox_text_current', '{current} of {total}'),
|
|
|
|
- 'previous' => variable_get('colorbox_text_previous', '« Prev'),
|
|
|
|
- 'next' => variable_get('colorbox_text_next', 'Next »'),
|
|
|
|
- 'close' => variable_get('colorbox_text_close', 'Close'),
|
|
|
|
|
|
+ 'current' => strip_tags(variable_get('colorbox_text_current', '{current} of {total}')),
|
|
|
|
+ 'previous' => strip_tags(variable_get('colorbox_text_previous', '« Prev')),
|
|
|
|
+ 'next' => strip_tags(variable_get('colorbox_text_next', 'Next »')),
|
|
|
|
+ 'close' => strip_tags(variable_get('colorbox_text_close', 'Close')),
|
|
'overlayClose' => variable_get('colorbox_overlayclose', 1) ? TRUE : FALSE,
|
|
'overlayClose' => variable_get('colorbox_overlayclose', 1) ? TRUE : FALSE,
|
|
'maxWidth' => variable_get('colorbox_maxwidth', '98%'),
|
|
'maxWidth' => variable_get('colorbox_maxwidth', '98%'),
|
|
'maxHeight' => variable_get('colorbox_maxheight', '98%'),
|
|
'maxHeight' => variable_get('colorbox_maxheight', '98%'),
|
|
@@ -187,6 +189,8 @@ function _colorbox_doheader() {
|
|
'initialHeight' => variable_get('colorbox_initialheight', '250'),
|
|
'initialHeight' => variable_get('colorbox_initialheight', '250'),
|
|
'fixed' => variable_get('colorbox_fixed', 1) ? TRUE : FALSE,
|
|
'fixed' => variable_get('colorbox_fixed', 1) ? TRUE : FALSE,
|
|
'scrolling' => variable_get('colorbox_scrolling', 1) ? TRUE : FALSE,
|
|
'scrolling' => variable_get('colorbox_scrolling', 1) ? TRUE : FALSE,
|
|
|
|
+ 'mobiledetect' => variable_get('colorbox_mobile_detect', 1) ? TRUE : FALSE,
|
|
|
|
+ 'mobiledevicewidth' => variable_get('colorbox_mobile_device_width', '480px'),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
@@ -199,6 +203,8 @@ function _colorbox_doheader() {
|
|
'maxWidth' => '98%',
|
|
'maxWidth' => '98%',
|
|
'maxHeight' => '98%',
|
|
'maxHeight' => '98%',
|
|
'fixed' => TRUE,
|
|
'fixed' => TRUE,
|
|
|
|
+ 'mobiledetect' => variable_get('colorbox_mobile_detect', 1) ? TRUE : FALSE,
|
|
|
|
+ 'mobiledevicewidth' => variable_get('colorbox_mobile_device_width', '480px'),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -213,7 +219,9 @@ function _colorbox_doheader() {
|
|
|
|
|
|
// Add and initialise the Colorbox plugin.
|
|
// Add and initialise the Colorbox plugin.
|
|
$variant = variable_get('colorbox_compression_type', 'minified');
|
|
$variant = variable_get('colorbox_compression_type', 'minified');
|
|
- libraries_load('colorbox', $variant);
|
|
|
|
|
|
+ if (module_exists('libraries')) {
|
|
|
|
+ libraries_load('colorbox', $variant);
|
|
|
|
+ }
|
|
drupal_add_js($path . '/js/colorbox.js');
|
|
drupal_add_js($path . '/js/colorbox.js');
|
|
|
|
|
|
// Add JS and CSS based on selected style.
|
|
// Add JS and CSS based on selected style.
|
|
@@ -251,6 +259,7 @@ function colorbox_field_formatter_info() {
|
|
'field types' => array('image'),
|
|
'field types' => array('image'),
|
|
'settings' => array(
|
|
'settings' => array(
|
|
'colorbox_node_style' => '',
|
|
'colorbox_node_style' => '',
|
|
|
|
+ 'colorbox_node_style_first' => '',
|
|
'colorbox_image_style' => '',
|
|
'colorbox_image_style' => '',
|
|
'colorbox_gallery' => 'post',
|
|
'colorbox_gallery' => 'post',
|
|
'colorbox_gallery_custom' => '',
|
|
'colorbox_gallery_custom' => '',
|
|
@@ -280,6 +289,14 @@ function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $
|
|
'#options' => $image_styles_hide,
|
|
'#options' => $image_styles_hide,
|
|
'#description' => t('Image style to use in the content.'),
|
|
'#description' => t('Image style to use in the content.'),
|
|
);
|
|
);
|
|
|
|
+ $element['colorbox_node_style_first'] = array(
|
|
|
|
+ '#title' => t('Content image style for first image'),
|
|
|
|
+ '#type' => 'select',
|
|
|
|
+ '#default_value' => $settings['colorbox_node_style_first'],
|
|
|
|
+ '#empty_option' => t('No special style.'),
|
|
|
|
+ '#options' => $image_styles,
|
|
|
|
+ '#description' => t('Image style to use in the content for the first image.'),
|
|
|
|
+ );
|
|
$element['colorbox_image_style'] = array(
|
|
$element['colorbox_image_style'] = array(
|
|
'#title' => t('Colorbox image style'),
|
|
'#title' => t('Colorbox image style'),
|
|
'#type' => 'select',
|
|
'#type' => 'select',
|
|
@@ -306,15 +323,12 @@ function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $
|
|
);
|
|
);
|
|
$element['colorbox_gallery_custom'] = array(
|
|
$element['colorbox_gallery_custom'] = array(
|
|
'#title' => t('Custom gallery'),
|
|
'#title' => t('Custom gallery'),
|
|
- '#type' => 'machine_name',
|
|
|
|
|
|
+ '#type' => 'textfield',
|
|
'#maxlength' => 32,
|
|
'#maxlength' => 32,
|
|
'#default_value' => $settings['colorbox_gallery_custom'],
|
|
'#default_value' => $settings['colorbox_gallery_custom'],
|
|
- '#description' => t('All images on a page with the same gallery value (rel attribute) will be grouped together. It must only contain lowercase letters, numbers, and underscores.'),
|
|
|
|
|
|
+ '#description' => t('All images on a page with the same gallery value (rel attribute) will be grouped together. It must only contain lowercase letters, numbers, hyphen and underscores.'),
|
|
|
|
+ '#element_validate' => array('colorbox_gallery_custom_validate'),
|
|
'#required' => FALSE,
|
|
'#required' => FALSE,
|
|
- '#machine_name' => array(
|
|
|
|
- 'exists' => 'colorbox_gallery_exists',
|
|
|
|
- 'error' => t('The custom gallery field must only contain lowercase letters, numbers, and underscores.'),
|
|
|
|
- ),
|
|
|
|
'#states' => array(
|
|
'#states' => array(
|
|
'visible' => array(
|
|
'visible' => array(
|
|
':input[name$="[settings_edit_form][settings][colorbox_gallery]"]' => array('value' => 'custom'),
|
|
':input[name$="[settings_edit_form][settings][colorbox_gallery]"]' => array('value' => 'custom'),
|
|
@@ -335,7 +349,7 @@ function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $
|
|
'#type' => 'select',
|
|
'#type' => 'select',
|
|
'#default_value' => $settings['colorbox_caption'],
|
|
'#default_value' => $settings['colorbox_caption'],
|
|
'#options' => $caption,
|
|
'#options' => $caption,
|
|
- '#description' => t('Automatic will use the first none empty value of the title, the alt text and the content title.'),
|
|
|
|
|
|
+ '#description' => t('Automatic will use the first non-empty value of the title, the alt text and the content title.'),
|
|
);
|
|
);
|
|
$element['colorbox_caption_custom'] = array(
|
|
$element['colorbox_caption_custom'] = array(
|
|
'#title' => t('Custom caption'),
|
|
'#title' => t('Custom caption'),
|
|
@@ -354,7 +368,7 @@ function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $
|
|
'#type' => 'fieldset',
|
|
'#type' => 'fieldset',
|
|
'#title' => t('Replacement patterns'),
|
|
'#title' => t('Replacement patterns'),
|
|
'#theme' => 'token_tree',
|
|
'#theme' => 'token_tree',
|
|
- '#token_types' => array($instance['entity_type'], 'file'),
|
|
|
|
|
|
+ '#token_types' => array_merge(array_keys($field['bundles']),array('file')),
|
|
'#recursion_limit' => $recursion_limit,
|
|
'#recursion_limit' => $recursion_limit,
|
|
'#dialog' => TRUE,
|
|
'#dialog' => TRUE,
|
|
'#states' => array(
|
|
'#states' => array(
|
|
@@ -380,6 +394,15 @@ function colorbox_field_formatter_settings_form($field, $instance, $view_mode, $
|
|
return $element;
|
|
return $element;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Validate function for colorbox_gallery_custom.
|
|
|
|
+ */
|
|
|
|
+function colorbox_gallery_custom_validate($element, &$form_state) {
|
|
|
|
+ if (!empty($element['#value']) && !preg_match('!^[a-z0-9_-]+$!', $element['#value'])) {
|
|
|
|
+ form_error($element, t('%name must only contain lowercase letters, numbers, hyphen and underscores.', array('%name' => $element['#title'])));
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Implements hook_field_formatter_settings_summary().
|
|
* Implements hook_field_formatter_settings_summary().
|
|
*/
|
|
*/
|
|
@@ -404,6 +427,10 @@ function colorbox_field_formatter_settings_summary($field, $instance, $view_mode
|
|
$summary[] = t('Content image style: Original image');
|
|
$summary[] = t('Content image style: Original image');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (isset($image_styles[$settings['colorbox_node_style_first']])) {
|
|
|
|
+ $summary[] = t('Content image style of first image: @style', array('@style' => $image_styles[$settings['colorbox_node_style_first']]));
|
|
|
|
+ }
|
|
|
|
+
|
|
if (isset($image_styles[$settings['colorbox_image_style']])) {
|
|
if (isset($image_styles[$settings['colorbox_image_style']])) {
|
|
$summary[] = t('Colorbox image style: @style', array('@style' => $image_styles[$settings['colorbox_image_style']]));
|
|
$summary[] = t('Colorbox image style: @style', array('@style' => $image_styles[$settings['colorbox_image_style']]));
|
|
}
|
|
}
|
|
@@ -455,6 +482,7 @@ function colorbox_field_formatter_view($entity_type, $entity, $field, $instance,
|
|
'#node' => $entity, // Left for legacy support.
|
|
'#node' => $entity, // Left for legacy support.
|
|
'#field' => $field,
|
|
'#field' => $field,
|
|
'#display_settings' => $display['settings'],
|
|
'#display_settings' => $display['settings'],
|
|
|
|
+ '#delta' => $delta,
|
|
);
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -464,11 +492,14 @@ function colorbox_field_formatter_view($entity_type, $entity, $field, $instance,
|
|
|
|
|
|
/**
|
|
/**
|
|
* Implements hook_insert_styles().
|
|
* Implements hook_insert_styles().
|
|
|
|
+ *
|
|
|
|
+ * @return array
|
|
*/
|
|
*/
|
|
function colorbox_insert_styles() {
|
|
function colorbox_insert_styles() {
|
|
$insert_styles = array();
|
|
$insert_styles = array();
|
|
foreach (image_styles() as $key => $style) {
|
|
foreach (image_styles() as $key => $style) {
|
|
- $insert_styles['colorbox__' . $key] = array('label' => t('Colorbox @style', array('@style' => $style['name'])));
|
|
|
|
|
|
+ $label = isset($style['label']) ? $style['label'] : $style['name'];
|
|
|
|
+ $insert_styles['colorbox__' . $key] = array('label' => t('Colorbox @style', array('@style' => $label)));
|
|
}
|
|
}
|
|
|
|
|
|
return $insert_styles;
|
|
return $insert_styles;
|
|
@@ -479,13 +510,13 @@ function colorbox_insert_styles() {
|
|
*/
|
|
*/
|
|
function colorbox_insert_content($item, $style, $widget) {
|
|
function colorbox_insert_content($item, $style, $widget) {
|
|
list($item['module_name'], $item['style_name']) = explode('__', $style['name'], 2);
|
|
list($item['module_name'], $item['style_name']) = explode('__', $style['name'], 2);
|
|
- return theme('colorbox_insert_image', array('item' => $item, 'widget' => $widget));
|
|
|
|
|
|
+ return theme(array('colorbox_insert_image__' . str_replace('-', '_', $item['style_name']), 'colorbox_insert_image'), array('item' => $item, 'widget' => $widget));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* Machine names normally need to be unique but that does not apply to galleries.
|
|
* Machine names normally need to be unique but that does not apply to galleries.
|
|
*
|
|
*
|
|
- * @return
|
|
|
|
|
|
+ * @return false
|
|
* Always FALSE
|
|
* Always FALSE
|
|
*/
|
|
*/
|
|
function colorbox_gallery_exists() {
|
|
function colorbox_gallery_exists() {
|