2 Copyright 2007 University of Cambridge
3 Copyright 2007 University of Toronto
5 Licensed under the Educational Community License (ECL), Version 2.0 or the New
6 BSD license. You may not use this file except in compliance with one these
9 You may obtain a copy of the ECL 2.0 License and BSD License at
10 https://source.fluidproject.org/svn/LICENSE.txt
13 var fluid = fluid || {};
36 fluid.mixin = function (target, args) {
37 for (var arg in args) {
38 if (args.hasOwnProperty (arg)) {
39 target[arg] = args[arg];
44 fluid.deriveLightboxCellBase = function (namebase, index) {
45 return namebase + "lightbox-cell:" + index + ":";
48 // Client-level initialisation for the lightbox, allowing parameterisation for
49 // different templates.
50 fluid.initLightbox = function (namebase, messageNamebase) {
51 var reorderform = fluid.Utilities.findForm (document.getElementById (namebase));
53 // Remove the anchors from the taborder - camel case 'tabIndex' needed for IE7 support
54 jQuery ("a", reorderform).attr ("tabIndex", "-1");
56 // An <input> tag nested within our root namebase tag, which has an id which
57 // begins with the namebase:lightbox-cell:: prefix, and ends with "reorder-index" trail.
58 // Very hard to imagine any perversity which may lead to this picking any stray stuff :P
60 // An approach based on the "sourceIndex" DOM property would be much more efficient,
61 // but this is only supported in IE.
62 var orderChangedCallback = function() {
63 var inputs = fluid.Utilities.seekNodesById(
66 "^" + fluid.deriveLightboxCellBase (namebase, "[^:]*") + "reorder-index$");
68 for (var i = 0; i < inputs.length; ++ i) {
72 if (reorderform && reorderform.action) {
73 jQuery.post(reorderform.action,
74 jQuery(reorderform).serialize(),
75 function (type, data, evt) { /* No-op response */ });
79 // This orderable finder knows that the lightbox thumbnails are 'div' elements
80 var lightboxCellNamePattern = "^" + fluid.deriveLightboxCellBase (namebase, "[0-9]+") +"$";
81 var lightboxOrderableFinder = function (containerEl) {
82 return fluid.Utilities.seekNodesById (containerEl, "div", lightboxCellNamePattern);
85 var lightboxContainer = jQuery ("[id=" + namebase + "]");
86 var layoutHandlerParams = {
87 orderableFinder: lightboxOrderableFinder,
88 container: lightboxContainer,
89 orderChangedCallback: orderChangedCallback
91 var lightbox = new fluid.Reorderer (lightboxContainer, {
92 messageNamebase : messageNamebase,
93 layoutHandler: new fluid.GridLayoutHandler (layoutHandlerParams),
94 orderableFinder: lightboxOrderableFinder
98 fluid.Lightbox.addThumbnailActivateHandler (lightbox);
104 * Utilities object for providing various general convenience functions
106 fluid.Utilities = {};
108 // Custom query method seeks all tags descended from a given root with a
109 // particular tag name, whose id matches a regex. The Dojo query parser
110 // is broken http://trac.dojotoolkit.org/ticket/3520#preview, this is all
111 // it might do anyway, and this will be plenty fast.
112 fluid.Utilities.seekNodesById = function (rootnode, tagname, idmatch) {
113 var inputs = rootnode.getElementsByTagName (tagname);
115 for (var i = 0; i < inputs.length; ++ i) {
116 var input = inputs[i];
118 if (id && id.match (idmatch)) {
125 fluid.Utilities.escapeSelector = function(id) {
126 return id.replace (/\:/g,"\\:");
129 fluid.Utilities.findForm = function (element) {
131 if (element.nodeName.toLowerCase() === "form") {
134 element = element.parentNode;