Versions Compared

Key

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

...

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

The first step is to include the Fluid component library code in your file. Do this by adding a script tag to the header referencing the Fluid-all.js javascript file:

...


<head>
  <title>Image Collection</title>
  <script type="text/javascript" src="Fluid-all.js"></script>
</head>

Step 2 - Add element IDs

The second step is to add IDs to the elements that the Image Reorderer needs to know about.

First, add an ID to the element that contains all of the image thumbnails. This ID can be anything unique. For this example, we'll use "image-collection":

...


<div id="image-collection">
  ...
</div>

Next, we need to add a unique ID to each of the thumbnail <div> s. This ID must be of a specific form: it must start with the string that was used for the container ID, followed by "lightbox-cell:", a number indicating the index, and finally a ":". This is shown below for our example:

...


<div id="image-collection">
  <div id="image-collectionlightbox-cell:1:"><img src="img1.jpg"/></div>
  <div id="image-collectionlightbox-cell:2:"><img src="img2.jpg"/></div>
  <div id="image-collectionlightbox-cell:3:"><img src="img3.jpg"/></div>
</div>

I know this seems a bit complex, but in the real world, these IDs will be generated by the server, and you won't have to write them by hand.

Step 3 - Add initialization script

The third step is to actually create the Lighbox by calling the initialization script. This initialization function has the form

...


fluid.lightbox.createLightboxFromId (containerId, options);

The Lightbox initialization function allows you to pass in a number of optional parameters to configure some aspects of the Lightbox, including a 'callback' function. The callback communicates changes in the ordering of images back to the server. In its "out-of-the-box" form, the Lightbox includes a default callback function that uses a form with hidden <input> elements in the markup to record the indexes of the elements. For our example, we will disable the default callback by specifying an empty function as one of the optional parameters:

...


<script type="text/javascript">
  fluid.lightbox.createLightboxFromIds ("image-collection", { orderChangedCallback : function(){} });
</script>

Step 4 - Define styles

The final step is to create styles so that 'interesting moments' in the reordering of images are easily apparent to the user.

The Image Reorderer pre-defines a number of class names that will be used for this purpose. It's possible, through the optional configuration, to override these class names, but for this example, we'll just define styles for the default class names.

The first style is the default style to be applied to any image thumbnail. For our example, we'll float the images so that they appear to be in a grid, and give them a background colour:

...



.orderable-default{
    background-color: #eee;
    float: left;
}

The second style is applied to the element that has been selected. A visual indication will inform users that the thumbnail can be moved using keystrokes. For our example, we'll change the background colour:

...


.orderable-selected{
    background-color: #ddd;
    float: left;
}

The Image Reorderer also supports mouse-based drag and drop, and another style is used when the cursor hovers over a thumbnail, to inform users that the thumbnail can be moved using the mouse. For our example, we'll change the background colour again, but we'll use a different colour:

...


.orderable-hover{
    background-color: lightyellow;
    cursor: move;
    float: left;
}

When a thumbnail is in the process of being moved, either by keyboard or by mouse-based drag and drop, a 'dragging' style is applied to the thumbnail to indicate this. We'll change the background colour for this:

...


.orderable-dragging {
    background-color: lightyellow;
    float: left;
}

When the mouse is used to pick up a thumbnail and move it, an 'avatar' is created to represent the thumbnail being dragged. By default, the avatar is a copy of the item. A style is applied that can be used to modify the appearance of the avatar. For our example, we will make it semi-transparent:

...


.orderable-avatar {
    opacity: 0.55;
}

Finally, when the mouse is used to move a thumbnail, a 'drop marker' is displayed in the location where the thumbnail will end up if it is dropped. The last style is used to control what that marker looks like. We'll make it a vertical red bar:

...


.orderable-drop-marker{
    height: 10px !important;
    width: 4px;
    background-color: red;
    float: left;
}

That's it! Your Image Reorderer is now functional, and you can rearrange the images in your collection. Congratulations!If you choose to use CSS classname different than the defaults, you can override the defaults using the options parameter to the reorderImages() function.

Specify your classnames using the {[styles}} option, and the required style names:

Code Block
javascript
javascript

var opts = {
    styles: {
        defaultStyle: "myMovableImage",
        imageTitle: "myImageCaption"
    },
};
return fluid.reorderImages("#reorder-images-form", opts);

There are actually many styles used by the Reorderer, affecting how the thumbnails look when the cursor hovers over them, what the avatar looks like while it's being dragged, what the drop marker looks like, and more. For a complete list of styles, see the full technical documentation: Image Reorderer API.

...