Documentation for a historical release of Infusion: 1.3
Please view the Infusion Documentation site for the latest documentation.
If you're looking for Fluid Project coordination, design, communication, etc, try the Fluid Project Wiki.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

This page will walk the reader through the steps necessary to use the Lightbox component. For specific information about the Lightbox API, see Lightbox API.


Tutorial: Making images reorderable

The Lightbox is a Fluid component designed to provide the ability to re-order images within a collection. Let's suppose you have some simple markup displaying a small collection of images. To use the Lightbox, your image thumbnails must each be within a <div> element, and the collection of thumbnails must be contained within an element. A simple example of this could be:

<html>
  <head>
    <title>Image Collection</title>
  </head>

  <body>

    <div>
      <div><img src="img1.jpg"/></div>
      <div><img src="img2.jpg"/></div>
      <div><img src="img3.jpg"/></div>
    </div>

  </body>
</html>

Step 1: Include the Fluid component library

The first step is to include the Fluid component library code in your file. Do this by adding a script tag to the header referencing the Fluid-all.js javascript file:

<head>
  <title>Image Collection</title>
  <script type="text/javascript" src="Fluid-all.js"></script>
</head>

Step 2: Add element IDs

The second step is to add IDs to the elements that the Lightbox needs to know about.

First, add an ID to the element that contains all of the image thumbnails. This ID can be anything unique. For this example, we'll use "image-collection":

<div id="image-collection">
  ...
</div>

Next, we need to add a unique ID to each of the thumbnail <div> s. This ID must be of a specific form: it must start with the string that was used for the container ID, followed by "lightbox-cell:", a number indicating the index, and finally a ":". This is shown below for our example:

<div id="image-collection">
  <div id="image-collectionlightbox-cell:1:"><img src="img1.jpg"/></div>
  <div id="image-collectionlightbox-cell:2:"><img src="img2.jpg"/></div>
  <div id="image-collectionlightbox-cell:3:"><img src="img3.jpg"/></div>
</div>

I know this seems a bit complex, but in the real world, these IDs will be generated by the server, and you won't have to write them by hand.

Step 3: Add initialization script

The third step is to actually create the Lighbox by calling the initialization script.

In its "out-of-the-box" form, the Lightbox includes a mechanism for sending any changes in the ordering of images back to the server via a callback function. This default callback function uses a form with hidden <input> elements in the markup to record the indexes of the elements.

The Lightbox initialization function allows you to pass in a number of optional parameters to configure some aspects of the Lightbox, including the callback function. For our example, we will disable the callback by specifying an empty function:

<script type="text/javascript">
  fluid.lightbox.createLightboxFromIds ("image-collection", {orderChangedCallback : function(){}});
</script>

Step 4: Define styles

.orderable-default{
    background-color: #eee;
}

.orderable-hover{
    background-color: lightyellow;
    cursor: move;
}

.orderable-selected{
    background-color: #ddd;
}

.orderable-dragging {
    background-color: lightyellow;
}

.orderable-avatar {
    opacity: 0.55;
    width: 300px;
    border: 0;
}

.orderable-drop-marker{
    background-color: red;
    height: 2px;
    margin: -4px;
    padding: 0px;
}
  • No labels