1 |
/* cbe_util.js $Revision: 0.14 $ |
2 |
* CBE v4.19, Cross-Browser DHTML API from Cross-Browser.com |
3 |
* Copyright (c) 2002 Michael Foster (mike@cross-browser.com) |
4 |
* Distributed under the terms of the GNU LGPL from gnu.org |
5 |
*/ |
6 |
// visit function returns: 0 == stop, 1 == continue, 2 == skip subtree |
7 |
function cbeTraverseTree(order, startNode, visitFunction, data) { |
8 |
cbeTraversePreOrder(startNode, 0, 0, visitFunction, data); |
9 |
} |
10 |
function cbeTraversePreOrder(node, level, branch, vFn, data) { |
11 |
var ret = vFn(node,level,branch,data); |
12 |
if (!ret) return 0; |
13 |
if (ret == 1 && node.firstChild) { |
14 |
var child = node.firstChild; |
15 |
while (child) { |
16 |
if (!level) ++branch; |
17 |
if (!cbeTraversePreOrder(child,level+1,branch,vFn,data)) return 1; |
18 |
child = child.nextSibling; |
19 |
} |
20 |
} |
21 |
return 1; |
22 |
} |
23 |
var cbeImageCount=0; |
24 |
var cbeImageObj = new Array(); |
25 |
var cbeImageName = new Array(); |
26 |
function cbeNewImage(imgName, imgUrl, imgWidth, imgHeight) { |
27 |
var imgObj; |
28 |
if (arguments.length == 4) imgObj = new Image(imgWidth,imgHeight); |
29 |
else imgObj = new Image(); |
30 |
imgObj.src = imgUrl; |
31 |
imgObj.id = imgObj.name = imgName; |
32 |
cbeImageObj[cbeImageCount] = imgObj; |
33 |
cbeImageName[cbeImageCount++] = imgName; |
34 |
return imgObj; |
35 |
} |
36 |
function cbeSetImage(tagImg, preloadedImg) { |
37 |
var t, p; |
38 |
if (typeof(tagImg)=='string') t = cbeGetImageByName(tagImg); |
39 |
else t = tagImg; |
40 |
if (typeof(preloadedImg)=='string') p = cbeGetImageByName(preloadedImg); |
41 |
else p = preloadedImg; |
42 |
t.src = p.src; |
43 |
} |
44 |
function cbeGetImageByName(imgName) { |
45 |
var i, j; |
46 |
if (document.images[imgName]) return document.images[imgName]; |
47 |
if (is.nav4) { |
48 |
for (i = 0; i < cbeAll.length; i++) { |
49 |
if (cbeAll[i].ele.document) { |
50 |
for (j = 0; j < cbeAll[i].ele.document.images.length; j++) { |
51 |
if (imgName == cbeAll[i].ele.document.images[j].name) return cbeAll[i].ele.document.images[j]; |
52 |
} |
53 |
} |
54 |
} |
55 |
} |
56 |
for (i = 0; i < cbeImageName.length; i++) { |
57 |
if (cbeImageName[i] == imgName) return cbeImageObj[i]; |
58 |
} |
59 |
return null; |
60 |
} |
61 |
function cbeGetFormByName(frmName) { |
62 |
var i, j; |
63 |
if (document.forms[frmName]) return document.forms[frmName]; |
64 |
if (is.nav4) { |
65 |
for (i = 0; i < cbeAll.length; i++) { |
66 |
if (cbeAll[i].ele.document) { |
67 |
for (j = 0; j < cbeAll[i].ele.document.forms.length; j++) { |
68 |
if (frmName == cbeAll[i].ele.document.forms[j].name) return cbeAll[i].ele.document.forms[j]; |
69 |
} |
70 |
} |
71 |
} |
72 |
} |
73 |
return null; |
74 |
} |
75 |
// cookie implementations based on code from Netscape Javascript Guide |
76 |
function cbeSetCookie(name, value, expire, path) { |
77 |
document.cookie = name + "=" + escape(value) + ((!expire) ? "" : ("; expires=" + expire.toGMTString())) + "; path=/"; |
78 |
} |
79 |
function cbeGetCookie(name) { |
80 |
var value=null, search=name+"="; |
81 |
if (document.cookie.length > 0) { |
82 |
var offset = document.cookie.indexOf(search); |
83 |
if (offset != -1) { |
84 |
offset += search.length; |
85 |
var end = document.cookie.indexOf(";", offset); |
86 |
if (end == -1) end = document.cookie.length; |
87 |
value = unescape(document.cookie.substring(offset, end)); |
88 |
} |
89 |
} |
90 |
return value; |
91 |
} |
92 |
function cbeGetURLArguments() { |
93 |
var idx = location.href.indexOf('?'); |
94 |
var params = new Array(); |
95 |
if (idx != -1) { |
96 |
var pairs = location.href.substring(idx+1, location.href.length).split('&'); |
97 |
for (var i=0; i<pairs.length; i++) { |
98 |
nameVal = pairs[i].split('='); |
99 |
params[i] = nameVal[1]; |
100 |
params[nameVal[0]] = nameVal[1]; |
101 |
} |
102 |
} |
103 |
return params; |
104 |
} |
105 |
function cbePad(str, finalLen, padChar, left) { |
106 |
if (left) { for (var i=str.length; i<finalLen; ++i) str = padChar + str; } |
107 |
else { for (var i=str.length; i<finalLen; ++i) str += padChar; } |
108 |
return str; |
109 |
} |
110 |
function cbeHexString(n, digits, prefix) { |
111 |
var p = '', n = Math.ceil(n); |
112 |
if (prefix) p = prefix; |
113 |
n = n.toString(16); |
114 |
for (var i=0; i < digits - n.length; ++i) { |
115 |
p += '0'; |
116 |
} |
117 |
return p + n; |
118 |
} |
119 |
function cbeRadians(deg) { return deg * (Math.PI / 180); } |
120 |
function cbeDegrees(rad) { return rad * (180 / Math.PI); } |
121 |
function cbeAddDragResizeListener(cbe) { |
122 |
cbe.addEventListener('dragStart', cbeDragResizeStartListener); |
123 |
cbe.addEventListener('drag', cbeDragResizeListener); |
124 |
} |
125 |
function cbeRemoveDragResizeListener(cbe) { |
126 |
cbe.removeEventListener('dragStart', cbeDragResizeStartListener); |
127 |
cbe.removeEventListener('drag', cbeDragResizeListener); |
128 |
} |
129 |
function cbeDragResizeStartListener(e) { |
130 |
if (e.offsetX > (e.cbeCurrentTarget.width() - 20) && e.offsetY > (e.cbeCurrentTarget.height() - 20)) { |
131 |
e.cbeCurrentTarget.isResizing = true; |
132 |
} |
133 |
else e.cbeCurrentTarget.isResizing = false; |
134 |
} |
135 |
function cbeDragResizeListener(e) { |
136 |
if (e.cbeCurrentTarget.isResizing) e.cbeCurrentTarget.resizeBy(e.dx, e.dy); |
137 |
else e.cbeCurrentTarget.moveBy(e.dx, e.dy); |
138 |
} |
139 |
var cbeUtilJsLoaded = true; |
140 |
// End cbe_util.js |