File: combobox.js

package info (click to toggle)
virtuoso-opensource 7.2.12%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 299,780 kB
  • sloc: ansic: 655,047; sql: 508,209; xml: 269,573; java: 84,064; javascript: 79,847; cpp: 37,662; sh: 32,429; cs: 25,702; php: 12,690; yacc: 11,661; lex: 7,933; makefile: 7,309; jsp: 4,523; awk: 1,719; perl: 1,013; ruby: 1,003; python: 326
file content (59 lines) | stat: -rw-r--r-- 1,945 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 *  $Id$
 *
 *  This file is part of the OpenLink Software Ajax Toolkit (OAT) project.
 *
 *  Copyright (C) 2005-2024 OpenLink Software
 *
 *  See LICENSE file for details.
 */
/*
	var cb = new OAT.ComboBox(defaultValue);
	appendChild(cb.div);
	cb.onchange = callback;

	cb.addOption(element,textValue)

	CSS: combo_box, combo_box_value, combo_box_list, combo_image
*/

OAT.ComboBox = function(defaultValue) {
	var self = this;
	this.onchange = function() {};
	this.div = OAT.Dom.create("div",{},"combo_box"); /* THE element */
	this.options = [];
	this.optList = OAT.Dom.create("div",{position:"absolute",left:"0px",top:"0px"},"combo_box_list"); /* list of other options; hidden most of the time */
	this.image = OAT.Dom.create("img",{cursor:"pointer"},"combo_image"); /* dropdown clicker */
	this.image.src = OAT.Preferences.imagePath+"Combobox_select.gif";
	this.selected = OAT.Dom.create("div",{},"combo_box_value");
	this.value = defaultValue;
	this.selected.innerHTML = this.value;

	self.instant = new OAT.Instant(this.optList);
	OAT.Dom.append([this.div,this.selected,this.image],[document.body,self.optList]);

	this.select = function(textValue) {
		self.value = textValue;
		self.selected.innerHTML = textValue;
		self.onchange(textValue);
		self.instant.hide();
	}

	self.instant.options.showCallback = function() { /* open listbox */
		var coords = OAT.Dom.position(self.div); /* calculate the place */
		var dims = OAT.Dom.getWH(self.div); /* calculate the place */
		self.optList.style.left = coords[0]+"px";
		self.optList.style.top = (coords[1]+dims[1])+"px";
	}

	this.addOption = function(element,textValue) {
		var elm = $(element);
		self.options.push([elm,textValue]);
		self.optList.appendChild(elm);
		var clickRef = function() {	self.select(textValue); }
		OAT.Event.attach(elm,"click",clickRef); /* what to do after clicking */
	}

	self.instant.createHandle(this.image);
	self.instant.createHandle(this.selected);
}