Section | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
Include Page | ||||
---|---|---|---|---|
|
...
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. (For a description of how to use this <form>
approach, see Talking to the Server Using The afterMove Event.) A simple example of this could be:
Code Block | ||||
---|---|---|---|---|
| ||||
<form action="#"> <a href="myImage1.jpg"> <img src="myImage1.jpg" alt="image 1 thumbnail" /> <span>Image 1</span> <input name="image 1" value="0" type="hidden" /> </a> <a href="myImage2.jpg"> <img src="myImage2.jpg" alt="image 2 thumbnail" /> <span>Image 2</span> <input name="image 2" value="1" type="hidden" /> </a> <a href="myImage3.jpg"> <img src="myImage3.jpg" alt="image 3 thumbnail" /> <span>Image 3</span> <input name="image 3" value="2" type="hidden" /> </a> ... </form> |
The Image Reordeer Reorderer needs to know about the 'container' of your image collection. In this case, that could would be the <form>
element. The Reorderer accepts a jQuery selector, But since there may be other <form>
elements in the markup, you will need to uniquely identify the <form>
you want to use as a container.
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:
Section | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
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.
...
Note | ||
---|---|---|
| ||
Currently the Image Reorderer is limited to using |
You also need to tell the Reorderer which of your images should be reorderable and 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 - with the Image Reorderer this is possible. For this tutorial, though, we'll make all contained images 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 , but you can override that if you like, but for . For this tutorial, we'll go the simple route. The default classname is stick with the defaults classname flc-imageReorderer-item
, so let. Let's add that to each of the <a>
elements:
Section | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
You can identify the captions using a custom classname, or use the default selector classname , flc-reorderer-imageTitle
:
Code Block | ||||
---|---|---|---|---|
| ||||
<form action="#" id="reorder-images-form"> <a href="myImage1.jpg" class="flc-imageReorderer-item"> <img src="myImage1.jpg" alt="image 1 thumbnail" /> <span class="flc-reorderer-imageTitle">Image 1</span> <input name="image 1" value="0" type="hidden" /> </a> <a href="myImage2.jpg" class="flc-imageReorderer-item"> <img src="myImage2.jpg" alt="image 2 thumbnail" /> <span class="flc-reorderer-imageTitle">Image 2</span> <input name="image 2" value="1" type="hidden" /> </a> <a href="myImage3.jpg" class="flc-imageReorderer-item"> <img src="myImage3.jpg" alt="image 3 thumbnail" /> <span class="flc-reorderer-imageTitle">Image 3</span> <input name="image 3" value="2" type="hidden" /> </a> ... </form> |
...
Step 2: Write the script
YouTo make the HTML you just created do something special, you'll need to create a file to contain your initialization script - the script you write to apply the Reorderer to your image collection.
Section | |||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...
Step 3: Add the script to your HTML
You'll need to add your initialization script, along with the Infusion library, to you HTML file. In the header of the file, link to the Javascript files with <script>
tags:
...
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:
Code Block | html | html | ||
---|---|---|---|---|
| ||||
<script type="text/javascript" src="../../../../lib/jquery/core/js/jquery.js"></script> <script type="text/javascript" src="../../../../lib/jquery/ui/js/jquery.ui.core.js"></script> <script type="text/javascript" src="../../../../lib/jquery/ui/js/jquery.ui.widget.js"></script> <script type="text/javascript" src="../../../../lib/jquery/ui/js/jquery.ui.mouse.js"></script> <script type="text/javascript" src="../../../../lib/jquery/ui/js/jquery.ui.draggable.js"></script> <script type="text/javascript" src="infusion-1.2/lib/jquery../../../../framework/core/js/jqueryFluidDocument.js"></script> <script type="text/javascript" src="infusion-1.2/lib/jquery/ui../../../../framework/core/js/jquery.ui.corekeyboard-a11y.js"></script> <script type="text/javascript" src="infusion-1.2/lib/jquery/ui/js/jquery.ui.widget../../../../framework/core/js/Fluid.js"></script> <script type="text/javascript" src="infusion-1.2/lib/jquery/ui/js/jquery.ui.mouse../../../../framework/core/js/FluidDOMUtilities.js"></script> <script type="text/javascript" src="infusion-1.2/lib/jquery/ui/js/jquery.ui.draggable../../../../framework/core/js/FluidView.js"></script> <script type="text/javascript" src="infusion-1.2../../../../framework/core/js/jquery.keyboard-a11yDataBinding.js"></script> <script type="text/javascript" src="infusion-1.2../../../../framework/core/js/FluidFluidIoC.js"></script> <script type="text/javascript" src="infusion-1.2/framework/core../../../../components/reorderer/js/FluidDOMUtilitiesReordererDOMUtilities.js"></script> <script type="text/javascript" src="infusion-1.2text/javascript" src="../../../../components/reorderer/js/GeometricManager.js"></script> <script type="text/javascript" src="infusion-1.2../../../../components/reorderer/js/Reorderer.js"></script> <script type="text/javascript" src="infusion-1.2../../../../components/reorderer/js/ImageReorderer.js"></script> <script type="text/javascript" src="image-collection.js"></script> |
...
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 or use the default Infusion Image Reorderer comes with a set of CSS styles that have been carefully created by interface and interaction designersstyle.
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 reorderer container element, using
fl-imageReorderer
andfl-reorderer-horizontalLayout
, - the reorderable elements themselves, using
fl-imageReorderer-item
, and - the captions, using
fl-imageReorderer-caption
.
...
The 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
If you choose to use CSS classname different than the defaults, you can override the defaults using the options
parameter to the reorderImages()
function.
...