Commit 8df71e85 authored by frjo's avatar frjo
Browse files

Make it work on 8.0.0-beta14, more or less at least. No longer using libraries...

Make it work on 8.0.0-beta14, more or less at least. No longer using libraries module so libraries path is hard coded.
parent b10bf82d
name: 'Colorbox'
type: module
description: 'A light-weight, customizable lightbox plugin for jQuery 1.4.3+.'
description: 'A light-weight, customizable lightbox plugin for jQuery.'
package: Media
core: 8.x
configure: colorbox.settings
dependencies:
- libraries
configure: colorbox.admin_settings
......@@ -13,6 +13,7 @@ use Drupal\Component\Utility\Unicode;
function colorbox_requirements($phase) {
$requirements = array();
/*
if ($phase == 'runtime') {
$library = libraries_detect('colorbox');
$error_type = isset($library['error']) ? Unicode::ucfirst($library['error']) : '';
......@@ -49,6 +50,7 @@ function colorbox_requirements($phase) {
);
}
}
*/
return $requirements;
}
colorbox:
remote: http://github.com/jackmoore/colorbox
version: "1.6.1"
license:
name: MIT
gpl-compatible: false
js:
/libraries/colorbox/jquery.colorbox-min.js: { minified: true }
dependencies:
- core/jquery
colorbox-dev:
remote: http://github.com/jackmoore/colorbox
version: "1.6.1"
license:
name: MIT
gpl-compatible: false
js:
/libraries/colorbox/jquery.colorbox.js: { }
dependencies:
- core/jquery
init:
version: VERSION
js:
js/colorbox.js: {}
......@@ -6,7 +28,7 @@ colorbox:
- core/jquery
- core/drupal
settings:
admin_settings:
version: VERSION
js:
js/colorbox_admin_settings.js: { preprocess: false }
......@@ -22,9 +44,7 @@ plain:
theme:
styles/plain/colorbox_style.css: {}
dependencies:
- colorbox/colorbox
- core/jquery
- core/drupal
- colorbox/init
stockholmsyndrome:
version: VERSION
......@@ -34,9 +54,7 @@ stockholmsyndrome:
theme:
styles/stockholmsyndrome/colorbox_style.css: {}
dependencies:
- colorbox/colorbox
- core/jquery
- core/drupal
- colorbox/init
default:
version: VERSION
......@@ -46,6 +64,44 @@ default:
theme:
styles/default/colorbox_style.css: {}
dependencies:
- colorbox/colorbox
- core/jquery
- core/drupal
- colorbox/init
example1:
version: VERSION
css:
theme:
/libraries/colorbox/example1/colorbox.css: {}
dependencies:
- colorbox/init
example2:
version: VERSION
css:
theme:
/libraries/colorbox/example2/colorbox.css: {}
dependencies:
- colorbox/init
example3:
version: VERSION
css:
theme:
/libraries/colorbox/example3/colorbox.css: {}
dependencies:
- colorbox/init
example4:
version: VERSION
css:
theme:
/libraries/colorbox/example4/colorbox.css: {}
dependencies:
- colorbox/init
example4:
version: VERSION
css:
theme:
/libraries/colorbox/example5/colorbox.css: {}
dependencies:
- colorbox/init
......@@ -34,130 +34,82 @@ function colorbox_theme() {
/**
* Implements hook_page_attachments().
*/
function colorbox_page_attachments(&$page) {
function colorbox_page_attachments(array &$page) {
if (drupal_installation_attempted()) {
return; // Don't add the JavaScript and CSS during installation.
}
static $already_added = FALSE;
if ($already_added) {
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.
$config = \Drupal::config('colorbox.settings');
if (!drupal_installation_attempted()) {
static $already_added = FALSE;
if ($already_added) {
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.
if ($config->get('custom.activate')) {
$js_settings = array(
'transition' => $config->get('custom.transition_type'),
'speed' => $config->get('custom.transition_speed'),
'opacity' => $config->get('custom.opacity'),
'slideshow' => $config->get('custom.slideshow.slideshow') ? TRUE : FALSE,
'slideshowAuto' => $config->get('custom.slideshow.auto') ? TRUE : FALSE,
'slideshowSpeed' => $config->get('custom.slideshow.speed'),
'slideshowStart' => $config->get('custom.slideshow.text_start'),
'slideshowStop' => $config->get('custom.slideshow.text_stop'),
'current' => $config->get('custom.text_current'),
'previous' => $config->get('custom.text_previous'),
'next' => $config->get('custom.text_next'),
'close' => $config->get('custom.text_close'),
'overlayClose' => $config->get('custom.overlayclose') ? TRUE : FALSE,
'maxWidth' => $config->get('custom.maxwidth'),
'maxHeight' => $config->get('custom.maxheight'),
'initialWidth' => $config->get('custom.initialwidth'),
'initialHeight' => $config->get('custom.initialheight'),
'fixed' => $config->get('custom.fixed') ? TRUE : FALSE,
'scrolling' => $config->get('custom.scrolling') ? TRUE : FALSE,
'mobiledetect' => $config->get('advanced.mobile_detect') ? TRUE : FALSE,
'mobiledevicewidth' => $config->get('advanced.mobile_device_width'),
);
}
else {
$js_settings = array(
'opacity' => '0.85',
'current' => t('{current} of {total}'),
'previous' => t('« Prev'),
'next' => t('Next »'),
'close' => t('Close'),
'maxWidth' => '98%',
'maxHeight' => '98%',
'fixed' => TRUE,
'mobiledetect' => $config->get('advanced.mobile_detect') ? TRUE : FALSE,
'mobiledevicewidth' => $config->get('advanced.mobile_device_width'),
);
}
$path = drupal_get_path('module', 'colorbox');
$style = $config->get('custom.style');
// Give other modules the possibility to override Colorbox settings and style.
\Drupal::moduleHandler()->alter('colorbox_settings', $js_settings, $style);
$page['#attached']['drupalSettings']['colorbox'] = $js_settings;
// Add and initialise the Colorbox plugin.
$variant = $config->get('advanced.compression_type');
libraries_load('colorbox', $variant);
$page['#attached']['library'][] = 'colorbox/colorbox';
// Add JS and CSS based on selected style.
switch ($style) {
case 'none':
break;
case 'default':
$page['#attached']['library'][] = 'colorbox/default';
break;
case 'plain':
$page['#attached']['library'][] = 'colorbox/plain';
break;
case 'stockholmsyndrome':
$page['#attached']['library'][] = 'colorbox/stockholmsyndrome';
break;
default:
$page['#attached']['library'][] = 'colorbox/default';
}
$already_added = TRUE;
}
}
if ($config->get('custom.activate')) {
$js_settings = array(
'transition' => $config->get('custom.transition_type'),
'speed' => $config->get('custom.transition_speed'),
'opacity' => $config->get('custom.opacity'),
'slideshow' => $config->get('custom.slideshow.slideshow') ? TRUE : FALSE,
'slideshowAuto' => $config->get('custom.slideshow.auto') ? TRUE : FALSE,
'slideshowSpeed' => $config->get('custom.slideshow.speed'),
'slideshowStart' => $config->get('custom.slideshow.text_start'),
'slideshowStop' => $config->get('custom.slideshow.text_stop'),
'current' => $config->get('custom.text_current'),
'previous' => $config->get('custom.text_previous'),
'next' => $config->get('custom.text_next'),
'close' => $config->get('custom.text_close'),
'overlayClose' => $config->get('custom.overlayclose') ? TRUE : FALSE,
'maxWidth' => $config->get('custom.maxwidth'),
'maxHeight' => $config->get('custom.maxheight'),
'initialWidth' => $config->get('custom.initialwidth'),
'initialHeight' => $config->get('custom.initialheight'),
'fixed' => $config->get('custom.fixed') ? TRUE : FALSE,
'scrolling' => $config->get('custom.scrolling') ? TRUE : FALSE,
'mobiledetect' => $config->get('advanced.mobile_detect') ? TRUE : FALSE,
'mobiledevicewidth' => $config->get('advanced.mobile_device_width'),
);
}
else {
$js_settings = array(
'opacity' => '0.85',
'current' => t('{current} of {total}'),
'previous' => t('« Prev'),
'next' => t('Next »'),
'close' => t('Close'),
'maxWidth' => '98%',
'maxHeight' => '98%',
'fixed' => TRUE,
'mobiledetect' => $config->get('advanced.mobile_detect') ? TRUE : FALSE,
'mobiledevicewidth' => $config->get('advanced.mobile_device_width'),
);
}
$style = $config->get('custom.style');
/**
* Implements hook_libraries_info().
*/
function colorbox_libraries_info() {
$libraries['colorbox'] = array(
'name' => 'Colorbox plugin',
'vendor url' => 'http://www.jacklmoore.com/colorbox',
'download url' => 'https://github.com/jackmoore/colorbox/archive/1.x.zip',
'version arguments' => array(
'file' => 'jquery.colorbox-min.js',
'pattern' => '@(?i:Colorbox)\sv?([0-9\.a-z]+)@',
'lines' => 5,
),
'files' => array(
'js' => array(
'jquery.colorbox-min.js',
),
),
'variants' => array(
'minified' => array(
'files' => array(
'js' => array(
'jquery.colorbox-min.js',
),
),
),
'source' => array(
'files' => array(
'js' => array(
'jquery.colorbox.js',
),
),
),
),
);
// Give other modules the possibility to override Colorbox settings and style.
\Drupal::moduleHandler()->alter('colorbox_settings', $js_settings, $style);
// Add colorbox js settings.
$page['#attached']['drupalSettings']['colorbox'] = $js_settings;
// Add and initialise the Colorbox plugin.
if ($config->get('advanced.compression_type' == 'minified')) {
$page['#attached']['library'][] = 'colorbox/colorbox';
}
else {
$page['#attached']['library'][] = 'colorbox/colorbox-dev';
}
// Add JS and CSS based on selected style.
if ($style != 'none') {
$page['#attached']['library'][] = "colorbox/$style";
}
return $libraries;
$already_added = TRUE;
}
/**
......
......@@ -37,9 +37,9 @@ class ColorboxSettingsForm extends ConfigFormBase {
// Get all settings
$config = $this->configFactory->get('colorbox.settings');
$form['#attached']['library'][] = 'colorbox/settings';
$form['#attached']['library'][] = 'colorbox/admin_settings';
$library = libraries_detect('colorbox');
//$library = libraries_detect('colorbox');
$form['colorbox_custom_settings'] = array(
'#type' => 'fieldset',
......@@ -49,11 +49,11 @@ class ColorboxSettingsForm extends ConfigFormBase {
'default' => t('Default'),
'plain' => t('Plain (mainly for images)'),
'stockholmsyndrome' => t('Stockholm Syndrome'),
$library['library path'] . '/example1' => t('Example 1'),
$library['library path'] . '/example2' => t('Example 2'),
$library['library path'] . '/example3' => t('Example 3'),
$library['library path'] . '/example4' => t('Example 4'),
$library['library path'] . '/example5' => t('Example 5'),
'example1' => t('Example 1'),
'example2' => t('Example 2'),
'example3' => t('Example 3'),
'example4' => t('Example 4'),
'example5' => t('Example 5'),
'none' => t('None'),
);
$form['colorbox_custom_settings']['colorbox_style'] = array(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment