This patch is shamelessly stolen from the Lightbox2 issue #474454: Views lightbox2 custom field handler (update). It looked so neat that I wanted to have it in Colorbox also. The credits go mainly to Crell with contributions from several others. Thank you!

Please try it out and report back here with your findings and suggestions.

Here are the description, also taken from the issue above.

1) Create a new views field handler. This field handler does not bind to any specific field in the database, much as the "edit link" field handler does not. We'll call this handler "Colorbox trigger" for now.

2) The configuration form for the "Colorbox trigger" handler supports the following:
a) Select any one existing other field on the view as the trigger field.
b) A textarea much like the "rewrite this field" textarea that accepts any field tokens. This is the "popup content".
c) Remove the "rewrite" and "make a link out of" stuff, since it would just break things.

3) On render, take the field that is the trigger field (as it gets rendered by that field's configuration) and throw a link around it to be a "Colorbox trigger" field.

4) When that trigger field is clicked, a Colorbox popup opens that contains whatever the rendered "popup content" content is rather than just a specific graphic.

Why do we do this?

This approach lets us use any field to trigger Colorbox, not just an image.

This approach lets us put any fields (not just one field) in the Colorbox itself, not just the same image we clicked on.

This enables things like:

- Have a separate thumbnail imagefield from full-sized imagefield, in case you want custom crops.
- Have a custom caption including HTML in a CCK text field for an image.
- Have a "view full size" link as the trigger, instead of an image.
- Have a teaser of text on the page, and in the Colorbox popup the full version of it.
- And more!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

EndEd’s picture

It works great... testing with emfields. Great job

frjo’s picture

Status: Needs review » Fixed

Committed to 6-dev.

Status: Fixed » Closed (fixed)

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

milehighlife’s picture

Category: task » support
Status: Closed (fixed) » Active

frjo,

This is awesome! Thanks so much for your time in putting this together.

I have a question about grouping fields together to display in a gallery. My view lists the fields but when I click on an image, I only get one image to load into colorbox (I want all images listed in the view to load as a colorbox gallery). How do I group the list of images for colorbox?

Thanks again!

frjo’s picture

Colorbox uses the "rel" attribute to group images in galleries.

milehighlife’s picture

Yes! Thank you. I have the trigger field working now. After spending more time with the Colorbox trigger in views I got it setup perfectly! Awesome contribution and thanks again.

froboy’s picture

I'm working on getting this running mostly to combine a title and byline field into my colorbox caption, but instead of simply wrapping the selected trigger (in my case, an image), it seems to be rendering the trigger again and then wrapping that second image in the colorbox. I could just turn display of the first image off, but then I'd have to duplicate all of the text fields that I want to use both in the display and in the colorbox.

Now my view looks like:
-image (trigger)
-image (large, no-display, for colorbox content)
-description
-byline
-colorbox trigger

But it displays:
-image
-description
-byline
-image with colorbox trigger

And in order to get the display I want, it seems like I'd have to do this, which seems kinda crazy:
-image (trigger)
-image (large, no-display, for colorbox content)
-description (no-display)
-byline (no-display)
-colorbox trigger
-description
-byline

Does that make any sense?

jessejesse’s picture

Anyone able to get the Caption field to render HTML? I'm trying to include some divs and/or line breaks and nothing seems to work. This is what it looks like now....

[nothing1]<br />[nothing2]

but it just ends up printing both fields inline with no break.

thanks in advance.

frjo’s picture

froboy: Only fields that appear before the trigger field itself can be used by it. Fields that comes after can't be seen by the trigger field. This is a views limitation.

And yes the Colorbox trigger field will render the filed you select to be the trigger field so that filed should be set to excluded.

The Colorbox trigger field is not the most intuitive solution and it lacks documentation. It is however very flexible and with time it's my aim that this feature will grow up and get documentation.

froboy’s picture

frjo: thanks for the clarification. I managed to make it work with the method I mentioned above.

jessejesse: I'm having the same issue. Text markup comes through fine, but HTML does not. I just used a pipe | to separate my fields for the time being...

frjo’s picture

By default the Colorbox script takes the caption from the title attribute and that means no tags, the l() function strips them out.

I attach a patch that sends the caption as a JavaScript setting directly yo the Colorbox plugin instead. This will allow tags in the caption. Please try it out.

What should we do with the title attribute for the Colorbox trigger? Just keep it as is, don't set it at all or et it to something else?

baxterjones’s picture

btw: great module, anything with views enabled featured is crazy flexible.

