Colorbox settings are currently not alterable for two reasons:

1. There is no colorbox_settings_alter hook.

2. The settings are hard-wired in the Javascript (namely Drupal.behaviors.initColorbox) because of some minor case differences, like slideshowSpeed:settings.slideshowspeed, etc.

To be able to allow adjusting settings on a page-by-page basis, or add one of the other Colorbox settings that are not supported by this module (which is my use case here), I'd suggest to fix (1) and (2) by passing Drupal.settings.colorbox unaltered but with correct casing, thereby also reducing the size of the Javascript.

Comments

smk-ka’s picture

Also I fail to understand what the custom settings should be good for, this looks very untypical for a Drupal module. You sure know there is a 'Reset' button on every Drupal settings page that allows users to get the module defaults back, don't you?

smk-ka’s picture

This looks also wrong (in _colorbox_doheader()):

  $style = variable_get('colorbox_style', 'default');
  switch ($style) {
    case 'default':
      drupal_add_css($path .'/styles/default/colorbox_default_style.css');
      break;
    case 'none':
      break;
    default:
      // This doesn't work: $style is the name of a style, which would have to reside in Drupal's root directory!
      drupal_add_css($style .'/colorbox.css');
  }
smk-ka’s picture

Status: Active » Needs review
StatusFileSize
new6.19 KB

First patch to demonstrate what I had in mind. Other Javascript files than the main colorbox.js still might need to be adjusted.

smk-ka’s picture

StatusFileSize
new6.2 KB

Sorry, ignore the last patch, it was outdated and non-working. Correct version attached.

frjo’s picture

#4: The alter_hook and the much smarter way of fixing the settings in "colorbox.js" looks really nice.

How would the settings be done in files like "colorbox_load.js" where some settings is build in functions and some comes from Drupal.settings?

#2: The code from is correct, the styles are located in the Colorbox plugin directory, not the Colorbox module directory.

#1: This was done in an attempt to make the settings page less overwhelming for new users, while still providing all the advanced settings. I sure its room for improvement.

Thanks for contributing this!

frjo’s picture

StatusFileSize
new3.04 KB

Part of this is already committed, the corrections of the setting names. Here is the rest.

hutch’s picture

I've just tested this patch and it works fine, though I haven't tested the hook alter part, only the js.
As it happens I was just about to provide a patch to allow a slideshow to be invoked from the source html, so I've altered what I was about to post to work with the new way to manage Drupal.settings.
As it would be a patch on a patch I'll just post the code:
Immediately below

  var settings = Drupal.settings.colorbox;
  $('a, area, input', context)
    .filter('.colorbox:not(.initColorbox-processed)')
    .addClass('initColorbox-processed')
    .colorbox(Drupal.settings.colorbox);

add

  settings.slideshow = true;
  $('a, area, input', context)
    .filter('.colorbox-slideshow:not(.initColorbox-processed)')
    .addClass('initColorbox-processed')
    .colorbox(settings);  

and use 'colorbox-slideshow' as the class for the grouped images.
Now I have per-instance slideshows :-)
Tested in Imagepicker.

hutch’s picture

Just to confirm:
The patch in #6 applies cleanly to current dev. My suggested addition to colorbox.js in #7 also works with current dev

hutch’s picture

I have tested the drupal_alter hook and it appears to work fine, Here is what I did

function mymodule_colorbox_settings_alter($args, &$style) {
  $style = "sites/all/libraries/colorbox/example3";
  $args['opacity'] = 1;
  return $args;
}

I'm not sure if this is correct....but it works.
It does however change it for the entire site, not just the instances being used by 'mymodule' so if more than one module has this hook we would have a kind of race condition.

frjo’s picture

Status: Needs review » Fixed

Committed to 6-dev. Thanks for the patch and the help testing it! This is a really neat and powerful addition to Colorbox.

Please post the colorbox-slideshow as a separate feature request. I would also put it in a separate JS file.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.