/* # dynamic_layer.js Version 4.1 # Copyright (c) 2000-2002 Luca Borrione write@tiscali-no.spam.it # Created 06 July 2000 Last Modified 06 November 2002 # _________________ # COPYRIGHT NOTICE: # Copyright (c) 2000-2002 Luca Borrione All Rights Reserved. # Permission granted to use and modify free of charge this script so long as this # copyright notice above is maintained, modifications are documented, # and credit is given for any use of the script. # By using this code you agree to indemnify Luca Borrione from any liability that # might arise from its use. # Selling the code contained in this script without prior written consent is # expressly forbidden. # Obtain permission before redistributing this script over the Internet or # in any other medium. # In all cases copyright and header must remain intact. # # ____________ # SCRIPT CODE: */ // REQUIRED: browser_check.js var d = document; debugging = (document.domain.match (/192.168.2.199/)); var curleft = 0; var curtop = 0; /* Per il moveTo con elemento di riferimento, se l'elemento di riferimento NON è un layer, NN4 dà solo la posizione relativa (al layer che lo contiene) e non assoluta. Queste variabili servono per correggere questo problema, calcolando la posizione assoluta del layer contenitore durante il loop in nn4_scanLayers. Devono pertanto essere azzerate ad ogni init_layer e questo viene appunto fatto in get_object. Le utilizzo anche per similitudine come variabile di ritorno in get_absolute per i browsers non NN4, per i quali invece il valore di partenza è sempre nullo. E questo viene appunto garantito essendo invocato get_object prima di get_absolute. EG TEST NB: 1 il name serve per NN4 l'id per IE5Mac. 2 non si può usare this.name (provare this.id) nell'istruzione xchè smette di funzionare in NN4. Passare la stringa. */ function layer (Id) { if (!d.layer || !d.layer[Id]) init_layer (Id); if (d.layer[Id]) return d.layer[Id]; else return null; } function init_layer (Id) { if (!d.layer) d.layer = []; d.layer[Id] = new Dynamic_Layer (Id); if (!d.layer[Id].object) { /* if (debugging) alert ("DYNAMIC LAYER Error:\n"+ "Impossibile risalire al layer "+ Id +"."); */ delete d.layer[Id]; } } function Dynamic_Layer (Id) { this.id = Id; this.object = get_object (Id); if (!this.object) return; this.css = (is.nn4) ? this.object : this.object.style; this.x = get_absolute_x (this.object); this.y = get_absolute_y (this.object); this.left = get_relative_x (this.object); this.top = get_relative_y (this.object); this.width = get_width (this.object); this.height = get_height (this.object); this.zIndex = this.css.zIndex; this.show = layer_show; this.hide = layer_hide; this.resizeTo = layer_resizeTo; this.moveBy = layer_moveBy; this.moveTo = layer_moveTo; this.write = layer_write; this.zOrder = layer_zOrder; this.align = layer_align; this.reset = layer_reset; this.getCSS = layer_getCSS; this.unset = layer_unset; this.none = layer_none; /* __________ FUNCTIONS: */ function layer_unset() { delete d.layer[this.id]; } function layer_show() { /* if( is.ie || is.nn>=5 ){ this.object.style.visibility="visible"; } else if( is.nn ){ this.object.visibility="show"; } */ if( is.ie || is.nn>=5 ){ this.object.style.visibility="inherit"; } else if( is.nn ){ this.object.visibility="inherit"; } } function layer_none() { if( is.ie || is.nn>=5 ){ this.object.style.visibility="none"; } else if( is.nn ){ this.object.visibility="none"; } } function layer_hide() { if( is.ie || is.nn>=5 ){ this.object.style.visibility="hidden"; } else if( is.nn ){ this.object.visibility="hide"; } } function layer_moveTo (x, y, Id_ref) { if (Id_ref) { var ref = get_object (Id_ref); if (!ref) { if (debugging) alert ("DYNAMIC LAYER Error:\n"+ "Impossibile risalire all'elemento di riferimento "+ Id_ref +"."); return; } x += get_absolute_x (ref); y += get_absolute_y (ref); } relative_x = x-this.x; relative_y = y-this.y; // alert (relative_x +"||"+ relative_y); this.moveBy (relative_x, relative_y); } function layer_moveBy( x,y ) { this.x += x; this.y += y; this.left += x; this.top += y; if (is.nn) { this.css.left = this.left; this.css.top = this.top; } else // DOM2 { this.css.pixelLeft = this.left; this.css.pixelTop = this.top; } } function layer_resizeTo( Width, Height ) { // alert( this.width +"||"+ this.height ); // return; if( Width ){ this.width = Width; } if( Height ){ this.height = Height; } if( is.ie ) { with( this ) { //Show.properties( css ); css.pixelWidth = Width; css.pixelHeight = Height; css.clip = "rect(0,"+ Width +","+ Height +",0)"; //Show.properties( css ); } } else if( is.nn ) { if( is.nn>=5 ) { with( this ) { css.width = Width; css.height = Height; css.clip = "rect(0,"+ Width +","+ Height +",0)"; } } else { with( this ) { css.clip.width = width; css.clip.height = height; } } } } function layer_zOrder (index,ref) { /* ##/ # # Uso: # 1: layer[id1].zOrder(1) # Imposta ad 1 lo z-index del layer id1. # # 2: layer[id1].zOrder("+/-1) # Aumenta o diminuisce di 1 lo z-index del layer id1. # # 3: layer[id1].zOrder("+/-1", id2) # Imposta lo z-index del layer id1 a + o - 1 rispetto allo z-index del layer id2. ##\ */ /* if (ref) { index = eval(d.layer[ref].zIndex+index); } var initial = index.toString().charAt(0); if (initial=="+" || initial=="-") { index = eval(this.zIndex+index); } */ this.zIndex = index; this.css.zIndex = index; } function layer_write( What ) { if( is.ie || is.nn>=5 ){ this.object.innerHTML = What; } else if( is.nn && is.nn<5 ) { this.css.document.write( What ); this.css.document.close(); // Show.properties( this.css ); } } function layer_reset() { this.x = get_absolute_x( this.object ); this.y = get_absolute_y( this.object ); this.left = get_relative_x( this.object ); this.top = get_relative_y( this.object ); this.width = get_width( this.object ); this.height = get_height( this.object ); } function layer_align( Align ) { var x; if (Align.toLowerCase() == "center") { var innerWidth = (is.ie) ? document.body.clientWidth : window.innerWidth; x = Math.round( (innerWidth - this.width)/2 ); this.moveTo( x, 0 ); } } function layer_getCSS( Prop ) { if( is.nn4 ) return( this.object[Prop] ); else if( is.nn ) return( document.defaultView.getComputedStyle(document.getElementById(this.id),null).getPropertyValue(Prop) ); else if( is.ie4 ) { if( this.object.style[Prop] ){ return( this.object.style[Prop] ); } var styles = this.object.document.styleSheets; var style; var ret = new Array(); var cssText = ""; reg = new Array(); reg.id = (this.object.id) ? new RegExp( this.object.id+"{" ) : null; reg.className = (this.object.className) ? new RegExp( this.object.className+"{" ) : null; reg.tagName = (this.object.tagName) ? new RegExp( this.object.tagName+"{" ) : null; for( var s=0; s0 ) r = nn4_scanLayers (Id, layer); curleft += layer.pageX; curtop += layer.pageY; if (r) return r; } return r; } /* ___________________ GETTING PROPERTIES: */ function get_absolute_x (obj) { if (document.getElementById || document.all) { while (obj.offsetParent) { curleft += obj.offsetLeft; obj = obj.offsetParent; } } else if (is.nn4) { if (typeof obj.pageX == 'undefined') curleft += obj.x; else curleft = obj.pageX; } return curleft; } function get_absolute_y (obj) { if (document.getElementById || document.all) { while (obj.offsetParent) { curtop += obj.offsetTop; obj = obj.offsetParent; } } else if (is.nn4) { if (typeof obj.pageY == 'undefined') curtop += obj.y; else curtop = obj.pageY; } return curtop; } function get_relative_x( Object ) { if (is.nn4){ return( Object.left ); } if (is.ie4 && Object.style.clipLeft){ return( Object.style.clipLeft ); } else // DOM return( Object.offsetLeft ); } function get_relative_y( Object ) { if( is.nn && is.nn<5 ){ return( Object.top ); } if( is.ie4 && Object.style.clipLeft ){ return( Object.style.clipTop ); } else{ return( Object.offsetTop ); } return( null ); } function get_width( obj ) { if (is.ie4 && is.win) { if (obj.style.pixelWidth){ return(obj.style.pixelWidth); } else{ return(obj.offsetWidth); } } else if (is.ie4){ return(obj.style.pixelWidth); } else if (is.ie >= 5 && is.win) { var clipRight = obj.currentStyle.clipRight; clipRight = (clipRight!="auto") ? clipRight.substring(0,clipRight.lastIndexOf("px")) : null; var offsetWidth = obj.offsetWidth; if (clipRight!=null){ return( Math.min( Math.round(clipRight), offsetWidth) ); } else{ return(offsetWidth); } } else if (is.nn4){ return( obj.clip.width ); } else // DOM return( obj.offsetWidth ); } function get_height( obj ) { if (is.ie4 && is.win) { if (obj.style.pixelHeight){ return(obj.style.pixelHeight); } else{ return(obj.offsetHeight); } } else if (is.ie4){ return(obj.style.pixelHeight); } else if (is.ie >= 5 && is.win) { var clipBottom = obj.currentStyle.clipBottom; clipBottom = (clipBottom!="auto") ? clipBottom.substring(0,clipBottom.lastIndexOf("px")) : null; var offsetHeight = obj.offsetHeight; if (clipBottom!=null){ return( Math.min( Math.round(clipBottom), offsetHeight) ); } else{ return(offsetHeight); } } else if (is.nn4){ return( obj.clip.height ); } else // DOM return( obj.offsetHeight ); }