what i want to do is somewhat one step further... i would like to display a list of nodes as teasers in the box. kind of like facebook's view friends where you have all of the friends listed over the content in a colorbox.

check image for better explanation

is this possible?

frjo’s picture

snowvirus: Happy to here that you find the Colorbox module useful!

For that you would need to build a view and style it with a custom page template to remove sidebars etc.

Next step is to activate the Colorbox load setting and build a link to the view and give it a class "colorbox-load".

The link takes queries, "[path]?width=500&height=500&iframe=true".

This feature needs some good documentation.

jessejesse’s picture

Frjo,

Thanks for the colorbox caption patch. I applied it but saw no change in the behavior... Let me get more specific....

When using a Colorbox Trigger in a view. There is a section for "Caption" it says...

Combine tokens from the "Replacement patterns" below and html to create the caption for the Colorbox. Leave empty for no caption.

... However no html tags work in that caption box... whether I try and use a line break or a div tag, nothing works. Replacement patterns show up, but all the html is stripped out... even with the patch installed.

Cheers,
Jesse

frjo’s picture

Category: support » feature
Status: Active » Needs review

I have committed patch #11 since it works for me. I removed the title attribute from the link, it will just look weird since it strips out all html.

mike_foe’s picture

Hi frjo,

I'm pretty new to Views and stumbled about your colorbox lately. It works fine with pictures and nodes when I enter it into the source code of a node.

Now I've got a view that displays all articles with product image, product title, price and buy-it button (I'm using ubercart). I can get the product image in a colorbox. If I click on the product title, the page with the details comes up.

To make it maybe a bit clearer, here is the link : Forganix

Now I'd like to show the details in a colorbox if you click on the link or even better if you hover over the link.

I'm using the latest dev version of colorbox, and I can see the option to insert a Colorbox trigger.

An here's my problem : I just can't get the colorbox come up. Could you please give an example of code that shows up the requested node in a colorbox.

Thanks a lot!

Mike

Alsciende’s picture

Version: 6.x-1.x-dev » 6.x-1.0-beta7
Component: Code » Documentation

edit: I solved my problem. But you're right when you say that this feature needs documentation :)

What I missed was the necessity to have both size of an image in the fields of a View. Then you can tell Colorbox to trigger on the smaller size to display the larger size. You can't do anything as long as you have only one size in the fields.

iparsin’s picture

Extremely useful add-on, thank you so much "frjo". Your module with this features is much more flexible and faster loading compared to node in Lighbox2.

oschuetze’s picture

I have a node-based gallery with my own content-types for the image and the gallery. If I add this Trigger after a (invisible) Image field in the gallery view, this image will be shown in a colorbox - this works fine. But there is a whole grid of images - only the clicked image is shown in the colorbox. The colorbox doesn't recognize that a next/prev-button is needed. How should I configure the trigger field?
Regards,
Oliver

frjo’s picture

next/prev-button is activated for images with the same "rel" value. By default the trigger field set it to "gallery-[view name]" but there are setting (Colorbox gallery) where you can set it to anything you like.

oschuetze’s picture

how can I set the "rel" value of the images?

frjo’s picture

@oschuetze, use the Colorbox gallery setting in the trigger field options I mentioned above.

inolen’s picture

Edit: Nevermind.

hedac’s picture

ok.. I was having a problem where I had my image which was the trigger field... configured as a colorbox already... so.. no.. the trigger field must be only an image.. not a colorbox.. if not.. it will trigger the normal colorbox.

hedac’s picture

one problem I find is..
if using 640px as width.. and 100% as height... then it uses 100% as height.. but the width.. is not respected in pixels.. by using both measures in px then it works.

a bit of css hack:
my problem is displaying pictures that have different widths... because some are horizontal and some are vertical... horizontal pictures have 640px width while vertical pictures have 640px height. and below the picture there is a variable body text description. so it would be nice to center the content at least.

#cboxLoadedContent{
text-align: center;
display:table-cell; 
vertical-align:middle;
}

this code aligns the content centered in the colorbox window

I know I can't control the body text and I don't have a problem if there is a lot of text then the scroll bar appears.

hedac’s picture

I've just found that using table-cell hides the scrollbar if the content is bigger than the height of the container... :/
so I don't know how to center vertically.. but at least horizontally.

1timer’s picture

sub

scotwith1t’s picture

i would just add that you may want to do like gmap does and disable previews when a trigger field is in use since this will not work when you're in the views edit screen...not sure how hard that is or if it's possible at all, but i had given up until i saved the view to realize what i had been doing all along was working :)

Eaglecanada’s picture

spent one hour play around with the colorbox trigger, still can't get it work.

