Child pages
  • Tutorial - Image Reorderer

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
html
html
<form action="#">
    <a href="myImage1.jpg">
        <img src="myImage1.jpg" alt="image 1 thumbnail" />
        <span">Image<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<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<span>Image 3</span>
        <input name="image 3" value="2" type="hidden" /> 
    </a>
    ...
</form>

...

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<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<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<span>Image 3</span>
        <input name="image 3" value="2" type="hidden" /> 
    </a>
    ...
</form>
Column
Panel
borderColor#566b30
bgColor#D3E3C4
titleNote
borderStyleoutset

Wiki Markup
As with the ID on the {{<form>}}, we can use any jQuery selector. 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 selector.

Step 2: Write the script

YouFinally, 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:

...


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.

...

borderColor#566b30
bgColor#D3E3C4
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:

...

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, flc-reorderer-imageTitle:

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>
        
movables: "[id^=pic-movable]"
<input name="image 3" value="2" type="hidden" /> 
    
}
</a>
    
}; 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:

...


<script type="text/javascript" src="infusion-1.0/InfusionAll.js"></script>
<script type="text/javascript" src="image-collection.js"></script>

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:

...


<script type="text/javascript" src="infusion-1.0/lib/jquery/core/js/jquery.js"></script>
<script type="text/javascript" src="infusion-1.0/lib/jquery/ui/js/ui.core.js"></script>
<script type="text/javascript" src="infusion-1.0/lib/jquery/ui/js/ui.draggable.js"></script>
<script type="text/javascript" src="infusion-1.0/framework/core/js/jquery.keyboard-a11y.js"></script>
<script type="text/javascript" src="infusion-1.0/framework/core/js/Fluid.js"></script>
<script type="text/javascript" src="infusion-1.0/framework/core/js/FluidDOMUtilities.js"></script>
<script type="text/javascript" src="infusion-1.0/components/reorderer/js/GeometricManager.js"></script>
<script type="text/javascript" src="infusion-1.0/components/reorderer/js/Reorderer.js"></script>
<script type="text/javascript" src="infusion-1.0/components/reorderer/js/ImageReorderer.js"></script>
<script type="text/javascript" src="image-collection.js"></script>

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!

...

...
</form>

...

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.

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
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:

Code Block
html
html

<script type="text/javascript" src="infusion-1.0/InfusionAll.js"></script>
<script type="text/javascript" src="image-collection.js"></script>

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="infusion-1.0/lib/jquery/core/js/jquery.js"></script>
<script type="text/javascript" src="infusion-1.0/lib/jquery/ui/js/ui.core.js"></script>
<script type="text/javascript" src="infusion-1.0/lib/jquery/ui/js/ui.draggable.js"></script>
<script type="text/javascript" src="infusion-1.0/framework/core/js/jquery.keyboard-a11y.js"></script>
<script type="text/javascript" src="infusion-1.0/framework/core/js/Fluid.js"></script>
<script type="text/javascript" src="infusion-1.0/framework/core/js/FluidDOMUtilities.js"></script>
<script type="text/javascript" src="infusion-1.0/components/reorderer/js/GeometricManager.js"></script>
<script type="text/javascript" src="infusion-1.0/components/reorderer/js/Reorderer.js"></script>
<script type="text/javascript" src="infusion-1.0/components/reorderer/js/ImageReorderer.js"></script>
<script type="text/javascript" src="image-collection.js"></script>

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:

  1. the 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.
Code Block
html
html

<form action="#" id="reorder-images-form" class="fl-imageReordererfl-reorderer-horizontalLayout">
    <a href="myImage1.jpg" class="flc-imageReorderer-item fl-imageReorderer-item">
        <img src="myImage1.jpg" alt="image 1 thumbnail" />
        <span class="flc-reorderer-imageTitle fl-imageReorderer-caption">Image 1</span>
        <input name="image 1" value="0" type="hidden" /> 
    </a>
    <a href="myImage2.jpg" class="flc-imageReorderer-item fl-imageReorderer-item">
        <img src="myImage2.jpg" alt="image 2 thumbnail" />
        <span class="flc-reorderer-imageTitle fl-imageReorderer-caption">Image 2</span>
        <input name="image 2" value="1" type="hidden" /> 
    </a>
    <a href="myImage3.jpg" class="flc-imageReorderer-item fl-imageReorderer-item">
        <img src="myImage3.jpg" alt="image 3 thumbnail" />
        <span class="flc-reorderer-imageTitle fl-imageReorderer-caption">Image 3</span>
        <input name="image 3" value="2" type="hidden" /> 
    </a>
    ...
</form>

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

...

Step 1 - Include the Fluid component library

...