Hello,

i'm looking for a clean way to add onComplete and onCleanup functions to just one of the galleries on my website.

I think it should be possible to do that through:

// Give other modules the possibility to override Colorbox settings and style.
  $data = &$js_settings;
  $data['__drupal_alter_by_ref'] = array(&$style);
  drupal_alter('colorbox_settings', $data);

in colorbox.module, but how?

thanks for helping me out with this.

Comments

joeysantiago’s picture

oh, found it :)

as often happens, after writing one finds his way. The correct name for the function to hook the settings is

function MYMODULE_colorbox_settings_alter($data, $context)

hope it helps someone :)

joeysantiago’s picture

Status: Active » Fixed
joeysantiago’s picture

Status: Fixed » Active

mhm. This is not working, even though it is called:

function MYMODULE_colorbox_settings_alter(&$data, $context){
  $data['onComplete'] = "function(){alert('loaded')}";
  $data['onClosed'] = "function(){ alert('closed'); }";
}

I think the problem is those are actually strings so jQuery doesn't know how to call them. Indeed i now have a javascript error:

c.call is not a function
http://localhost/MYSITE/sites/all/libraries/colorbox/colorbox/jquery.colorbox-min.js?6
Line 4

Can anyone help me?

joeysantiago’s picture

Well, i found no other way than overriding the Drupal.behaviors.initColorbox in a JS that i add to the page i want to modify.

Please, let me know whether i could do this in a better way.

frjo’s picture

Status: Active » Closed (works as designed)

Closing old issues that doesn't seems to effect a lot of users.

pandaPowder’s picture

Version: 6.x-1.0-beta11 » 7.x-2.4
Status: Closed (works as designed) » Needs review

Yes, I came to the same conclusion as @joeysantiago. Drupal.settings is not a place for printing out callbacks I don't think since you have to print them as strings in php. Perhaps you could use drupal_add_js inline and pass a piece of inline javascript code, but that would require a change to Drupal.behaviors.initColorbox (and possibly a new settings alter hook?) I believe to have it merge settings.colorbox with a predetermined javascript object printed out inline. I reopened this request to see if the maintainers are interested in adding such a feature. I think it would be a good addition to allow other modules access to all the events colorbox has to offer.

In any case, I found a decent enough solution for my particular need using the "universal" event hook cbox_complete which changes all colorboxes everywhere on your site. In my case, that was not a problem since I was simply trying to focus a form field when the colorbox completed.

	$(document).bind('cbox_complete', function () {
		$('#edit-submitted-zipcode:visible').focus();
	});
pandaPowder’s picture

Category: support » feature

Changing this to a feature request since we are really asking for a new settings_alter hook which would allow other modules to add some inline code with callbacks which colorbox could then merge in to settings.colorbox.

pandaPowder’s picture

Title: add onComplete and onCleanup functions » add ability for other modules to alter colorbox settings that aren't strings (like callback settings)

changing subject to reflect new purpose of this thread.

frjo’s picture

Issue summary: View changes
Status: Needs review » Active
Neslee Canil Pinto’s picture

Status: Active » Closed (works as designed)