Simple List Reorderer Tutorial - v0.4

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.

Simple List Reorderer Tutorial - v0.4


Step 0: Download and install the Fluid Infusion library

  1. Download a copy of the Fluid Infusion component library from:

    • http://fluidproject.org/index.php/downloads
      You only really need the "Minified deployment package," but if you want to actually look at the code, you should download the "Source package."

  2. 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 it's name (e.g. fluid-0.4/). The rest of this tutorial will use fluid-0.4 in its examples, but if you downloaded a different version, you'll have to adjust.


Step 1: Prepare your markup

You also need to tell the Reorderer which of your list items should be reorderable. Perhaps the first item on your list, "Select the date," really needs to stay the first item, since everything else depends on the date. You don't want that item to be moveable, so you can't just make every list item orderable.

You'll tell the Reorderer which items are to be orderable with another jQuery selector. Let's add a CSS class for that, say movable:

That's all - these are the only changes you need to make to your HTML.


Step 2: Write the script

You'll need to create a file, say todo-list.js, to contain your initialization script - the script you write to apply the Reorderer to your list.

In this file, write a function that calls the :

jQuery(document).ready(function () { return fluid.reorderList("#todo-list", ".movable"); });

In this function call, the first parameter, "#todo-list", is a jQuery selector identifying the element with the ID "todo-list". The second parameter is a jQuery selector identifying elements with the CSS class "movable". That's all the information required by the fluid.reorderList() function.

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


Step 3: Add the script to your HTML

You'll need to add your initialization script, along with the Fluid library, to you HTML file. In the header of the file, link to the Javascript files with <script> tags:

<script type="text/javascript" src="fluid-0.4/fluid-components/js/Fluid-all.js"></script> <script type="text/javascript" src="todo-list.js"></script>

NOTE that the Fluid-all.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="fluid-0.4/fluid-components/js/jquery/jquery-1.2.6.js"></script> <script type="text/javascript" src="fluid-0.4/fluid-components/js/jquery/jquery.keyboard-a11y.js"></script> <script type="text/javascript" src="fluid-0.4/fluid-components/js/jquery/jARIA.js"></script> <script type="text/javascript" src="fluid-0.4/fluid-components/js/fluid/Fluid.js"></script> <script type="text/javascript" src="fluid-0.4/fluid-components/js/fluid/Reorderer.js"></script> <script type="text/javascript" src="todo-list.js"></script>

But all of these individual files are not necessary to make it work - the Fluid-all.js file has everything you need.

That's it! That's all you need to do to make your list reorderable!


Step 4: Apply styles

BUT: If you look at your file in a browser now, it doesn't look any different than it looked before - there's no way to tell that your list items are reorderable. That's what the styles are for.

There are a number of "interesting moments" that happen when dealing with a reorderable list. These include, for example, when the mouse hovers over a reorderable item, or when an item is selected using the keyboard. The Reorderer automatically applies CSS classes to the list items to mark these interesting moments. You can use these classes to define styles that inform users of the moments.

The CSS classes that are applied by the Reorderer, and the 'interesting moments' they are used for, are described below.

If we add a stylesheet with these styles (along with some global styles to make the font look a bit nicer, etc.), your list will look like this:

When you hover over an item, it will be apparent:

If you use the tab and arrow keys to select an item, you'll be able to tell:

And while you're dragging, you'll be able to tell where the drop will happen: