Lightbox2

From: Peter (BOUGHTONP)16 May 2012 16:33
To: af (CAER) 84 of 91
quote:
The main issue is determining what the 'Next' and 'Previous' images are – there's no easy way to figure it out.

Without having any idea of the context of this, you identify them by checking the class and rel attributes - i.e. [class=nav][rel=next] and [class=nav][rel=prev] - which is perfectly easy to do?
From: af (CAER)16 May 2012 16:37
To: Peter (BOUGHTONP) 85 of 91
No, I mean how do you determine which image to show when the user clicks Next or Previous? From what I remember, one implementation had an option to specify list of 'containers', which would be one way to group images/links.
From: Peter (BOUGHTONP)16 May 2012 17:18
To: af (CAER) 86 of 91
:? You seem to be making a mountain out of a wormhill.

You show the image that is the immediate sibling of the current one.

If you are at the end of a container you do one of three things:

1) nothing (maybe display some "end" message/indication)
2) loop back to other end of current container
3) proceed to first/last image of next/prev container

Which of those three you do would be a configuration option, and/or dependant on what key the user presses.

For example:
code:
function determineNextChild( container )
{
	if ( container.hasNextChild() ) return container.nextChild()

	switch ( EndImageBehaviour )
	{
		case 'nothing' : return null
		case 'loop'    : return container.firstChild()
		case 'proceed' : return container.nextContainer().firstChild()
		default : error("Invalid EndImageBehaviour setting")
	}

}


To identify the containers, you simply have an array of dom nodes/pointers. These are provided either as a single parent element (if the HTML is all in one piece), and/or as an array of individual containers (if they are separated/mixed in the HTML), in both cases either using CSS selectors, or as raw DOM nodes.

code:
ContainerParent : document.getElementById('MyContainers')

code:
Containers : ['#album1','#album3','.otheralbums:not(#al7)']


etc.
From: af (CAER)16 May 2012 17:39
To: Peter (BOUGHTONP) 87 of 91
quote:
You show the image that is the immediate sibling of the current one.
That's the problem – no assumptions are (currently, at least) made about the structure of the HTML. The script attaches a click handler to the document body and, starting with the event's target, works its way up through the DOM tree until it finds an appropriate link (in which case it shows a popup), or it reaches the top of the tree. It has no knowledge of adjacent nodes, nor at what level it should start traversing back down the tree to find the next link. There needn't even be any images on the page itself, merely links to them.

HTML code:
<ul id="container1">
  <li><span>(1 of 3)</span> <a href="kitten.jpg">Kitten</a></li>
  <li><span>(2 of 3)</span> <a href="puppy.jpg">Puppy</a></li>
  <li><span>(3 of 3)</span> <a href="squirrel.jpg">Squirrel</a></li>
</ul>
EDITED: 16 May 2012 17:40 by CAER
From: af (CAER)16 May 2012 17:44
To: Peter (BOUGHTONP) 88 of 91
From: ANT_THOMAS 8 Jun 2012 14:23
To: af (CAER) 89 of 91

I'm guessing you haven't looked much more into this?

 

A friend I'm making a site for wants Next and Prev buttons and I really don't want to use Lightbox :(

From: af (CAER) 8 Jun 2012 15:19
To: ANT_THOMAS 90 of 91
Heh no, I haven't had much time for it, alas. Maybe this weekend if I feel up to it, but no guarantees.
From: ANT_THOMAS11 Jun 2012 10:25
To: af (CAER) 91 of 91
I just thought I'd add that there's no rush. I had a look for lightbox alternatives and found FancyBox which so far seems to do what I want.