Subversion Repositories svnkaklik

Rev

Go to most recent revision | Details | Last modification | View Log

Rev Author Line No. Line
6 kaklik 1
// {{{ global constants
2
 
3
/**
4
 * Global constants (DO NOT EDIT)
5
 */
6
 
7
// browsers
8
var domLib_userAgent = navigator.userAgent.toLowerCase();
9
var domLib_isOpera = domLib_userAgent.indexOf('opera 7') != -1 ? 1 : 0;
10
var domLib_isKonq = domLib_userAgent.indexOf('konq') != -1 ? 1 : 0;
11
var domLib_isIE = !domLib_isKonq && !domLib_isOpera && (domLib_userAgent.indexOf('msie 5') != -1 || domLib_userAgent.indexOf('msie 6') != -1);
12
var domLib_isIE5up = domLib_isIE;
13
var domLib_isIE50 = domLib_isIE && domLib_userAgent.indexOf('msie 5.0') != -1;
14
var domLib_isIE55 = domLib_isIE && domLib_userAgent.indexOf('msie 5.5') != -1;
15
var domLib_isIE5 = domLib_isIE50 || domLib_isIE55;
16
var domLib_isIE55up = domLib_isIE5up && !domLib_isIE50;
17
var domLib_isIE6up = domLib_isIE55up && !domLib_isIE55;
18
var domLib_isGecko = domLib_userAgent.indexOf('gecko') != -1 ? 1 : 0;
19
 
20
// abilities
21
var domLib_useLibrary = domLib_isOpera || domLib_isKonq || domLib_isIE5up || domLib_isGecko ? 1 : 0;
22
var domLib_canTimeout = !(domLib_isKonq || domLib_isIE50);
23
var domLib_canFade = domLib_isGecko || domLib_isIE55up;
24
 
25
// event variables
26
var domLib_eventTarget = domLib_isIE ? 'srcElement' : 'currentTarget';
27
var domLib_eventButton = domLib_isIE ? 'button' : 'which';
28
var domLib_eventTo = domLib_isIE ? 'toElement' : 'relatedTarget';
29
var domLib_stylePointer = domLib_isIE ? 'hand' : 'pointer';
30
// :FIX: bug in Opera that it can't set maxWidth to 'none'
31
var domLib_styleNoMaxWidth = domLib_isOpera ? '10000px' : 'none';
32
var domLib_hidePosition = '-1000px';
33
var domLib_scrollbarWidth = 14;
34
var domLib_autoId = 1;
35
var domLib_zIndex = 100;
36
 
37
// detection
38
var domLib_selectElements;
39
 
40
var domLib_timeoutStateId = 0;
41
var domLib_timeoutStates = new Hash();
42
 
43
// }}}
44
// {{{ Object.prototype.clone
45
 
46
Object.prototype.clone = function()
47
{
48
	var copy = {};
49
	for (var i in this)
50
	{
51
		var value = this[i];
52
		try
53
		{
54
			if (value != null && typeof(value) == 'object' && value != window && !value.nodeType)
55
			{
56
				// for IE5 which doesn't inherit prototype
57
				value.clone = Object.clone;
58
				copy[i] = value.clone();
59
			}
60
			else
61
			{
62
				copy[i] = value;
63
			}
64
		}
65
		catch(e)
66
		{
67
			copy[i] = value;
68
		}
69
	}
70
 
71
	return copy;
72
}
73
 
74
// }}}
75
// {{{ class Hash()
76
 
77
function Hash()
78
{
79
	this.length = 0;
80
	this.elementData = [];
81
	for (var i = 0; i < arguments.length; i += 2)
82
	{
83
		if (typeof(arguments[i + 1]) != 'undefined')
84
		{
85
			this.elementData[arguments[i]] = arguments[i + 1];
86
			this.length++;
87
		}
88
	}
89
 
90
	this.get = function(in_key)
91
	{
92
		return this.elementData[in_key];
93
	}
94
 
95
	this.set = function(in_key, in_value)
96
	{
97
		if (typeof(in_value) != 'undefined')
98
		{
99
			if (typeof(this.elementData[in_key]) == 'undefined')
100
			{
101
				this.length++;
102
			}
103
 
104
			return this.elementData[in_key] = in_value;
105
		}
106
 
107
		return false;
108
	}
109
 
110
	this.remove = function(in_key)
111
	{
112
		var tmp_value;
113
		if (typeof(this.elementData[in_key]) != 'undefined')
114
		{
115
			this.length--;
116
			tmp_value = this.elementData[in_key];
117
			delete this.elementData[in_key];
118
		}
119
 
120
		return tmp_value;
121
	}
122
 
123
	this.size = function()
124
	{
125
		return this.length;
126
	}
127
 
128
	this.has = function(in_key)
129
	{
130
		return typeof(this.elementData[in_key]) != 'undefined';
131
	}
132
}
133
 
