Child pages
  • Tutorial - Image Reorderer

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Section
Column
width60%

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 already familiar with HTML, Javascript and CSS
  • you are familiar with what the Image Reorderer is and does
  • now you just want to know how to add it to your file.

For more general information about the Reorderer, see Reorderer. For technical API documentation, see Image Reorderer API and Advanced Reorderer API.


Tutorial: How to Use the Image Reorderer

Scenario

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.

Column
Panel
borderColor#321137
bgColor#fff
titleBGColor#aab597
borderStylesolid
titleStatus
borderStylesolid

This component is in Production status

solid
Panel
borderStyle
borderColor#566b30
bgColor#fff
titleBGColor#D3E3C4
borderStylesolid
titleOn This Page
Table of Contents
toc
maxLevel
5
minLevel2
maxLevel5
Panel
borderColor#321137
bgColor#fff
titleBGColor#c1b7c3
borderStylesolid
titleSee Also
borderStylesolid
Panel
borderColor#321137
bgColor#fff
titleBGColor#cccccc
borderStylesolid
titleStill need help?
borderStylesolid

Join the infusion-users mailing list and ask your questions there.

...

Include Page
Infusion13:Tutorial SetupInfusion13:
Tutorial Setup

...

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:

...

Section
Column
Code Block
html
html
<form action="#" id="reorder-images-form">
    ...
Column
Panel
borderColor#566b30
bgColor#D3E3C4
borderStyleoutset
titleNote
borderStyleoutset

This example uses an ID, but you might, for example, use a CSS class, or the element hierarchy - whatever works, so long as it uniquely identifies the right element.

...

Section
Column
Code Block
html
html
<form action="#" id="reorder-images-form">
    <a href="myImage1.jpg" class="flc-imageReorderer-item">
        <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" class="flc-imageReorderer-item">
        <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" class="flc-imageReorderer-item">
        <img src="myImage3.jpg" alt="image 3 thumbnail" />
        <span>Image 3</span>
        <input name="image 3" value="2" type="hidden" /> 
    </a>
    ...
</form>
Column
As with the ID on the {{<form>}}, we can use any jQuery selector for the reorderable images. For example, we could attach a unique ID to each movable {{<a>}} with a unique prefix, maybe {{pic-movable1}}, {{pic-movable2}}, etc. Then we could use the jQuery selector {{\[id^=pic-movable\]}} to override the default
Panel
borderColor#566b30
bgColor#D3E3C4
titleNote
borderStyleoutset
Wiki Markup
titleNote

As with the ID on the <form>, we can use any jQuery selector for the reorderable images. For example, we could attach a unique ID to each movable <a> with a unique prefix, maybe pic-movable1, pic-movable2, etc. Then we could use the jQuery selector [fluid:id^=pic-movable] to override the default selector.

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.

...

Code Block
html
html
<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

To 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
Column

Create a file, say image-collection.js, and in this file, write a function that looks like this:

Code Block
javascript
javascript
jQuery(document).ready(function () {
    return fluid.reorderImages("#reorder-images-form");
});

In this function call, the parameter to reorderImages(), "#reorder-images-form", is a jQuery selector identifying the element with the ID reorder-images-form. That's all the information required by the fluid.reorderList() function.

By enclosing the function call inside jQuery(document).ready(), we ensure that the HTML is fully rendered before we apply the Reorderer to it.

Column
Panel
borderColor#566b30
bgColor#D3E3C4
borderStyleoutset
titleNote
borderStyleoutset

If you choose to use a custom selector for the movable items (instead of the default classname), you can override the default using options passed as the second parameter. Define an options block that specifies the selector you'd like, and pass it to the function:

Code Block
javascript
javascript
jQuery(document).ready(function () {
    var opts = {
        selectors: {
            movables: "[id^=pic-movable]"
        }
    };
    return fluid.reorderImages("#reorder-images-form", opts);
});

For more information on selectors and other options, see the Image Reorderer API documentation.

...

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:

...

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:

  1. the reorderer container element, using fl-imageReorderer and fl-reorderer-horizontalLayout,
  2. the reorderable elements themselves, using fl-imageReorderer-item, and
  3. 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.

...