/* The ButtonBar code was written by Andrew Houghton; it can be used and * modified freely, but this header message must be included in any source * (in particular you may want to remove all comments other than this one). * Please email me at 'aah@cmu.edu' with comments or suggestions. If you * make use of this code I would appreciate hearing about it. */ /* ButtonBar version 0.9 * * A generic button array holder.. called ButtonBar since it was originally * meant to handle multiple buttons in a row. The button images can be GIFS * or JPEGS, they can animate, etc. By default, the button bar only allows * a single button to be pressed, though you can toggle that and allow * multiple buttons to be selected at a time. * * In your JavaScript code: * 1) create a new object of type ButtonBar * 2) call addButton() for each button you want to add to the ButtonBar * 3) call asTable() to get the buttonset written out as a table * * Notes: * 1) all buttons start in the "unselected", or "up" mode * 2) if there is only one button, and you choose a ButtonBar of type * "SINGLE" (the default), that button can be pressed, but only * once -- you'll never be able to toggle it. */ /* ImageButton * * internal object to ButtonBar; holds a button's specific information * * Notes: * 1) an ImageButton's 'status' property reflects whether that button is * in a selected state: * true == selected * false == unselected */ function ImageButton(selectedName, unselectedName, selected, unselected, sScript, uScript) { this.status = false; this.selectedName = selectedName; this.unselectedName = unselectedName; this.selected = selected; this.unselected = unselected; this.sScript = sScript; this.uScript = uScript; } /* ButtonBar.addButton() * * Call this function to add a button to the ButtonBar. * * REQUIRED Arguments: * unselected: string representing the URL of an image to use when button * is "up" * selected: string representing the URL of an image to use when button * is "down" * * OPTIONAL Arguments: * uScript: string to be eval'd when button moves to "up" state * sScript: string to be eval'd when button moves to "down" state * * Notes: * 1) unselected and selected *must* be passed, though they can both be * the same * 2) uScript and sScript can be ignored, since JavaScript will consider * them to be null, and when they're evaluated nothing will happen.. * this will make for a functional, though useless, button bar. */ function ButtonBar_addButton(unselected, selected, uScript, sScript) { if ((unselected == null) || (selected == null)) { alert("ButtonBar ("+this.name+"): attempt to pass null values to addButton() failed"); return; } var sImage = new Image(); var uImage = new Image(); sImage.src = selected; uImage.src = unselected; var element = this.numButtons; this.buttonArray[element] = new ImageButton(selected, unselected, sImage, uImage, sScript, uScript); this.numButtons++; } /* ButtonBar.select() * * Internal function. Handles toggling a button from unselected to selected state. */ function ButtonBar_selectButton(element) { var tableElement = this.prefix + element; eval("document."+tableElement).src = this.buttonArray[element].selected.src; eval (this.buttonArray[element].sScript); this.buttonArray[element].status = true; } /* ButtonBar.unselect() * * Internal function. Handles toggling a button from selected to unselected state. */ function ButtonBar_unselectButton(element) { var tableElement = this.prefix + element; eval("document."+tableElement).src = this.buttonArray[element].unselected.src; eval (this.buttonArray[element].uScript); this.buttonArray[element].status = false; } /* ButtonBar.onClick() * * Internal function. Handles an onClick() event on a button. */ function ButtonBar_onClick(element) { if (this.type == "MULTI") { if (this.buttonArray[element].status == true) { this.unselectButton(element); } else { this.selectButton(element); } } else { if (this.selected == element) { return; } if (this.selected != null) { this.unselectButton(this.selected); this.selected = null; } this.selectButton(element); this.selected = element; } } /* ButtonBar.asTable() * * Returns: * a string representing the ButtonBar as a table. The table correctly * handles onClick() events and changing the button state, etc. * * REQUIRED Arguments: * None * * OPTIONAL Arguments: * tableOptions: string representing any table-wide options; this string is * dropped verbatim into the