134
// }}}
135
// {{{ domLib_isDescendantOf()
136
 
137
function domLib_isDescendantOf(in_object, in_ancestor)
138
{
139
	if (in_object == in_ancestor)
140
	{
141
		return true;
142
	}
143
 
144
	while (in_object != document.documentElement)
145
	{
146
		try
147
		{
148
			if ((tmp_object = in_object.offsetParent) && tmp_object == in_ancestor)
149
			{
150
				return true;
151
			}
152
			else if ((tmp_object = in_object.parentNode) == in_ancestor)
153
			{
154
				return true;
155
			}
156
			else
157
			{
158
				in_object = tmp_object;
159
			}
160
		}
161
		// in case we get some wierd error, just assume we haven't gone out yet
162
		catch(e)
163
		{
164
			return true;
165
		}
166
	}
167
 
168
	return false;
169
}
170
 
171
// }}}
172
// {{{ domLib_detectCollisions()
173
 
174
// :WARNING: hideList is being used as an object property and is not a string
175
function domLib_detectCollisions(in_object, in_recover)
176
{
177
	// no need to do anything for opera
178
	if (domLib_isOpera)
179
	{
180
		return;
181
	}
182
 
183
	if (typeof(domLib_selectElements) == 'undefined')
184
	{
185
		domLib_selectElements = document.getElementsByTagName('select');
186
	}
187
 
188
	// if we don't have a tip, then unhide selects
189
	if (in_recover)
190
	{
191
		for (var cnt = 0; cnt < domLib_selectElements.length; cnt++)
192
		{
193
			var thisSelect = domLib_selectElements[cnt];
194
 
195
			if (!thisSelect.hideList)
196
			{
197
				thisSelect.hideList = new Hash();
198
			}
199
 
200
			// if this is mozilla and it is a regular select or it is multiple and the
201
			// size is not set, then we don't need to unhide
202
			if (domLib_isGecko && (!thisSelect.multiple || thisSelect.size < 0))
203
			{
204
				continue;
205
			}
206
 
207
			thisSelect.hideList.remove(in_object.id);
208
			if (!thisSelect.hideList.length)
209
			{
210
				domLib_selectElements[cnt].style.visibility = 'visible';
211
			}
212
		}
213
 
214
		return;
215
	}
216
 
217
	// okay, we have a tip, so hunt and destroy
218
	var objectOffsets = domLib_getOffsets(in_object);
219
 
220
	for (var cnt = 0; cnt < domLib_selectElements.length; cnt++)
221
	{
222
		var thisSelect = domLib_selectElements[cnt];
223
 
224
		// if this is mozilla and not a multiple-select or the multiple select size
225
		// is not defined, then continue since mozilla does not have an issue
226
		if (domLib_isGecko && (!thisSelect.multiple || thisSelect.size < 0))
227
		{
228
			continue;
229
		}
230
 
231
		// if the select is in the tip, then skip it
232
		// :WARNING: is this too costly?
233
		if (domLib_isDescendantOf(thisSelect, in_object))
234
		{
235
			continue;
236
		}
237
 
238
		if (!thisSelect.hideList)
239
		{
240
			thisSelect.hideList = new Hash();
241
		}
242
 
243
		var selectOffsets = domLib_getOffsets(thisSelect); 
244
		// for mozilla we only have to worry about the scrollbar itself
245
		if (domLib_isGecko)
246
		{
247
			selectOffsets.set('left', selectOffsets.get('left') + thisSelect.offsetWidth - domLib_scrollbarWidth);
248
			selectOffsets.set('leftCenter', selectOffsets.get('left') + domLib_scrollbarWidth/2);
249
			selectOffsets.set('radius', Math.max(thisSelect.offsetHeight, domLib_scrollbarWidth/2));
250
		}
251
 
252
		var center2centerDistance = Math.sqrt(Math.pow(selectOffsets.get('leftCenter') - objectOffsets.get('leftCenter'), 2) + Math.pow(selectOffsets.get('topCenter') - objectOffsets.get('topCenter'), 2));
253
		var radiusSum = selectOffsets.get('radius') + objectOffsets.get('radius');
254
		// the encompassing circles are overlapping, get in for a closer look
255
		if (center2centerDistance < radiusSum)
256
		{
257
			// tip is left of select
258
			if ((objectOffsets.get('leftCenter') <= selectOffsets.get('leftCenter') && objectOffsets.get('right') < selectOffsets.get('left')) ||
259
			// tip is right of select
260
				(objectOffsets.get('leftCenter') > selectOffsets.get('leftCenter') && objectOffsets.get('left') > selectOffsets.get('right')) ||
261
			// tip is above select
262
				(objectOffsets.get('topCenter') <= selectOffsets.get('topCenter') && objectOffsets.get('bottom') < selectOffsets.get('top')) ||
263
			// tip is below select
264
				(objectOffsets.get('topCenter') > selectOffsets.get('topCenter') && objectOffsets.get('top') > selectOffsets.get('bottom')))
265
			{
266
				thisSelect.hideList.remove(in_object.id);
267
				if (!thisSelect.hideList.length)
268
				{
269
					thisSelect.style.visibility = 'visible';
270
				}
271
			}
272
			else
273
			{
274
				thisSelect.hideList.set(in_object.id, true);
275
				thisSelect.style.visibility = 'hidden';
276
			}
277
		}
278
	}
279
}
280
 
