Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
joeysantiago CreditAttribution: joeysantiago commentedoh, 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 :)
Comment #2
joeysantiago CreditAttribution: joeysantiago commentedComment #3
joeysantiago CreditAttribution: joeysantiago commentedmhm. This is not working, even though it is called:
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:
Can anyone help me?
Comment #4
joeysantiago CreditAttribution: joeysantiago commentedWell, 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.
Comment #5
frjo CreditAttribution: frjo commentedClosing old issues that doesn't seems to effect a lot of users.
Comment #6
pandaPowder CreditAttribution: pandaPowder commentedYes, 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.
Comment #7
pandaPowder CreditAttribution: pandaPowder commentedChanging 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.
Comment #8
pandaPowder CreditAttribution: pandaPowder commentedchanging subject to reflect new purpose of this thread.
Comment #9
frjo CreditAttribution: frjo commentedComment #10
Neslee Canil Pinto