Annotation of ECHO_content/js/hl_lib.js, revision 1.5
1.1 casties 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:
1.4 casties 17: Authors: ROC 23.11.2004
1.1 casties 18: */
19:
1.4 casties 20: var hllibVersion = "1.0.1";
1.1 casties 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) {
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.pxarea = 0;
31: return this;
32: }
33:
34: function addArea(id, target_id, a_x, a_y, a_w, a_h, type) {
35: hlAreas[id] = new Area(id, target_id, a_x, a_y, a_w, a_h, type);
36: }
37:
1.4 casties 38: function parseTrafo(target) {
1.1 casties 39: // returns Transform for given target picsize
1.4 casties 40: var picsize = getElementRect(target);
1.1 casties 41: var trafo = new Transform();
42: // subtract area offset and size
43: //trafo.concat(getTranslation(new Position(-dlArea.x, -dlArea.y)));
44: //trafo.concat(getScale(new Size(1/dlArea.width, 1/dlArea.height)));
45: // scale to screen size
46: trafo.concat(getScale(picsize));
47: trafo.concat(getTranslation(picsize));
48: return trafo;
49: }
50:
51: function placeAreas() {
52: // positions all area-images
53: var maxsize = 0;
54: for (var a in hlAreas) {
55: var area = hlAreas[a];
56: var trafo = hlTrafos[area.target_id];
57: if (trafo) {
58: var rect = trafo.transform(area.rect);
59: area.pxarea = rect.getArea();
60: maxsize = Math.max(maxsize, area.pxarea);
1.2 casties 61: var img = getElement("i."+area.id);
62: if (area.type == "arrow") {
63: var pos = rect.getPosition();
64: var isize = getElementSize(img);
65: pos.x += rect.width * 0.5 - isize.width * 0.5;
66: pos.y += rect.height * 0.5 - isize.height * 0.5;
67: moveElement(img, pos);
68: if (img.layers) {
1.4 casties 69: // N4: grow layer for border
1.2 casties 70: img.resizeBy(2,2);
71: }
1.1 casties 72: } else {
1.2 casties 73: if (img.layers) {
1.4 casties 74: // for N4 we size a transparent image as the area
1.2 casties 75: var li = img.document.images[0];
76: li.width = rect.width;
77: li.height = rect.height;
78: }
79: moveElement(img, rect);
1.1 casties 80: }
81: }
82: }
83: // add z-index (largest value for smallest area)
84: for (a in hlAreas) {
85: area = hlAreas[a];
86: var elem = getElement("i."+area.id);
87: if (elem.style) {
1.2 casties 88: elem.style.zIndex = getInt(maxsize - area.pxarea);
89: } else if (elem.layers) {
90: elem.zIndex = getInt(maxsize - area.pxarea);
1.1 casties 91: }
92: }
93: }
94:
95: function highlightPair(id, highlight) {
96: // hightlights or unhighlights the link and image of id
1.2 casties 97: //alert("highlightpair: "+id+" "+highlight);
1.1 casties 98: var area = hlAreas[id];
99: var img = getElement("i."+id);
100: var link = getElement("a."+id);
101: if (highlight) {
1.2 casties 102: if (link.style) {
103: link.style.backgroundColor = "#f08080";
104: } else if (link.layers) {
105: link.bgColor = "#f08080";
106: }
1.1 casties 107: if (area.type == "arrow") {
1.2 casties 108: if (img.style) {
109: img.style.borderStyle = "solid";
110: } else if (img.layers) {
111: img.bgColor = "#0000ff";
112: }
1.1 casties 113: } else if (area.type == "area") {
1.2 casties 114: if (img.style) {
115: img.style.background = "url(area_img)";
116: } else if (img.layers) {
117: img.background.src = "area_img";
118: }
1.1 casties 119: }
120: } else {
1.2 casties 121: if (link.style) {
122: link.style.backgroundColor = "";
123: } else if (link.layers) {
124: link.bgColor = null;
125: }
1.1 casties 126: if (area.type == "arrow") {
1.2 casties 127: if (img.style) {
128: img.style.borderStyle = "none";
129: } else if (img.layers) {
130: img.bgColor = null;
131: }
1.1 casties 132: } else if (area.type == "area") {
1.2 casties 133: if (img.style) {
134: img.style.background = "url(trans_img)";
135: } else if (img.layers) {
136: img.background.src = null;
137: }
1.1 casties 138: }
139: }
140: }
141:
142: function init() {
1.3 casties 143: map_init();
144: }
145:
1.4 casties 146: var elemScaler;
147: var dlTrafo;
148:
1.3 casties 149: function map_init() {
1.4 casties 150: // initialise baselib
151: base_init();
152: //alert("huhu4!");
153: elemScaler = getElement("overview");
154: dlTrafo = parseTrafo(elemScaler);
155: hlTrafos["overview"] = dlTrafo;
1.1 casties 156: placeAreas();
157: return null;
1.2 casties 158: }
159:
160: function showcoordsN4() {
161: var s = "";
162: for (var l in document.layers) {
163: if (l == "length") continue;
164: e = document.layers[l];
165: if (e) {
166: 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";
167: } else {
168: s += " {" + l + "}<br>\n";
169: }
170: }
171: return s;
1.1 casties 172: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>