Annotation of ECHO_content/js/hl_lib.js, revision 1.4

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);
                     80:        if (browserType.isIEWin) {
1.4     ! casties    81:            // IE/Win needs to set the area once
1.2       casties    82:            highlightPair(area.id, false);
                     83:        }
1.1       casties    84:        }
                     85:    }
                     86:     }
                     87:     // add z-index (largest value for smallest area)
                     88:     for (a in hlAreas) {
                     89:    area = hlAreas[a];
                     90:    var elem = getElement("i."+area.id);
                     91:    if (elem.style) {
1.2       casties    92:        elem.style.zIndex = getInt(maxsize - area.pxarea);
                     93:    } else if (elem.layers) {
                     94:        elem.zIndex = getInt(maxsize - area.pxarea);
1.1       casties    95:    }
                     96:     }
                     97: }
                     98: 
                     99: function highlightPair(id, highlight) {
                    100:     // hightlights or unhighlights the link and image of id
1.2       casties   101:     //alert("highlightpair: "+id+" "+highlight);
1.1       casties   102:     var area = hlAreas[id];
                    103:     var img = getElement("i."+id);
                    104:     var link = getElement("a."+id);
                    105:     if (highlight) {
1.2       casties   106:    if (link.style) {
                    107:        link.style.backgroundColor = "#f08080";
                    108:    } else if (link.layers) {
                    109:        link.bgColor = "#f08080";
                    110:    }
1.1       casties   111:    if (area.type == "arrow") {
1.2       casties   112:        if (img.style) {
                    113:        img.style.borderStyle = "solid";
                    114:        } else if (img.layers) {
                    115:        img.bgColor = "#0000ff";
                    116:        }
1.1       casties   117:    } else if (area.type == "area") {
1.2       casties   118:        if (img.style) {
                    119:        img.style.background = "url(area_img)";
                    120:        } else if (img.layers) {
                    121:        img.background.src = "area_img";
                    122:        }
1.1       casties   123:    }
                    124:     } else {
1.2       casties   125:    if (link.style) {
                    126:        link.style.backgroundColor = "";
                    127:    } else if (link.layers) {
                    128:        link.bgColor = null;
                    129:    }
1.1       casties   130:    if (area.type == "arrow") {
1.2       casties   131:        if (img.style) {
                    132:        img.style.borderStyle = "none";
                    133:        } else if (img.layers) {
                    134:        img.bgColor = null;
                    135:        }
1.1       casties   136:    } else if (area.type == "area") {
1.2       casties   137:        if (img.style) {
                    138:        img.style.background = "url(trans_img)";
                    139:        } else if (img.layers) {
                    140:        img.background.src = null;
                    141:        }
1.1       casties   142:    }
                    143:     }
                    144: }
                    145: 
                    146: function init() {
1.3       casties   147:     map_init();
                    148: }
                    149: 
1.4     ! casties   150: var elemScaler;
        !           151: var dlTrafo;
        !           152: 
1.3       casties   153: function map_init() {
1.4     ! casties   154:     // initialise baselib
        !           155:     base_init();
        !           156:     //alert("huhu4!");
        !           157:     elemScaler = getElement("overview");
        !           158:     dlTrafo = parseTrafo(elemScaler);
        !           159:     hlTrafos["overview"] = dlTrafo;
1.1       casties   160:     placeAreas();
                    161:     return null;
1.2       casties   162: }
                    163: 
                    164: function showcoordsN4() {
                    165:     var s = "";
                    166:     for (var l in document.layers) {
                    167:    if (l == "length") continue;
                    168:    e = document.layers[l];
                    169:    if (e) {
                    170:        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";
                    171:    } else {
                    172:        s += " {" + l + "}<br>\n";
                    173:    }
                    174:     }
                    175:     return s;
1.1       casties   176: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>