This tutorial is incomplete - treat it with caution.
This page will walk you through an example of using the Infusion Reorderer's reorderImages() function to reorder image thumbnails in a collection.
This tutorial assumes that:
- you are familiar with what the Image Reorderer is and does
- now you just want to know how to add it to your file.
Tutorial: How to Use the Image Reorderer
Suppose you're not satisfied with any of the image sharing applications currently available on the web, and you're convinced that you can write a better one. You want to use Infusion's Image Reorderer to let your users re-arrange the images in their collections.
There are five basic steps to using the Image Reorderer in your application:
- Setup: Download and install the Fluid Infusion library
- Step 1: Prepare your markup
- Step 2: Write the script
- Step 3: Add the script to your HTML
- Step 4: Apply styles
The rest of this tutorial will explain each of these steps in detail.
Setup: Download and install the Fluid Infusion library
- Download a copy of the Fluid Infusion component library from:
You only really need the "Minified deployment package," but if you want to actually look at the code, you should download the "Source package."
- Unpack the zip file you just downloaded, and place the resulting folder somewhere convenient for your development purposes.
The folder will have the release number in its name (e.g. infusion-1.4/). The rest of this tutorial will use infusion-1.4 in its examples, but if you downloaded a different version, you'll have to adjust.
Step 1: Prepare your markup
Let's suppose you're using a
<form> with hidden
<input> elements to record the ordering of the images in your collections. A simple example of this could be:
The Image Reordeer needs to know about the 'container' of your image collection. In this case, that could be the
<form> element. The Reorderer accepts a jQuery selector, so you can choose any method that will uniquely identify the
<form> element. We'll attach a unique ID to it:
You also need to tell the Reorderer which of your images should be reorderable. Most of the time, that will likely be all of them, but perhaps you want the first image to always be first, since it's the cover of the album. For this tutorial, though, we'll make all of the image movable.
You'll tell the Reorderer which items are to be orderable with another jQuery selector. The Image Reorderer understands a default class name for this purpose. You can override that if you like, but for this tutorial, we'll go the simple route. The default classname is
flc-imageReorderer-item, so let's add that to each of the
Finally, you'll want to tell the Image Reorderer which part of your markup is the caption for the image. The Image Reorderer will use this information to help make your image collection more usable by people using assistive technologies, such as a screen reader.
You can identify the captions using the default selector classname,
Step 2: Write the script
You'll need to create a file to contain your initialization script - the script you write to apply the Reorderer to your image collection.
Create a file, say
image-collection.js, and in this file, write a function that looks like this:
In this function call, the parameter to
"#reorder-images-form", is a jQuery selector identifying the element with the ID
reorder-images-form. That's all the information required by the
By enclosing the function call inside
jQuery(document).ready(), we ensure that the HTML is fully rendered before we apply the Reorderer to it.
Step 3: Add the script to your HTML
Keep in mind that the
InfusionAll.js file is minified - all of the whitespace has been removed - so it isn't really human-readable. If you're using the source distribution and you want to be able to debug the code, you'll want to include each of the required files individually. This would look like this:
But all of these individual files are not necessary to make it work - the
InfusionAll.js file has everything you need.
That's it! That's all you need to do to make your images reorderable!
Step 4: Apply styles
You can style your image gallery any way you choose (of course), but the Infusion Image Reorderer comes with a set of CSS styles that have been carefully created by interface and interaction designers.
Using the default styles
You can take advantage of the Image Reorderer styles provided with the component by simply adding the default styling class names to your markup. The Image Reorderer will take care of the rest.
There are three things you'll want to add styling classnames to:
- the container element, using
- the reorderable elements themselves, using
- the captions, using
fl-reorderer-horizontalLayout will lay the images out horizontally, and will make sure that the drop marker shows up between the thumbnails properly.
Customizing the styles
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
Step 2 - Add element IDs
The second step is to add IDs to the elements that the Image Reorderer 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":
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:
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. This initialization function has the form
The Lightbox initialization function allows you to pass in a number of optional parameters to configure some aspects of the Lightbox, including a 'callback' function. The callback communicates changes in the ordering of images back to the server. In its "out-of-the-box" form, the Lightbox includes a default callback function that uses a form with hidden
<input> elements in the markup to record the indexes of the elements. For our example, we will disable the default callback by specifying an empty function as one of the optional parameters:
Step 4 - Define styles
The final step is to create styles so that 'interesting moments' in the reordering of images are easily apparent to the user.
The Image Reorderer pre-defines a number of class names that will be used for this purpose. It's possible, through the optional configuration, to override these class names, but for this example, we'll just define styles for the default class names.
The first style is the default style to be applied to any image thumbnail. For our example, we'll float the images so that they appear to be in a grid, and give them a background colour:
The second style is applied to the element that has been selected. A visual indication will inform users that the thumbnail can be moved using keystrokes. For our example, we'll change the background colour:
The Image Reorderer also supports mouse-based drag and drop, and another style is used when the cursor hovers over a thumbnail, to inform users that the thumbnail can be moved using the mouse. For our example, we'll change the background colour again, but we'll use a different colour:
When a thumbnail is in the process of being moved, either by keyboard or by mouse-based drag and drop, a 'dragging' style is applied to the thumbnail to indicate this. We'll change the background colour for this:
When the mouse is used to pick up a thumbnail and move it, an 'avatar' is created to represent the thumbnail being dragged. By default, the avatar is a copy of the item. A style is applied that can be used to modify the appearance of the avatar. For our example, we will make it semi-transparent:
Finally, when the mouse is used to move a thumbnail, a 'drop marker' is displayed in the location where the thumbnail will end up if it is dropped. The last style is used to control what that marker looks like. We'll make it a vertical red bar:
That's it! Your Image Reorderer is now functional, and you can rearrange the images in your collection. Congratulations!