281
// }}}
282
// {{{ domLib_getOffsets()
283
 
284
function domLib_getOffsets(in_object)
285
{
286
	var originalObject = in_object;
287
	var originalWidth = in_object.offsetWidth;
288
	var originalHeight = in_object.offsetHeight;
289
	var offsetLeft = 0;
290
	var offsetTop = 0;
291
 
292
	while (in_object)
293
	{
294
		offsetLeft += in_object.offsetLeft;
295
		offsetTop += in_object.offsetTop;
296
		in_object = in_object.offsetParent;
297
	}
298
 
299
	return new Hash(
300
		'left',			offsetLeft,
301
		'top',			offsetTop,
302
		'right',		offsetLeft + originalWidth,
303
		'bottom',		offsetTop + originalHeight,
304
		'leftCenter',	offsetLeft + originalWidth/2,
305
		'topCenter',	offsetTop + originalHeight/2,
306
		'radius',		Math.max(originalWidth, originalHeight) 
307
	);
308
}
309
 
310
// }}}
311
// {{{ domLib_setTimeout()
312
 
313
function domLib_setTimeout(in_function, in_timeout, in_args)
314
{
315
	if (typeof(in_args) == 'undefined')
316
	{
317
		in_args = [];
318
	}
319
 
320
	if (in_timeout == 0)
321
	{
322
		in_function(in_args);
323
		return 0;
324
	}
325
 
326
	// must make a copy of the arguments so that we release the reference
327
	if (typeof(in_args.clone) != 'function')
328
	{
329
		in_args.clone = Object.clone;
330
	}
331
 
332
	var args = in_args.clone();
333
 
334
	if (domLib_canTimeout)
335
	{
336
		return setTimeout(function() { in_function(args); }, in_timeout);
337
	}
338
	else
339
	{
340
		var id = domLib_timeoutStateId++;
341
		var data = new Hash();
342
		data.set('function', in_function);
343
		data.set('args', args);
344
		domLib_timeoutStates.set(id, data);
345
 
346
		data.set('timeoutId', setTimeout('domLib_timeoutStates.get(' + id + ').get(\'function\')(domLib_timeoutStates.get(' + id + ').get(\'args\')); domLib_timeoutStates.remove(' + id + ');', in_timeout));
347
		return id;
348
	}
349
}
350
 
351
// }}}
352
// {{{ domLib_clearTimeout()
353
 
354
function domLib_clearTimeout(in_id)
355
{
356
	if (domLib_canTimeout)
357
	{
358
		clearTimeout(in_id);
359
	}
360
	else
361
	{
362
		if (domLib_timeoutStates.has(in_id))
363
		{
364
			clearTimeout(domLib_timeoutStates.get(in_id).get('timeoutId'))
365
			domLib_timeoutStates.remove(in_id);
366
		}
367
	}
368
}
369
 
370
// }}}
371
// {{{ domLib_getEventPosition()
372
 
373
function domLib_getEventPosition(in_eventObj)
374
{
375
	var eventPosition = new Hash();
376
	if (domLib_isKonq)
377
	{
378
		eventPosition.set('x', in_eventObj.x);
379
		eventPosition.set('y', in_eventObj.y);
380
	}
381
	else if (domLib_isIE)
382
	{
383
		if (document.documentElement.clientHeight)
384
		{
385
			eventPosition.set('x', in_eventObj.clientX + document.documentElement.scrollLeft);
386
			eventPosition.set('y', in_eventObj.clientY + document.documentElement.scrollTop);
387
		}
388
		// :WARNING: consider case where document.body doesn't yet exist for IE
389
		else
390
		{
391
			eventPosition.set('x', in_eventObj.clientX + document.body.scrollLeft);
392
			eventPosition.set('y', in_eventObj.clientY + document.body.scrollTop);
393
		}
394
	}
395
	else
396
	{
397
		eventPosition.set('x', in_eventObj.pageX);
398
		eventPosition.set('y', in_eventObj.pageY);
399
	}
400
 
401
	return eventPosition;
402
}
403
 
404
// }}}
405
// {{{ makeTrue()
406
 
407
function makeTrue()
408
{
409
	return true;
410
}
411
 
412
// }}}
413
// {{{ makeFalse()
414
 
415
function makeFalse()
416
{
417
	return false;
418
}
419
 
420
// }}}