File: toolbar.js

package info (click to toggle)
virtuoso-opensource 6.1.4%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 245,116 kB
  • sloc: ansic: 639,631; sql: 439,225; xml: 287,085; java: 61,048; sh: 38,723; cpp: 36,889; cs: 25,240; php: 12,562; yacc: 9,036; lex: 7,149; makefile: 6,093; jsp: 4,447; awk: 1,643; perl: 1,017; ruby: 1,003; python: 329
file content (153 lines) | stat: -rw-r--r-- 3,243 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
 *  $Id: toolbar.js,v 1.8.2.3 2010/04/06 16:46:12 source Exp $
 *
 *  This file is part of the OpenLink Software Ajax Toolkit (OAT) project.
 *
 *  Copyright (C) 2005-2010 OpenLink Software
 *
 *  See LICENSE file for details.
 */
/*
	t = new OAT.Toolbar(div);

	var i = t.addIcon(twoStates,imagePath,tooltip,callback)  ---  callback(state)
	var s = t.addSeparator()
	alert(i.state) --- 0/1

	t.removeIcon(i)
	t.removeSeparator(s)


	CSS: .toolbar .toolbar_icon .toolbar_icon_down .toolbar_separator
*/


OAT.ToolbarButtonState = {
    UP: 0,
    DOWN: 1,
    DISABLED: 2
};

OAT.ToolbarButtonType = {
    TOGGLE: 0,
    BUTTON: 1
};

OAT.ToolbarButton = function (container, opts) {
    var self = this;

    this._iconUrls = [];
    this._tooltips = [];
    this._classes = ["toolbar_btn_up", "toolbar_btn_down", "toolbar_btn_disabled"];
    this._container = {};
    this._state = OAT.ToolbarButtonState.UP;
    this._btnType = OAT.ToolbarButtonType.BUTTON;
    this._size = [16,16];
    this._callbacks = {};

    this.setIcon = function (state, icon) {
	self.iconUrls[state]=icon;
    };

    this.getIcon = function (state) {
	return self.icons[state];
    };

    this.toggle = function () {
    };

    this.enable = function () {

    };

    this.setContainer = function (ctr) {
	this._container = ctr;
    };

    this.setState = function (state) {
	self._state = state;
	self._img.href = self.icons(state);
    };

    this.clickHandler = function () {
	if (self._btnType == TOGGLE) {
	    self.toggle ();
	}
	OAT.Msg.send (self, "TOOLBAR_BUTTON_CLICK", self);
    };

    this.overHandler = function () {
	OAT.Msg.send (self, "TOOLBAR_BUTTON_CLICK", self);
    };

    self.setContainer (container);
};

OAT.Toolbar = function(div,optObj) {
    var self = this;

    this.options = {
	labels:false
    }

    for (var p in optObj) { self.options[p] = optObj[p]; }

    this.div = $(div);
    OAT.Dom.addClass(this.div,"toolbar");
    this.icons = [];
    this.separators = [];

    this.addIcon = function(twoStates,imagePath,tooltip,callback) {
	var div = OAT.Dom.create("div",{},"toolbar_icon");
	div.title = tooltip;
	div.state = 0;

	var img = OAT.Dom.create("img");
	img.src = imagePath;

	div.toggleState = function(newState) {
	    div.state = newState;
	    if (div.state) {
		OAT.Dom.addClass(div,"toolbar_icon_down");
	    } else {
		OAT.Dom.removeClass(div,"toolbar_icon_down");
	    }
	    callback(div.state);
	}

	div.toggle = function(event) {
	    var nstate = div.state+1;
	    if (nstate > 1) { nstate = 0; }
	    if (!twoStates) { nstate = 0; }
	    div.toggleState(nstate);
	}

		OAT.Event.attach(div,"click",div.toggle);
	OAT.Dom.append([div,img],[self.div,div]);

	if (self.options.labels) {
	    div.appendChild(OAT.Dom.text(tooltip));
	}

	self.icons.push(div);
	return div;
    }

    this.addSeparator = function() {
	var div = OAT.Dom.create("div",{className: "toolbar_separator"});
	self.div.appendChild(div);
	self.separators.push(div);
	return div;
    }

    this.removeIcon = function(div) {
	var index = self.icons.indexOf(div);
	self.icons.splice(index,1);
    }

    this.removeSeparator = function(div) {
	var index = self.separators.indexOf(div);
	this.separators.splice(index,1);
    }

}