1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* The contents of this file are subject to the Mozilla Public
4
* License Version 1.1 (the "License"); you may not use this file
5
* except in compliance with the License. You may obtain a copy of
6
* the License at http://www.mozilla.org/MPL/
8
* Software distributed under the License is distributed on an "AS
9
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10
* implied. See the License for the specific language governing
11
* rights and limitations under the License.
13
* The Original Code is JSIRC Library
15
* The Initial Developer of the Original Code is New Dimensions Consulting,
16
* Inc. Portions created by New Dimensions Consulting, Inc. are
17
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
21
* Robert Ginda, rginda@ndcico.com, original author
27
this.listContainer = document.createElement ("box");
28
this.listContainer.setAttribute ("class", "list");
29
this.listContainer.setAttribute ("align", "vertical");
33
CListBox.prototype.clear =
34
function lbox_clear (e)
36
var obj = this.listContainer.firstChild;
40
this.listContainer.removeChild (obj);
41
obj = obj.nextSibling;
46
CListBox.prototype.clickHandler =
47
function lbox_chandler (e)
49
var lm = this.listManager;
53
if (lm && typeof lm.onClick == "function")
54
lm.onClick ({realTarget: this, event: e});
58
CListBox.prototype.onClick =
59
function lbox_chandler (e)
62
/* Check for the button number first */
63
/* FIXME: are there constants for this stuff? */
64
if (e.event.button == 2)
70
* If the ctrlKey is _not_ set, unselect all currently
76
this.enumerateElements(this._unselectCallback, e.realTarget);
79
/* Check to see whether the item is currently selected */
80
var isSelected = e.realTarget.getAttribute("selected");
82
/* toggle the value */
83
if ("true" == isSelected)
84
e.realTarget.setAttribute("selected", "false");
86
e.realTarget.setAttribute("selected", "true");
90
CListBox.prototype._unselectCallback =
91
function (element, ndx, realTarget)
93
if (element != realTarget)
94
element.setAttribute("selected", "false");
97
CListBox.prototype.add =
98
function lbox_add (stuff, tag)
100
/* NOTE: JG using a div here makes the item span the full
101
length and looks better when selected */
103
var option = document.createElement ("box");
104
option.setAttribute ("class", "list-option");
105
option.setAttribute ("align", "horizontal");
106
option.appendChild (stuff);
107
option.onclick = this.clickHandler;
108
option.listManager = this;
110
this.listContainer.appendChild (option);
115
CListBox.prototype.prepend =
116
function lbox_prepend (stuff, oldstuff, tag)
119
if (!this.listContainer.firstChild)
120
return this.add (stuff, tag);
122
var nextOption = this._findOption (oldstuff);
126
var option = document.createElement ("box");
127
option.setAttribute ("align", "horizontal");
129
option.appendChild (stuff);
130
option.onclick = this.clickHandler;
131
option.listManager = this;
133
this.listContainer.insertBefore (option, nextOption);
137
CListBox.prototype.insert =
138
function lbox_Insert (stuff, tag)
140
this.prepend (stuff, this.listContainer.firstChild, tag);
143
CListBox.prototype.remove =
144
function lbox_remove (stuff)
146
var option = this._findOption (stuff);
149
this.listContainer.removeChild (option);
154
CListBox.prototype._findOption =
155
function lbox_remove (stuff)
157
var option = this.listContainer.firstChild;
161
if (option.firstChild == stuff)
163
option = option.nextSibling;
169
CListBox.prototype.enumerateElements =
170
/* NOTE: JG: added data param so arbitrary data can be passed. */
171
function lbox_enum (callback, data)
174
var current = this.listContainer.firstChild;
178
callback (current, i++, data);
179
current = current.nextSibling;
185
* Using enumerateElements, this is used just to fill an array
186
* with selected nick names.
187
* @returns an array of selected nicknames
189
CListBox.prototype.getSelectedItems =
190
function lbox_getselecteditems ()
194
this.enumerateElements(this.selectedItemCallback, ary);
200
* used to build the array of values returned by getSelectedItems.
202
CListBox.prototype.selectedItemCallback =
203
function (item, idx, data)