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

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.6     ! casties    72:        } else if (area.type == "text") {
        !            73:        var txt = getElement("t."+area.id);
        !            74:        if (img.layers) {
        !            75:            // for N4 we size a transparent image as the area
        !            76:            var li = img.document.images[0];
        !            77:            li.width = rect.width;
        !            78:            li.height = rect.height;
        !            79:        }
        !            80:        moveElement(img, rect);
        !            81:        moveElement(txt, rect);
1.1       casties    82:        } else {
1.2       casties    83:        if (img.layers) {
1.4       casties    84:            // for N4 we size a transparent image as the area
1.2       casties    85:            var li = img.document.images[0];
                     86:            li.width = rect.width;
                     87:            li.height = rect.height;
                     88:        }
                     89:        moveElement(img, rect);
1.1       casties    90:        }
                     91:    }
                     92:     }
                     93:     // add z-index (largest value for smallest area)
                     94:     for (a in hlAreas) {
                     95:    area = hlAreas[a];
                     96:    var elem = getElement("i."+area.id);
                     97:    if (elem.style) {
1.2       casties    98:        elem.style.zIndex = getInt(maxsize - area.pxarea);
                     99:    } else if (elem.layers) {
                    100:        elem.zIndex = getInt(maxsize - area.pxarea);
1.1       casties   101:    }
                    102:     }
                    103: }
                    104: 
                    105: function highlightPair(id, highlight) {
                    106:     // hightlights or unhighlights the link and image of id
1.2       casties   107:     //alert("highlightpair: "+id+" "+highlight);
1.1       casties   108:     var area = hlAreas[id];
                    109:     var img = getElement("i."+id);
                    110:     var link = getElement("a."+id);
                    111:     if (highlight) {
1.2       casties   112:    if (link.style) {
                    113:        link.style.backgroundColor = "#f08080";
                    114:    } else if (link.layers) {
                    115:        link.bgColor = "#f08080";
                    116:    }
1.1       casties   117:    if (area.type == "arrow") {
1.2       casties   118:        if (img.style) {
                    119:        img.style.borderStyle = "solid";
                    120:        } else if (img.layers) {
                    121:        img.bgColor = "#0000ff";
                    122:        }
1.6     ! casties   123:    } else if (area.type == "text") {
        !           124:        if (img.style) {
        !           125:        img.style.background = "url(area_img)";
        !           126:        } else if (img.layers) {
        !           127:        img.background.src = "area_img";
        !           128:        }
        !           129:        var txt = getElement("t."+id);
        !           130:        if (txt.style) {
        !           131:        txt.style.visibility = "visible";
        !           132:        }
1.1       casties   133:    } else if (area.type == "area") {
1.2       casties   134:        if (img.style) {
                    135:        img.style.background = "url(area_img)";
                    136:        } else if (img.layers) {
                    137:        img.background.src = "area_img";
                    138:        }
1.1       casties   139:    }
                    140:     } else {
1.6     ! casties   141:    // unhighlight
1.2       casties   142:    if (link.style) {
                    143:        link.style.backgroundColor = "";
                    144:    } else if (link.layers) {
                    145:        link.bgColor = null;
                    146:    }
1.1       casties   147:    if (area.type == "arrow") {
1.2       casties   148:        if (img.style) {
                    149:        img.style.borderStyle = "none";
                    150:        } else if (img.layers) {
                    151:        img.bgColor = null;
1.6     ! casties   152:        }
        !           153:    } else if (area.type == "text") {
        !           154:        if (img.style) {
        !           155:        img.style.background = "url(trans_img)";
        !           156:        } else if (img.layers) {
        !           157:        img.background.src = null;
        !           158:        }
        !           159:        var txt = getElement("t."+id);
        !           160:        if (txt.style) {
        !           161:        txt.style.visibility = "hidden";
1.2       casties   162:        }
1.1       casties   163:    } else if (area.type == "area") {
1.2       casties   164:        if (img.style) {
                    165:        img.style.background = "url(trans_img)";
                    166:        } else if (img.layers) {
                    167:        img.background.src = null;
                    168:        }
1.1       casties   169:    }
                    170:     }
                    171: }
                    172: 
                    173: function init() {
1.3       casties   174:     map_init();
                    175: }
                    176: 
1.4       casties   177: var elemScaler;
                    178: var dlTrafo;
                    179: 
1.3       casties   180: function map_init() {
1.4       casties   181:     // initialise baselib
                    182:     base_init();
                    183:     //alert("huhu4!");
                    184:     elemScaler = getElement("overview");
                    185:     dlTrafo = parseTrafo(elemScaler);
                    186:     hlTrafos["overview"] = dlTrafo;
1.1       casties   187:     placeAreas();
                    188:     return null;
1.2       casties   189: }
                    190: 
                    191: function showcoordsN4() {
                    192:     var s = "";
                    193:     for (var l in document.layers) {
                    194:    if (l == "length") continue;
                    195:    e = document.layers[l];
                    196:    if (e) {
                    197:        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";
                    198:    } else {
                    199:        s += " {" + l + "}<br>\n";
                    200:    }
                    201:     }
                    202:     return s;
1.1       casties   203: }

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