File: slidebar.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 (178 lines) | stat: -rw-r--r-- 4,618 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 *  $Id: slidebar.js,v 1.4.2.5 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.
 */

/*
	var slb = new OAT.Slidebar (div,
								{ 	autoClose,		true,
									autoCloseDelay,	1000,
									XXX: has no effect yet: position,		"right",
									width,			300,
									handleWidth		10,
									handleOpenImg,	"handle_open.png",
									handleCloseImg,	"handle_close.png",
									imgPrefix,		"i/",
									animSpeed, 		10});
	slb.open ();
	slb.close ();

	CSS: slidebar, slb_handle, slb_handle_img, slb_content

	requires OAT.AnimationSize

	Messages: OAT.MSG.SLB_OPENED, OAT.MSG.SLB_CLOSED

	The widget creates a new container div.slb_content and moves the original DIVs contents to it.

	TODO add left, top, bottom slide bars

*/

OAT.Slidebar = function (div, optionsObj) {

	this.div = $(div);
	var self = this;

	this.sb_to = 0;			/* Timeout to close when autoClose = true */

	this.options = {
		autoClose: 		true,
		autoCloseDelay:	2000, // milliseconds
//		position:		"right",
		width:			300,
		handleWidth:	10,
		handleOpenImg:	"handle_open.png",
		handleCloseImg:	"handle_close.png",
		imgPrefix:		"i/",
		animSpeed:		10
	}
//	called onmouseover

	this.activate = function () {
		clearTimeout (self.sb_to);
	}

// 	called onmouseout

	this.deactivate = function () {
		clearTimeout (self.sb_to);
		self.sb_to = setTimeout (self.close, self.options.autoCloseDelay);
	}

	this.close = function () {
		clearTimeout (self.sb_to);
		OAT.Event.detach (self.handle_div, "click", self.close);
		OAT.Style.set (self.content_div, {overflow : "hidden"});
		self.a_close.start ();
	}

	this.open = function () {
		clearTimeout (self.sb_to);
		OAT.Event.detach (self.handle_div, "click", self.open);
		self.a_open.start ();
	}

	this.opened = function (source, message, event) {

		if (self.options.autoClose) {
			OAT.Event.attach (self.content_div, "mouseover", self.activate);
			OAT.Event.attach (self.div, "mouseout", self.deactivate);
		}

		OAT.Event.attach (self.handle_div, "click", self.close);
		OAT.Style.set (self.content_div, {overflow : "auto"});
		self.handle_close();
		OAT.MSG.send (self, "SLB_OPENED", self);
	}

	this.closed = function (source, message, event) {

// console.log ("sb_closed handler called.");

		if (self.options.autoClose) {
			OAT.Event.detach (self.content_div, "mouseover", self.activate);
			OAT.Event.detach (self.div, "mouseout", self.deactivate);
		}

		OAT.Event.attach (self.handle_div, "click", self.open);
		self.handle_open();
		OAT.MSG.send(self, "SLB_CLOSED", self);
	}

	this.center_handle_img = function () {
		OAT.Dom.center (self.handle_img, false, true);
	}

	this.handle_open = function () {
		self.handle_img.src = self.options.imgPrefix + self.options.handleOpenImg;
	}

	this.handle_close = function () {
		self.handle_img.src = self.options.imgPrefix + self.options.handleCloseImg;
	}

// Initialization

	for (var p in optionsObj) {
	    this.options[p] = optionsObj[p];
	}

	OAT.Dom.addClass (this.div, "slidebar");

// Create container

	this.content_div = document.createElement ("div");
	this.content_div.className = "slb_content";

// Copy original contents to new inner container

	var l = this.div.childNodes.length;

    for (i = 0; i < l; i++) {
    	this.content_div.appendChild (this.div.firstChild);
    }

	this.handle_div  = document.createElement ("div");
	this.handle_div.className = "slb_handle";

	this.handle_img  = document.createElement ("img");
	this.handle_img.className = "slb_handle_img";
	this.handle_img.setAttribute ("alt", "Handle image");

//	move orig. div contents to the container


	this.div.appendChild (this.content_div);
	this.div.appendChild (this.handle_div);
	this.handle_div.appendChild (this.handle_img);

	this.a_open = 	new OAT.AnimationSize (this.div,
										   {width:self.options.width,
										   	speed:self.options.animSpeed,
										   	delay:7});

	this.a_close = 	new OAT.AnimationSize (this.div,
										   {width:self.options.handleWidth,
										   	speed:self.options.animSpeed,
										   	delay:7});

	this.handle_img.src = this.options.imgPrefix+this.options.handleOpenImg;

	OAT.Event.attach (this.handle_div, "click", this.open);

	OAT.MSG.attach (this.a_open.animation, "ANIMATION_STOP", this.opened);
	OAT.MSG.attach (this.a_close.animation, "ANIMATION_STOP", this.closed);

	this.center_handle_img ();

	OAT.Event.attach (window, "resize", this.center_handle_img);
	OAT.Style.set (this.content_div, {overflow : "hidden"});


}