/* © Struppi Mail: struebig@gmx.net URL: http://javascript.jstruebig.de/source/popup.html letzte Änderung: 26.07.2005 Beschreibung: ------------- Ein Skript um ein Fenster in der Größe eines Bildes öffnen. Einbinden: ---------- <script src="popup.js"></script> <A HREF="grosses_bild.jpg" target="bild" onclick="return showBild(this, 'name_des_Bildes');" ><IMG SRC="kleines_bild.jpg"></A>*////////////////////////////////////////////////////////////// Globale Definitionenvar popup_bgColor = '#ffffff';var rahmen        = '0px solid black';var abstand_w      = 1;var abstand_h      = 1;var center_popup  = false;var popup_close   = 'click'; // Mögliche Werte: 'blur', 'click', ''///////////////////////////////////////////////////////////// showBild(a, name) - die Hauptfunktion.var default_site = window.opera ? '' : '';function popup(a){    if(!a.target) a.target = "BildFenster";    var default_width   = 600;    var default_height  = 400;    if(popup_close == 'blur' || !showFenster || showFenster.closed ||     typeof showFenster.closed == 'undefined' // Opera 8 Bugfix    )    showFenster = popUpp(default_site, a.target, default_width, default_height);    showFenster.document.open();    showFenster.document.write( getHTML(a.href, a.title || a.alt) );    showFenster.document.close();    showFenster.focus();    var img = new Image;    img.ready = false;    img.onload = function() { fitWin(this, showFenster); //alert('onload' + this.width)    };    img.src = a.href;    if(img.complete) { fitWin(img, showFenster); // alert('complete' + img.width);     }    return false;}///////////////////////////////////////////////////////////// fitWin(Image, window) - wird aus dem Popup aufgerufen.function fitWin(i, win){    if(i.ready) return;    i.ready = i.width > 0;    var w = i.width;    var h = i.height;    var w_s = getWinSize(win);    var r = 2 * parseInt(rahmen);    var scr = { width: screen.width, height: screen.height};    win.resizeBy((w - w_s.width + ( 2 * abstand_w) + r), (h - w_s.height + ( 2 * abstand_h) + r) );    if(center_popup && !window.opera)    {         win.moveTo(( scr.width - w_s.width) / 2, (scr.height - w_s.height) / 2 );    }    win.focus();}/////////////////////////////////////////////////////////////////////// getHTML(bild, titel, farbe)function getHTML(src, title, bgcolor){    if(!title) title = 'kein Titel';    if(!bgcolor) bgcolor = popup_bgColor;    var NL = "\n";    var text = '<!DOCTYPE HTML PUBLIC "-\/\/W3C\/\/DTD HTML 4.01\/\/EN" "http:\/\/www.w3.org\/TR\/html4\/strict.dtd">\n'    + '<HTML>\n<HEAD>' + NL    + '<TITLE>' + title + '<\/TITLE>' + NL    + '<STYLE type="text/css">' + NL    + 'body{margin:0;padding:0;overflow:hidden;' + NL    + 'background-color:' + popup_bgColor + NL    + ';}' + NL    + 'img{padding:0;'    + (rahmen ? 'border:' + rahmen + ';'  : '')    + 'margin-top:' + abstand_h +'px;' + NL    + 'margin-bottom:' + abstand_h +'px;' + NL    + 'margin-left:' + abstand_w +'px;' + NL    + 'margin-right:' + abstand_w +'px;' + NL    + '}\n' + NL    + '<\/STYLE>' + NL    + '<\/HEAD>' + NL    + '<body'    + (popup_close.toLowerCase() == 'blur' ? ' onblur="self.close();"' : '')    + '>'    + '<img src="' + src + '" alt="" title="' + title + '"'    + '>' + NL    + (popup_close.toLowerCase() == 'click' ? '<script> document.images[0].onclick=function(){window.close()};</script>' : '')    + '<\/body><\/html>'    ;    return text;}/////////////////////////////////////////////////////////////////////// Ein popup öffnenfunction popUpp(url, fname, w, h){    var tmp = new Array();    tmp[tmp.length] = 'resizable=yes';    tmp[tmp.length] = 'scrollbars=no';    if(w) tmp[tmp.length] = 'width=' + w;    if(h) tmp[tmp.length] = 'height=' + h;    return window.open(url, fname, tmp.join(','));}////////////////////////////////////////////////////////////// getWinSize(window)function getWinSize(win){    if(!win) win = window;    var s = new Object();    if(typeof win.innerWidth != 'undefined')    {        s.width = win.innerWidth;        s.height = win.innerHeight;    }    else    {         var obj = getBody(win);         s.width = parseInt(obj.clientWidth);         s.height = parseInt(obj.clientHeight);    }    return s;}////////////////////////////////////////////////////////////// Der IE hat 2 verschiedene Objekte für den strict und quirks Mode.function getBody(w){    return (w.document.compatMode && w.document.compatMode == "CSS1Compat") ? w.document.documentElement : w.document.body || null;}var showFenster = null;/////////////////////////////////////////////////////////////////////// ... und am schluss alle Fenster schliessen.window.onunload = function (){    if(showFenster && !showFenster.closed) showFenster.close();}
