Commit e56a88f1 authored by frjo's avatar frjo
Browse files

Clean out inline, load and views field features. I never use them myself and...

Clean out inline, load and views field features. I never use them myself and they can easily be added in some Colorbox extras module if someone is interested.
parent 548daab6
......@@ -111,14 +111,6 @@ function colorbox_page_attachments(&$page) {
$page['#attached']['css'][$path . '/styles/' . $style . '/colorbox.css'] = array();
}
if ($config->get('extra.load', 0)) {
//$page['#attached']['js'][$path . '/js/colorbox_load.js'] = array();
}
if ($config->get('extra.inline', 0)) {
//$page['#attached']['js'][$path . '/js/colorbox_inline.js'] = array();
}
$already_added = TRUE;
}
}
......
<?php
/**
* @file
* colorbox.views.inc
*/
/**
* Implementation of hook_views_data()
*/
function colorbox_views_data() {
$data['colorbox']['table']['group'] = t('Colorbox');
$data['colorbox']['table']['join'] = array(
'#global' => array(),
);
$data['colorbox']['colorbox'] = array(
'title' => t('Colorbox trigger'),
'help' => t('Provide custom text or link.'),
'field' => array(
'id' => 'colorbox',
),
);
return $data;
}
extra:
load: FALSE
inline: FALSE
custom:
style: 'default'
activate: '0'
......
......@@ -2,16 +2,6 @@ colorbox.settings:
type: mapping
label: 'Colorbox settings'
mapping:
extra:
type: mapping
label: 'Extra features'
mapping:
load:
type: boolean
label: 'Enable Colorbox load'
inline:
type: boolean
label: 'Enable Colorbox inline'
custom:
style:
type: string
......
(function ($) {
Drupal.behaviors.initColorboxInline = {
attach: function (context, settings) {
if (!$.isFunction($.colorbox)) {
return;
}
$.urlParam = function(name, url){
if (name == 'fragment') {
var results = new RegExp('(#[^&#]*)').exec(url);
}
else {
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(url);
}
if (!results) { return ''; }
return results[1] || '';
};
$('.colorbox-inline', context).once('init-colorbox-inline').colorbox({
transition:settings.colorbox.transition,
speed:settings.colorbox.speed,
opacity:settings.colorbox.opacity,
slideshow:settings.colorbox.slideshow,
slideshowAuto:settings.colorbox.slideshowAuto,
slideshowSpeed:settings.colorbox.slideshowSpeed,
slideshowStart:settings.colorbox.slideshowStart,
slideshowStop:settings.colorbox.slideshowStop,
current:settings.colorbox.current,
previous:settings.colorbox.previous,
next:settings.colorbox.next,
close:settings.colorbox.close,
overlayClose:settings.colorbox.overlayClose,
maxWidth:settings.colorbox.maxWidth,
maxHeight:settings.colorbox.maxHeight,
innerWidth:function(){
return $.urlParam('width', $(this).attr('href'));
},
innerHeight:function(){
return $.urlParam('height', $(this).attr('href'));
},
title:function(){
return decodeURIComponent($.urlParam('title', $(this).attr('href')));
},
iframe:function(){
return $.urlParam('iframe', $(this).attr('href'));
},
inline:function(){
return $.urlParam('inline', $(this).attr('href'));
},
href:function(){
return $.urlParam('fragment', $(this).attr('href'));
}
});
}
};
})(jQuery);
(function ($) {
Drupal.behaviors.initColorboxLoad = {
attach: function (context, settings) {
if (!$.isFunction($.colorbox)) {
return;
}
$.urlParams = function (url) {
var p = {},
e,
a = /\+/g, // Regex for replacing addition symbol with a space
r = /([^&=]+)=?([^&]*)/g,
d = function (s) { return decodeURIComponent(s.replace(a, ' ')); },
q = url.split('?');
while (e = r.exec(q[1])) {
e[1] = d(e[1]);
e[2] = d(e[2]);
switch (e[2].toLowerCase()) {
case 'true':
case 'yes':
e[2] = true;
break;
case 'false':
case 'no':
e[2] = false;
break;
}
if (e[1] == 'width') { e[1] = 'innerWidth'; }
if (e[1] == 'height') { e[1] = 'innerHeight'; }
p[e[1]] = e[2];
}
return p;
};
$('.colorbox-load', context)
.once('init-colorbox-load', function () {
var params = $.urlParams($(this).attr('href'));
$(this).colorbox($.extend({}, settings.colorbox, params));
});
}
};
})(jQuery);
......@@ -34,23 +34,6 @@ class ColorboxSettingsForm extends ConfigFormBase {
$library = libraries_detect('colorbox');
$form['colorbox_extra_features'] = array(
'#type' => 'fieldset',
'#title' => t('Extra features'),
);
$form['colorbox_extra_features']['colorbox_load'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Colorbox load'),
'#default_value' => $config->get('extra.load'),
'#description' => t('This enables custom links that can open forms and paths in a Colorbox. Add the class "colorbox-load" to the link and build the url like this for paths "[path]?width=500&height=500&iframe=true" or "[path]?width=500&height=500" if you don\'t want an iframe. Other modules may activate this for easy Colorbox integration.'),
);
$form['colorbox_extra_features']['colorbox_inline'] = array(
'#type' => 'checkbox',
'#title' => t('Enable Colorbox inline'),
'#default_value' => $config->get('extra.inline'),
'#description' => t('This enables custom links that can open inline content in a Colorbox. Add the class "colorbox-inline" to the link and build the url like this "?width=500&height=500&inline=true#id-of-content". Other modules may activate this for easy Colorbox integration.'),
);
$form['colorbox_custom_settings'] = array(
'#type' => 'fieldset',
'#title' => t('Styles and options'),
......@@ -323,8 +306,6 @@ class ColorboxSettingsForm extends ConfigFormBase {
$form_values = $form_state['values'];
$config
->set('extra.load', $form_values['colorbox_load'])
->set('extra.inline', $form_values['colorbox_inline'])
->set('custom.style', $form_values['colorbox_style'])
->set('custom.activate', $form_values['colorbox_custom_settings_activate'])
->set('custom.transition_type', $form_values['colorbox_transition_type'])
......
<?php
/**
* @file
* Definition of Drupal\colorbox\Plugin\views\field\Colorbox.
*/
namespace Drupal\colorbox\Plugin\views\field;
use Drupal\Component\Annotation\PluginID;
use Drupal\Core\Annotation\Translation;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
/**
* A handler to provide a field that is completely custom by the administrator.
*
* @ingroup views_field_handlers
*
* @PluginID("colorbox")
*/
class Colorbox extends FieldPluginBase {
function query() {
// Do nothing, as this handler does not need to do anything to the query itself.
}
function defineOptions() {
$options = parent::defineOptions();
$options['trigger_field'] = array('default' => '');
$options['popup'] = array('default' => '');
$options['caption'] = array('default' => '');
$options['gid'] = array('default' => TRUE);
$options['custom_gid'] = array('default' => '');
$options['width'] = array('default' => '600px');
$options['height'] = array('default' => '400px');
return $options;
}
function buildOptionsForm(&$form, &$form_state) {
parent::buildOptionsForm($form, $form_state);
// Get a list of the available fields and arguments for trigger field and token replacement.
$options = array();
$fields = array('trigger_field' => t('- None -'));
foreach ($this->view->display_handler->getHandlers('field') as $field => $handler) {
$options[t('Fields')]["[$field]"] = $handler->adminLabel();
// We only use fields up to (and including) this one.
if ($field == $this->options['id']) {
break;
}
$fields[$field] = $handler->definition['title'];
}
$count = 0; // This lets us prepare the key as we want it printed.
foreach ($this->view->display_handler->getHandlers('argument') as $arg => $handler) {
$options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->adminLabel()));
$options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->adminLabel()));
}
$this->documentSelfTokens($options[t('Fields')]);
// Default text.
$patterns = t('<p>You must add some additional fields to this display before using this field. These fields may be marked as <em>Exclude from display</em> if you prefer. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.</p>');
// We have some options, so make a list.
if (!empty($options)) {
$patterns = t('<p>The following tokens are available for this field. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.
If you would like to have the characters %5B and %5D please use the html entity codes \'%5B\' or \'%5D\' or they will get replaced with empty space.</p>');
foreach (array_keys($options) as $type) {
if (!empty($options[$type])) {
$items = array();
foreach ($options[$type] as $key => $value) {
$items[] = $key . ' == ' . $value;
}
$patterns .= theme('item_list',
array(
'items' => $items,
'type' => $type
));
}
}
}
$form['trigger_field'] = array(
'#type' => 'select',
'#title' => t('Trigger field'),
'#description' => t('Select the field that should be turned into the trigger for the Colorbox. Only fields that appear before this one in the field list may be used.'),
'#options' => $fields,
'#default_value' => $this->options['trigger_field'],
'#weight' => -12,
);
$form['popup'] = array(
'#type' => 'textarea',
'#title' => t('Popup'),
'#description' => t('The Colorbox popup content. You may include HTML. You may enter data from this view as per the "Replacement patterns" below.'),
'#default_value' => $this->options['popup'],
'#weight' => -11,
);
$form['caption'] = array(
'#type' => 'textfield',
'#title' => t('Caption'),
'#description' => t('The Colorbox Caption. You may include HTML. You may enter data from this view as per the "Replacement patterns" below.'),
'#default_value' => $this->options['caption'],
'#weight' => -10,
);
$form['gid'] = array(
'#type' => 'checkbox',
'#title' => t('Automatic generated Colorbox gallery'),
'#description' => t('Enable Colorbox gallery using a generated gallery id for this view.'),
'#default_value' => $this->options['gid'],
'#weight' => -9,
);
$form['custom_gid'] = array(
'#type' => 'textfield',
'#title' => t('Custom Colorbox gallery'),
'#description' => t('Enable Colorbox gallery with a given string as gallery. Overrides the automatically generated gallery id above. You may enter data from this view as per the "Replacement patterns" below.'),
'#default_value' => $this->options['custom_gid'],
'#weight' => -8,
);
$form['width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#description' => t('Specify the width of the Colorbox popup window. Because the content is dynamic, we cannot detect this value automatically. Example: "100%", 500, "500px".'),
'#default_value' => $this->options['width'],
'#weight' => -6,
);
$form['height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#description' => t('Specify the height of the Colorbox popup window. Because the content is dynamic, we cannot detect this value automatically. Example: "100%", 500, "500px".'),
'#default_value' => $this->options['height'],
'#weight' => -7,
);
$form['patterns'] = array(
'#type' => 'fieldset',
'#title' => t('Replacement patterns'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#value' => $patterns,
);
}
/**
* Render the trigger field and its linked popup information.
*/
function render(ResultRow $values) {
$config = config('colorbox.settings');
// Load the necessary js file for Colorbox activation.
if (_colorbox_active() && !$config->get('extra.inline')) {
$conf_js = array(
'#attached' => array(
'js' => array(
drupal_get_path('module', 'colorbox') . '/js/colorbox_inline.js' => array(),
),
),
);
drupal_render($conf_js);
}
// We need to have multiple unique IDs, one for each record.
static $i = 0;
$i = mt_rand();
// Return nothing if no trigger filed is selected.
if (empty($this->options['trigger_field'])) {
return;
}
// Get the token information and generate the value for the popup and the
// caption.
$tokens = $this->getRenderTokens($this->options['alter']);
$popup = filter_xss_admin($this->options['popup']);
$caption = filter_xss_admin($this->options['caption']);
$gallery = filter_xss_admin($this->options['custom_gid']);
$popup = strtr($popup, $tokens);
$caption = strtr($caption, $tokens);
$gallery = strtr($gallery, $tokens);
$width = $this->options['width'] ? $this->options['width'] : '';
$height = $this->options['height'] ? $this->options['height'] : '';
$gallery_id = !empty($this->options['custom_gid']) ? $gallery : ($this->options['gid'] ? 'gallery-' . $this->view->storage->id : '');
$link_text = $tokens["[{$this->options['trigger_field']}]"];
$link_options = array(
'html' => TRUE,
'fragment' => 'colorbox-inline-' . $i,
'query' => array(
'width' => $width,
'height' => $height,
'title' => $caption,
'inline' => 'true'
),
'attributes' => array(
'class' => array('colorbox-inline'),
'rel' => $gallery_id
)
);
// Remove any parameters that aren't set.
$link_options['query'] = array_filter($link_options['query']);
// If the nid is present make the link degrade to the node page if
// JavaScript is off.
$link_target = isset($values->nid) ? 'node/' . $values->nid : '';
$link_tag = l($link_text, $link_target, $link_options);
// The outside div is there to hide all of the divs because if the specific Colorbox
// div is hidden it won't show up as a Colorbox.
return $link_tag . '<div style="display: none;"><div id="colorbox-inline-' . $i . '">' . $popup . '</div></div>';
}
}
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