1: /* Copyright (C) 2004 itgroup MPIWG
2:
3: This program is free software; you can redistribute it and/or
4: modify it under the terms of the GNU General Public License
5: as published by the Free Software Foundation; either version 2
6: of the License, or (at your option) any later version.
7:
8: This program is distributed in the hope that it will be useful,
9: but WITHOUT ANY WARRANTY; without even the implied warranty of
10: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: GNU General Public License for more details.
12:
13: You should have received a copy of the GNU General Public License
14: along with this program; if not, write to the Free Software
15: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
16:
17: Authors: ROC 10.6.2005
18: */
19:
20: var hllibVersion = "1.0.2";
21: var hlAreas = new Object();
22: var hlTrafos = new Object();
23:
24: // Area class
25: function Area(id, target_id, a_x, a_y, a_w, a_h, type, perm) {
26: this.id = id;
27: this.target_id = target_id;
28: this.rect = new Rectangle(a_x, a_y, a_w, a_h);
29: this.type = type;
30: this.permanent = (perm.toLowerCase() == 'true');
31: this.pxarea = 0;
32: return this;
33: }
34:
35: function addArea(id, target_id, a_x, a_y, a_w, a_h, type, perm) {
36: hlAreas[id] = new Area(id, target_id, a_x, a_y, a_w, a_h, type, perm);
37: }
38:
39: function parseTrafo(target) {
40: // returns Transform for given target picsize
41: var picsize = getElementRect(target);
42: var trafo = new Transform();
43: // subtract area offset and size
44: //trafo.concat(getTranslation(new Position(-dlArea.x, -dlArea.y)));
45: //trafo.concat(getScale(new Size(1/dlArea.width, 1/dlArea.height)));
46: // scale to screen size
47: trafo.concat(getScale(picsize));
48: trafo.concat(getTranslation(picsize));
49: return trafo;
50: }
51:
52: function placeAreas() {
53: // positions all area-images
54: var maxsize = 0;
55: for (var a in hlAreas) {
56: var area = hlAreas[a];
57: var trafo = hlTrafos[area.target_id];
58: if (trafo) {
59: var rect = trafo.transform(area.rect);
60: area.pxarea = rect.getArea();
61: maxsize = Math.max(maxsize, area.pxarea);
62: var img = getElement("i."+area.id);
63: if (area.type == "arrow") {
64: var pos = rect.getPosition();
65: var isize = getElementSize(img);
66: pos.x += rect.width * 0.5 - isize.width * 0.5;
67: pos.y += rect.height * 0.5 - isize.height * 0.5;
68: moveElement(img, pos);
69: if (img.layers) {
70: // N4: grow layer for border
71: img.resizeBy(2,2);
72: }
73: } else if (area.type == "text") {
74: var txt = getElement("t."+area.id);
75: if (img.layers) {
76: // for N4 we size a transparent image as the area
77: var li = img.document.images[0];
78: li.width = rect.width;
79: li.height = rect.height;
80: }
81: moveElement(img, rect);
82: moveElement(txt, rect);
83: } else {
84: if (img.layers) {
85: // for N4 we size a transparent image as the area
86: var li = img.document.images[0];
87: li.width = rect.width;
88: li.height = rect.height;
89: }
90: moveElement(img, rect);
91: }
92: highlightMark(area.id, area.permanent);
93: }
94: }
95: // add z-index (largest value for smallest area)
96: for (a in hlAreas) {
97: area = hlAreas[a];
98: var elem = getElement("i."+area.id);
99: if (elem.style) {
100: elem.style.zIndex = getInt(maxsize - area.pxarea);
101: } else if (elem.layers) {
102: elem.zIndex = getInt(maxsize - area.pxarea);
103: }
104: }
105: }
106:
107: function highlightLink(id, highlight) {
108: // hightlights or unhighlights the link of id
109: var link = getElement("a."+id);
110: if (highlight) {
111: // highlight
112: if (link.style) {
113: link.style.backgroundColor = "#f08080";
114: } else if (link.layers) {
115: link.bgColor = "#f08080";
116: }
117: } else {
118: // unhighlight
119: if (link.style) {
120: link.style.backgroundColor = "";
121: } else if (link.layers) {
122: link.bgColor = null;
123: }
124: }
125: }
126:
127: function highlightMark(id, highlight) {
128: // hightlights or unhighlights the area/img of id
129: var area = hlAreas[id];
130: var img = getElement("i."+id);
131: if (highlight) {
132: // highlight
133: if (area.type == "arrow") {
134: if (img.style) {
135: img.style.borderStyle = "solid";
136: } else if (img.layers) {
137: img.bgColor = "#0000ff";
138: }
139: } else if (area.type == "text") {
140: if (img.style) {
141: img.style.background = "url(area_img)";
142: } else if (img.layers) {
143: img.background.src = "area_img";
144: }
145: var txt = getElement("t."+id);
146: if (txt.style) {
147: txt.style.visibility = "visible";
148: }
149: } else if (area.type == "area") {
150: if (img.style) {
151: img.style.background = "url(area_img)";
152: } else if (img.layers) {
153: img.background.src = "area_img";
154: }
155: }
156: } else {
157: // unhighlight
158: if (area.type == "arrow") {
159: if (img.style) {
160: img.style.borderStyle = "none";
161: } else if (img.layers) {
162: img.bgColor = null;
163: }
164: } else if (area.type == "text") {
165: var txt = getElement("t."+id);
166: if (img.style) {
167: img.style.background = "url(trans_img)";
168: } else if (img.layers) {
169: img.background.src = null;
170: }
171: if (txt.style) {
172: txt.style.visibility = "hidden";
173: }
174: } else if (area.type == "area") {
175: if (img.style) {
176: img.style.background = "url(trans_img)";
177: } else if (img.layers) {
178: img.background.src = null;
179: }
180: }
181: }
182: }
183:
184: function highlightPair(id, highlight) {
185: // hightlights or unhighlights the link and image of id
186: //alert("highlightpair: "+id+" "+highlight);
187: var area = hlAreas[id];
188: highlightLink(id, highlight);
189: if (!area.permanent) {
190: highlightMark(id, highlight);
191: }
192: }
193:
194: function init() {
195: map_init();
196: }
197:
198: var elemScaler;
199: var dlTrafo;
200:
201: function map_init() {
202: // initialise baselib
203: base_init();
204: //alert("huhu4!");
205: elemScaler = getElement("overview");
206: dlTrafo = parseTrafo(elemScaler);
207: hlTrafos["overview"] = dlTrafo;
208: placeAreas();
209: return null;
210: }
211:
212: function showcoordsN4() {
213: var s = "";
214: for (var l in document.layers) {
215: if (l == "length") continue;
216: e = document.layers[l];
217: if (e) {
218: s += " [" + e.name + "]: pageX:" + e.pageX + " pageY:" + e.pageY + " width:" + e.clip.width + " height:" + e.clip.height + " visibility:" + e.visibility + " zindex:" + e.zIndex + "<br>\n";
219: } else {
220: s += " {" + l + "}<br>\n";
221: }
222: }
223: return s;
224: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>