Dashboard > Fluid > ... > API documents - v0.3 > Reorderer API - v0.3
Reorderer API - v0.3
Added by Anastasia Cheetham, last edited by Jonathan Hung on Jun 24, 2008  (view change)
Labels: 
(None)


This documentation refers to the v0.3 released version of the Reorderer code. For documentation specific to trunk, please see Reorderer API.

Reorderer Overview

The Reorderer will handle almost any arbitrary stream of markup you pass to it, assuming a very simple contract is maintained:

  1. The orderable elements are contained within some kind of container element.
  2. A selector for the container is passed to the Reorderer upon instantiation.
  3. A selector for the orderable elements themselves is also supplied.

Optional:

  1. Provide a callback function. This will be called by the Reorderer each time the user reorders an element, and is generally used to communicate ordering changes back to the server.
  2. Specify configuration options to customize the behaviour of the Reorderer. These are documented below.

Creating a Reorderer

Lists

fluid.reorderList(containerSelector, itemSelector, orderChangedCallback, options);

Grids

fluid.reorderGrid(containerSelector, itemSelector, orderChangedCallback, options);

Layouts

fluid.reorderLayout(containerSelector, layoutSelectors, orderChangedCallback, options);

More information about these initialization functions are available in the simple list, simple grid, and simple layout documentation pages.

Still need help?

Join the fluid-talk mailing list and ask your questions there.


Advanced use of the Reorderer

For cases where need more control over the configuration of your Reorderer instance, there is a constructor function that allows you to specify the Layout Handler - v0.3 used by the Reorderer, and offers a means to specify your items using functions instead of jQuery selectors. To use this advanced constructor, you need to:

  1. Pass the container of the orderable elements itself to the Reorderer upon instantiation.
  2. Specify a Javascript function that returns a list of all the orderable elements within the container. This function is passed to the Reorderer upon instantiation.
  3. Specify a Layout Handler - v0.3 to deal with the spatial arrangement of orderable elements. The Reorderer includes several layout handlers to choose from out of the box, which will work with most types of markup supported by the Reorderer. The layout handler is passed to the Reorderer upon instantiation.

Optional:

  1. Provide the Layout Handler - v0.3 with a callback to communicate ordering changes to the server.
  2. Specify elements within the container which can be selected, i.e. which should be focused by the arrow keys, but which may or may not be movable.
  3. Specify valid drop targets within the container.
  4. Specify an element within the given movable that is to be used as a 'handle' for the mouse-based drag and drop of the movable.
  5. Configure the keystrokes to be used.
  6. Customize the avatar used with mouse-based drag and drop.
  7. Create CSS styles for desired appearance of orderable elements when selected and dragging.

Constructors

Reorderer(containerEl, findMovables, layoutHandler[, options]);
Reorderer(containerEl, findItems, layoutHandler[, options]);

Parameters

containerEl

The containerEl parameter is the root node of the Reorderer.

findMovables

The findMovables parameter is a function that returns all of the movable elements in the container.

findItems

The findItems parameter is an object containing a number of functions:

findItems {
    movables: function(),  // required
    selectables: function(),   // optional
    dropTargets: function(),   // optional
    grabHandle: function(movable)   // optional
};

movables: A function that returns all of the movable elements in the container. This is the only required item, but if it is the only function used, it can be passed directly to the constructor, as in the first form of the constructor above.

selectables: A function that returns all of the selectable elements in the container. This can be used if the container included elements that the user wishes to be included in the keyboard tab order, but which are not to be movable. All movable elements must also be selectable, so the element list returned by the selectables function must include all of the elements returned by the movables function. If selectables is not provided, the movables function will be used.

dropTargets: A function that returns all of the elements that can be used as drop targets for the mouse-based drag and drop functionality. If dropTargets is not provided, the movables function will be used.

grabhandle: A function that returns the element within the given movable that is to be used as a 'handle' for the mouse-based drag and drop of the movable. This can be used if the implementer wishes to restrict the user to click only on a portion of the movable item. If grabHandle is not provided, the entire movable element will be used.

layoutHandler

The layoutHandler parameter is an instance of a Layout Handler - v0.3.

options

The options parameter is an optional collection of name-value pairs that configure the Reorderer:

Name Description Values Default
role indicates the role, or general use, for this instance of the Reorderer fluid.role.LIST
fluid.role.GRID
fluid.role.LIST
keysets an object containing sets of keycodes to use for directional navigation, and for the modifier key used for moving a movable item. The object must be a list of objects containing the following keys:
modifier : a function that returns true or false, indicating whether or not the required modifier(s) are activated
up
down
right
left
fluid.defaultKeysets = [{
    modifier : function (evt) {
        return evt.ctrlKey;
    },
    up : fluid.keys.UP,
    down : fluid.keys.DOWN,
    right : fluid.keys.RIGHT,
    left : fluid.keys.LEFT
},
{
    modifier : function (evt) {
        return evt.ctrlKey;
    },
    up : fluid.keys.i,
    down : fluid.keys.m,
    right : fluid.keys.k,
    left : fluid.keys.j
}];
cssClassNames an object containing class names for styling the Reorderer. See below for a discussion of CSS styling of the Reorderer The object may contain any of the keys defined in the defaultCssClassNames (shown to the right). And class names not provided will revert to the default.
var defaultCssClassNames = {
    defaultStyle: "orderable-default",
    selected: "orderable-selected",
    dragging: "orderable-dragging",
    mouseDrag: "orderable-dragging",
    hover: "orderable-hover",
    dropMarker: "orderable-drop-marker",
    avatar: "orderable-avatar"
};
avatarCreator a function that returns a valid DOM node to be used as the dragging avatar   The item being dragged will be cloned
dropWarningId the ID of an element that should be displayed if users attempt to move an item to a location where movement is not permitted   (none)
instructionMessageId the ID of the element containing any instructional messages   "message-bundle:"

CSS Classes

The Reorderer applies CSS classes to orderable items, and updates them as they are moved. These classes can be used to apply visual cues to the various states of the orderable items. The class names are configurable. The default class names are:

   orderable-default - This class is applied to elements in their default state.
   orderable-selected - This class is applied to the element that has been selected. The selected item can then be moved using keystrokes.
   orderable-hover - This class is applied to orderable elements when the mouse hovers over them.
   orderable-dragging - This class is applied to the orderable element that is currently being moved using the keyboard.
   orderable-mouseDrag - This class is applied to the orderable element that is currently being moved using the mouse.
   orderable-avatar - This class is applied to the avatar, which defaults to the image of the orderable element as it is being dragged about by the mouse.
   orderable-drop-marker - This class is applied to the drop target indicator when the mouse is used to drag an item.


Dependencies

The following files must be included in the mark-up, in the given order: 

js/jquery/jquery-1.2.3.js
js/jquery/jquery.keyboard-a11y.js
js/jquery/jquery.dimensions.js
js/jquery/ui.base.js
js/jquery/ui.draggable.js
js/jquery/ui.droppable.js
js/jquery/jARIA.js
js/fluid/Fluid.js
js/fluid/Reorderer.js

or use the Fluid-all.js file.


Tutorial

You can follow a tutorial describing how to use the Reorderer at Reorderer Integration Tutorial - v0.3.

Site running on a free Atlassian Confluence Open Source Project License granted to The FLUID Project. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5 Build:#805 Apr 26, 2007) - Bug/feature request - Contact Administrators