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
|
// $Id$
/**
* Clear contents of element 'jsdebug'
*/
function CED(txt)
{
var element = document.getElementById('jsdebug');
if (element)
element.innerHTML = txt ? txt : "";
}
/**
* Add debugging output to element 'jsdebug'
*/
function ED()
{
var element = document.getElementById('jsdebug');
if (element)
{
var text = "";
for (var i = 0; i < arguments.length; i++)
{
var variable = arguments[i];
if (typeof variable == "string")
variable = variable.replace(/&/g, '&').replace(/</g, '<');
text += (typeof variable) + " " + variable;
if (typeof variable == "object")
{
text += ":";
for (field in variable)
{
text += field + "=";
try { text += typeof variable[field] == 'function' ? 'function' : variable[field]; }
catch (e) { text += "*" + e + "*"; }
text += "\n";
}
text += "\n";
}
text += "\n";
}
element.innerHTML += '<pre style="background-color:#FEE; margin:0">' + text + '</pre>';
}
}
/**
* Quote HTML special chars
* @return Text string with & " < > htmlentities-encoded
*/
function Q(value)
{
return value.toString().replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
}
/**
* String class: Replaces variables of the form {var} with values from given array
* @param values Associative array containing values to fill in (optional)
* @return Text string with variables replaced by their values
*/
String.prototype.T = function(values)
{
var result = this;
for (key in values)
result = result.replace(new RegExp("{" + key + "}", "g"), values[key]);
return result;
}
/**
* Insert an event handler on top of chain
* @param p.element Element to handle event for
* @param p.event Name of event:'focus', 'click', ... (without 'on')
* @param p.object Object that contains handler method
* @param p.method Method of p.object to call on p.event
*/
function it_event(p)
{
var oldhandler = p.element["on" + p.event];
p.element["on" + p.event] = function(ev)
{
var pp = arguments.callee.p ? arguments.callee.p : p;
var oo = arguments.callee.oldhandler ? arguments.callee.oldhandler : oldhandler;
var result = pp.object[pp.method](ev ? ev : window.event, pp);
if (result && oo)
result = oo(ev);
return result;
}
p.element["on" + p.event].p = p;
p.element["on" + p.event].oldhandler = oldhandler;
}
/* Get object pixel position. Based on quirksmode.org's code */
function it_get_obj_x(obj)
{
var curleft = 0;
if (obj.offsetParent)
while (obj)
{
curleft += obj.offsetLeft;
obj = obj.offsetParent;
}
else if (obj.x)
curleft += obj.x;
return curleft;
}
function it_get_obj_y(obj)
{
var curtop = 0;
if (obj.offsetParent)
while (obj)
{
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
else if (obj.y)
curtop += obj.y;
return curtop;
}
/* Get an iframe's content document in a compatible way */
function it_get_iframe_document(iframe)
{
return iframe.contentWindow ? iframe.contentWindow.document : iframe.contentDocument;
}
/**
* Clone src value and return dst. If dst is given then src attributes are
* copied into it, otherwise a new object is created. Also works with scalar
* values. Performs a deep copy of objects
* @param src Source object/value to clone
* @param dst Destination object to copy attributes from src to (optional)
* @return dst holding copy of src
*/
function it_clone(src, dst)
{
if (typeof src == "object")
{
if (!dst)
dst = {};
for (var i in src)
dst[i] = it_clone(src[i]);
}
else
dst = src;
return dst;
}
|