What I wanted to achive is
(similar in http://drupal.org/node/826740):

in a view listing all gallery nodes, for each node, only display one thumbnail image, when click on this image, it will bring to the colorbox pop up to display all images assoicated with this node.

What i did:
in View/fields, add content image, group multiple valuse to show only one image, fromat: thumbnail image;

in view/fields, add another content image([field_image_fid_1]), show all images but set to exclude from display.

in colocbox trigger: selected the first content image as trigger;
in colorbox trigger/popup, aadded second image token: [field_image_fid_1],

But when click on the thumbnail image, the popup shows duplcated images( if the node has 4 images, it will show like 7 images, including one that displying all thumbnail images, adn one duplcated with the thimbnail image)

Any suggestions? can this be done using Colorbox trigger?

thanks!

baxterjones’s picture

@Eaglecanada. Some help.
there is a snippet attached which is from my views export.
I have a link on my homepage to show cinema schedules.. the site is www.namlish.com now the when users click on the link then they should see the image thumb, with the movie showing times and i didn't want the users to close and then check the next schedule. So how i did this was with next buttons (made possible by selecting the 'Image field gallery: Per page gallery' in the colorbox options page (*/admin/settings/colorbox)

and walla!
I used the same method for having youtube embedded videos display in the colorbox too.

Bartezz’s picture

Having some problems too, probably doing things wrong but cant see where!

I have a view (fields) which loads images from various nodes;

Field -> Content: Image (field_image)
Excluded from display
Group multiple values -> show 1 value
Label-> none

Field -> Colorbox: Colorbox trigger
Trigger field -> Image (field_image)
Automatic generated Colorbox gallery -> checked
Custom Colorbox gallery: veryunique123

Now when I click one of the images the colorbox shows the single image and one can not prev or next. I've noticed that the rel attribute is different for the images so that's the problem. But how can I tune this so the rel is the same for the images loaded thru this view?

I don't want to change the global the per page gallery setting as this would mess up things elsewhere...

Help appreciated!

Cheers

Tony Finlay’s picture

Is this possible in D7 release?

Sinan Erdem’s picture

subscribing for D7

jorisx’s picture

would be really nice feature for D7

lsolesen’s picture

You should put D7 requests in a different issue.

Cablestein’s picture

I'm using this as well, did get it to work with paging at some point. Nice work!

Annoyance:

With Views I'm rendering a grid of thumbnails.

If I render the thumbnails with a CCK Image Field, then in the Views field settings for the thumbnail, I see "Colorbox" options in the long format drop-down list. Using this field as a Colorbox trigger, it will output as a regular URL with no messy parameters (great!), and the results of this field get grouped into pages in the modal (wonderful).

Conversely, if I render the thumbnails by using the image field provided by the Image Module, then in Views I add a field "Image: Image", the settings for this field include no options regarding format or Colorbox. Instead I get a short drop down list of image sizes (as defined by the Image module settings in admin). Using this field as a Colorbox trigger will output working Colorbox modal functionality, with grouped paging... BUT the URL is full of messy parameters and does not degrade gracefully.

Another test, if I select a body field as a Colorbox trigger, the URL is messy with parameters. Obviously there's no file to link to like in the above example, but at least there code be a node link.

Is this an issue with Core, Views or Colorbox?

Is this essentially a formatting option which has to be extended further?

Views fields that have no Colorbox formatter seem to output a link that's messy with parameters. This kind of link doesn't degrade well (if Javascript is turned off) and isn't SEO friendly. Whereas a Views field which has a Colorbox formatter as an option, the link that gets outputted is a clean regular URL direct to the file

frjo’s picture

Status: Needs review » Closed (fixed)
bellagio’s picture

This is what i'm trying to do - Have a "view full size" link as the trigger, instead of an image.

My problem is if there are 5 images, "view full size" shows 5 times.
When i make my link show only once, then colorbox shows all 5 images vertically together...

Anyone made this work? please help.

warmth’s picture

Due this is an issue coming from the trigger, can somebody here help me:

#1852384: wyciwyg issue with Colorbox Trigger in views

estela_t’s picture

This is an old thread but really hoping I can get some help... I've tried applying both patches (to v7) and both fail to apply. I'm having the same issue mentioned above and in other threads of not being able to use HTML tags in the caption, which we need to italicize portions of the title. I tried manually applying the changes in the caption patch as well, and no luck. Any help would be super appreciated!

froboy’s picture

estela_t I doubt you're going to get much of a reply here. I'd recommend opening a new issue and linking to this as a related issue.