aCajasScroll = new Array(); bSelectDesplegado = null; nYScrollWeb = 0; nRatonPulsado = 0; bSobreCajas = false; function cajaScroll() { var _bSobreListado = false; var _intervaloScroll = null; var _nYListado = 0; var _nAcel = 0; var _bSobreLiebre = false; var _nHBarra = 0; var _nXCSC = 0; var _nWCSC = 0; var _nHCSC = 0; var _nHCSCActual = 0; var _nXScroll = 0; var _nHBarra = 0; var _nXLiebre = 0; var _sDivConjunto = ""; var _nX = 0; var _nY = 0; var _nAncho = 0; var _nAlto = 0; var _nSize = 0; var _nWScroll = 0; var _nVelScroll = 0; var _nInterlineado = 0; this.crearScroll = crearScroll; this.iniciarScroll = iniciarScroll; this.reIniciarScroll = reIniciarScroll; this.moverListado = moverListado; this.sobreListado = sobreListado; this.fueraListado = fueraListado; this.pulsandoFlechas = pulsandoFlechas; this.moviendoListado = moviendoListado; this.sueltaFlecha = sueltaFlecha; this.wheel = wheel; this.handle = handle; this.cambiarContenido = cambiarContenido; this.redimensionarCajaScroll = redimensionarCajaScroll; this.pulsaFlechaArr = pulsaFlechaArr; this.pulsaFlechaAbj = pulsaFlechaAbj; this.pulsaFlecha = pulsaFlecha; this.pulsaBarra = pulsaBarra; this.pulsaLiebre= pulsaLiebre; this.onMouseMoveMenuScroll = onMouseMoveMenuScroll; this.situarTextoSegunBarra = situarTextoSegunBarra; this.situarLiebreSegunTexto = situarLiebreSegunTexto; this.getObj = getObj; var o = this; function crearScroll( sDivConjunto, nX, nY, nAncho, nAlto, nSize, nWScroll, nVel, nInterlineado, nXCSC, nWCSC ) { _sDivConjunto = sDivConjunto; _nX = nX; _nY = nY; _nAncho = nAncho; _nAlto = nAlto; _nSize = nSize; _nWScroll = nWScroll; _nVelScroll = -nVel; _nInterlineado = nInterlineado; document.getElementById( sDivConjunto ).onmouseover = this.sobreListado; document.getElementById( sDivConjunto ).onmouseout = this.fueraListado; if( _nWScroll != 0 ) { if( sNavegador != "firefox" ) document.getElementById( sDivConjunto ).onmousewheel = this.wheel; //if IE (and Opera depending on user setting) else window.addEventListener('DOMMouseScroll', this.wheel, false); //WC3 browsers } document.getElementById( sDivConjunto+"-barra" ).onmousedown = this.pulsaBarra; document.getElementById( sDivConjunto+"-barra" ).onmouseup = this.sueltaFlecha; document.getElementById( sDivConjunto+"-liebre" ).onmousedown = this.pulsaLiebre; document.getElementById( sDivConjunto+"-liebre" ).onmouseup = this.sueltaFlecha; document.getElementById( sDivConjunto+"-liebre" ).ondragstart = 'return false'; document.getElementById( sDivConjunto ).onmouseup = this.sueltaFlecha; document.getElementById( "contenedor" ).onmouseup = this.sueltaFlecha; _nXCSC = nXCSC; _nWCSC = nWCSC; _nHCSC = document.getElementById( _sDivConjunto+"-CSC" ).scrollHeight; _nXScroll = document.getElementById( _sDivConjunto+"-FLECHASSCROLL" ).offsetLeft; _nHBarra = document.getElementById( _sDivConjunto+"-barra" ).scrollHeight; _nXLiebre = document.getElementById( _sDivConjunto+"-liebre" ).offsetLeft; } function getObj() { return _sDivConjunto; } function iniciarScroll( bRedimensionar ) { if( _sDivConjunto != "" && _sDivConjunto != null ) { document.getElementById( _sDivConjunto+"-CSC" ).style.height = document.getElementById( _sDivConjunto+"-CSC" ).scrollHeight+"px"; _nHCSCActual = document.getElementById( _sDivConjunto+"-CSC" ).scrollHeight; _nVelScroll *= -1; //alert( "Inicio: "+_sDivConjunto+": "+_nAncho+","+_nAlto+"//"+ _nWCSC+","+_nHCSC+"//"+document.getElementById( _sDivConjunto+"-CSC" ).scrollHeight ); if( bRedimensionar != null ) redimensionarCajaScroll(); else reIniciarScroll(); } } function cambiarContenido( sNuevoContenido ) { document.getElementById( _sDivConjunto+"-CSC" ).innerHTML = sNuevoContenido; reIniciarScroll(); } function redimensionarCajaScroll( bNuevoContenido ) { if( _nVelScroll >= 0 ) { document.getElementById( _sDivConjunto ).style.left = _nX*nCal+"px"; document.getElementById( _sDivConjunto ).style.top = _nY*nCal+"px"; document.getElementById( _sDivConjunto ).style.width = _nAncho*nCal+"px"; document.getElementById( _sDivConjunto ).style.height = _nAlto*nCal+"px"; if( bNuevoContenido != null ) _nHCSCActual = document.getElementById( _sDivConjunto+"-CSC" ).scrollHeight; else _nHCSCActual = _nHCSC*nCal; //alert( "Redim: "+_sDivConjunto+": "+ _nHCSCActual+","+_nAncho+","+_nAlto+","+document.getElementById( _sDivConjunto+"-CSC" ).scrollHeight ); document.getElementById( _sDivConjunto+"-CSC" ).style.left = _nXCSC*nCal+"px"; document.getElementById( _sDivConjunto+"-CSC" ).style.top = document.getElementById( _sDivConjunto+"-CSC" ).offsetTop*nCal+"px"; document.getElementById( _sDivConjunto+"-CSC" ).style.width = _nWCSC*nCal+"px"; document.getElementById( _sDivConjunto+"-CSC" ).style.fontSize = _nSize*nCal+"px"; document.getElementById( _sDivConjunto+"-CSC" ).style.lineHeight = _nInterlineado*nCal+"px"; document.getElementById( _sDivConjunto+"-CSC" ).style.height = _nHCSCActual+"px"; document.getElementById( _sDivConjunto+"-FLECHASSCROLL" ).style.left = _nXScroll*nCal+"px"; document.getElementById( _sDivConjunto+"-FLECHASSCROLL" ).style.width = _nWScroll*nCal+"px"; document.getElementById( _sDivConjunto+"-FLECHASSCROLL" ).style.height = _nAlto*nCal+"px"; document.getElementById( _sDivConjunto+"-barra" ).style.width = _nWScroll*nCal+"px"; document.getElementById( _sDivConjunto+"-barra" ).style.height = _nHBarra*nCal+"px"; document.getElementById( _sDivConjunto+"-liebre" ).style.left = _nXLiebre*nCal+"px" reIniciarScroll(); } } function reIniciarScroll() { if( _nHCSCActual > Math.ceil(_nAlto*nCal) ) document.getElementById( _sDivConjunto+"-FLECHASSCROLL" ).style.display = "block"; else document.getElementById( _sDivConjunto+"-FLECHASSCROLL" ).style.display = "none"; _nYListado = 0; document.getElementById( _sDivConjunto+"-CSC" ).style.top = _nYListado +"px"; } function sobreListado() { if( document.getElementById( _sDivConjunto+"-CSC" ).style.visibility != "hidden" ) { _bSobreListado = true; bSobreCajas = true; } } function fueraListado() { _bSobreListado = false; bSobreCajas = false; } function pulsaBarra() { if( !_bSobreLiebre ) { var nY = nRatonY - getOrigenPadre( document.getElementById( _sDivConjunto+"-FLECHASSCROLL" ) )[1] - document.getElementById( _sDivConjunto+"-barra" ).offsetTop; situarTextoSegunBarra( nY ); } } function pulsaLiebre() { nRatonPulsado = 1; _bSobreLiebre = true; } function pulsaFlechaArr() { pulsaFlecha(1) } function pulsaFlechaAbj() { pulsaFlecha(-1) } function pulsaFlecha( nDirec ) { if( nRatonPulsado == 0 && _intervaloScroll == null ) { nRatonPulsado = nDirec; pulsandoFlechas(); } else sueltaFlecha( true ); } function pulsandoFlechas() { _bSobreListado = true; window.clearInterval( _intervaloScroll ); _intervaloScroll = window.setInterval( moviendoListado, 10 ); } function sueltaFlecha( bForzar ) { if( bForzar == null && sNavegador == "ipad" ) return; nRatonPulsado = 0; _bSobreListado = false; _bSobreLiebre = false; _nAcel = 0; window.clearInterval( _intervaloScroll ); _intervaloScroll = null; } function moviendoListado() { //if( nRatonPulsado < 0 && _nAcel >= -50 ) _nAcel -= 1; //else if( _nAcel <= 345 ) _nAcel += 1; _nYListado += _nVelScroll + _nAcel; } function moverListado() { if( _nYListado > 0 ) _nYListado = 0; else if( _nYListado + _nHCSCActual < _nAlto*nCal ) { _nYListado = _nAlto*nCal - _nHCSCActual; } document.getElementById( _sDivConjunto+"-CSC" ).style.top = _nYListado +"px"; situarLiebreSegunTexto(); } function onMouseMoveMenuScroll(e) { posRaton( e ); if( _bSobreLiebre ) { var nY = nRatonY - getOrigenPadre( document.getElementById( _sDivConjunto+"-FLECHASSCROLL" ) )[1] - document.getElementById( _sDivConjunto+"-barra" ).offsetTop; //document.getElementById( 'aux' ).innerHTML = nRatonX+"x"+nRatonY+"///"+nY+","+getOrigenPadre( document.getElementById( _sDivConjunto+"-FLECHASSCROLL" ) )[1]; situarTextoSegunBarra( nY ); } } function situarTextoSegunBarra( nY ) { var nPorcen = nY*100 / (document.getElementById( _sDivConjunto+"-barra" ).scrollHeight - document.getElementById( _sDivConjunto+"-liebre" ).scrollHeight); if( nPorcen >= 100 ) nPorcen = 100; var nH = _nHCSCActual - _nAlto*nCal; _nYListado = -nPorcen * nH / 100; moverListado(); //alert( nPorcen+","+nY); } function situarLiebreSegunTexto() { var nH = _nHCSCActual - _nAlto*nCal; var nPorcen = Math.abs(_nYListado*100 / nH ); //Posicion del texto var nY = nPorcen * (document.getElementById( _sDivConjunto+"-barra" ).scrollHeight - document.getElementById( _sDivConjunto+"-liebre" ).scrollHeight) / 100; if( nY > document.getElementById( _sDivConjunto+"-barra" ).scrollHeight - document.getElementById( _sDivConjunto+"-liebre" ).scrollHeight ) { nY = document.getElementById( _sDivConjunto+"-barra" ).scrollHeight - document.getElementById( _sDivConjunto+"-liebre" ).scrollHeight; } else if( nY < 0 ){ nY = 0; alert(0); } document.getElementById( _sDivConjunto+"-liebre" ).style.top = nY+"px"; } function wheel(event) { var delta = 0; /* For IE. */ if (!event) { event = window.event; } if (event.wheelDelta) { /* IE/Opera. */ delta = event.wheelDelta/120; /** In Opera 9, delta differs in sign as compared to IE. */ if (window.opera) delta = -delta; } else if (event.detail) { /** Mozilla case. In Mozilla, sign of delta is different than in IE. Also, delta is multiple of 3.*/ delta = -event.detail/3; } /** If delta is nonzero, handle it. Basically, delta is now positive if wheel was scrolled up, and negative, if wheel was scrolled down.*/ if (delta) handle(delta); /** Prevent default actions caused by mouse wheel. That might be ugly, but we handle scrolls somehow anyway, so don't bother here..*/ if(event.preventDefault) event.preventDefault(); event.returnValue = false; } function handle(delta) { if( document.getElementById( _sDivConjunto+"-FLECHASSCROLL" ).style.display == "block" && _bSobreListado ) { _nYListado += delta*20; moverListado(); } } } ////////////////////////////////////////////////////////////////////////////////////////////////////// // FUNCIONES ////////////////////////////////////////////////////////////////////////////////////////////////////// function wheelWeb(event) { if( !bSelectDesplegado || bSobreCajas ) { var delta = -event.detail/3; nYScrollWeb -= delta*50; scrollTo( 0, nYScrollWeb ); if (event.preventDefault) event.preventDefault(); event.returnValue = false; } } function nuevaCajaScroll( sDiv, nX, nY, nAncho, nAlto, sFamilia, nSize, sColor, nWScroll, sArchivoFlechas, sArchivoBarra, nVel, nInterlineado, sPreRuta ) { //GUARDAMOS var nNum = aCajasScroll.length; aCajasScroll.push( new cajaScroll() ); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // CAJA SCROLL ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if( nInterlineado == null || nInterlineado == "" ) nInterlineado = nSize; document.getElementById( sDiv ).style.left = nX+"px"; document.getElementById( sDiv ).style.top = nY+"px"; document.getElementById( sDiv ).style.width = nAncho+"px"; document.getElementById( sDiv ).style.height = nAlto+"px"; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // SCROLL ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if( document.getElementById( "menu" ) != null ) sPreRuta = "../"; else if( sPreRuta == null ) sPreRuta = ""; document.getElementById( sDiv ).innerHTML += "
"; //Origen scroll, Origen contenido, Anchura contenido var nMargenSep = 1.5; var anCoords = new Array( nAncho-nWScroll-5, 0, nAncho-nWScroll-5 ); //Scroll en lado derecho if( nWScroll < 0 ) nCoords = new Array( 0, Math.abs(nWScroll)*nMargenSep, nAncho-Math.abs(nWScroll)*nMargenSep ); //Scroll en lado izquierdo nWScroll = Math.abs( nWScroll ); document.getElementById( sDiv+"-FLECHASSCROLL" ).style.left = anCoords[0]+"px"; document.getElementById( sDiv+"-FLECHASSCROLL" ).style.top = 0+"px"; document.getElementById( sDiv+"-FLECHASSCROLL" ).style.width = nWScroll+5+"px"; document.getElementById( sDiv+"-FLECHASSCROLL" ).style.height = nAlto+"px"; //Barra document.getElementById( sDiv+"-FLECHASSCROLL" ).innerHTML += "
"; if( sArchivoFlechas != "" ) { document.getElementById( sDiv+"-barra" ).style.height = nAlto-nWScroll*2+"px"; } document.getElementById( sDiv+"-liebre" ).style.height = document.getElementById( "img-"+sDiv+"-liebre" ).height+"px"; document.getElementById( "img-"+sDiv+"-liebre" ).style.height = document.getElementById( "img-"+sDiv+"-liebre" ).height+"px"; nuevoEvento( document.getElementById( sDiv ), 'mousemove', aCajasScroll[nNum].onMouseMoveMenuScroll ); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // CAJA SCROLL CONTENIDO ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// document.getElementById( sDiv+"-CSC" ).style.left = anCoords[1]+"px"; document.getElementById( sDiv+"-CSC" ).style.width = anCoords[2]+"px"; document.getElementById( sDiv+"-CSC" ).style.fontSize = nSize+"px"; document.getElementById( sDiv+"-CSC" ).style.fontFamily = sFamilia; document.getElementById( sDiv+"-CSC" ).style.lineHeight = nInterlineado+"px"; document.getElementById( sDiv+"-CSC" ).style.color = sColor; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // CREAMOS LA CAJA ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Si el contenido de la Caja es mayor que la altura de la caja creamos el Scroll aCajasScroll[ nNum ].crearScroll( sDiv, nX, nY, nAncho, nAlto, nSize, nWScroll, nVel, nInterlineado, anCoords[1], anCoords[2] ); //Scroll para la web //if( nNum == 0 && sNavegador == "firefox" && nWScroll != 0 ) window.addEventListener('DOMMouseScroll', wheelWeb, false); return nNum; }