PageSourceSearch

https://www.zaragoza.es/js/tree_functions.js

js zaragoza.es collected 2026-10-09 16:46:49 UTC 21,726 bytes, 664 lines download raw bytes

1/*************************************************************************************/
2/**Variables globales								    **/
3/*************************************************************************************/
4//Directorio de imagenes de bordes redondeados del arbol
5/*
6	iaaa: 08-03-2013
7	Variable para facilitar la introduccion de rutas absolutas
8	Si se define como "" se emplean relativas
9*/
10var myHomeIP;
11try{
12	if (homeIP) {
13		myHomeIP = homeIP;
14	} else {
15		if (parent.homeIP) {
16			myHomeIP = parent.homeIP;
17		} else {
18			myHomeIP = "";
19		}
20	}
21} catch(e) {
22	try {
23		if (parent.homeIP) {
24			myHomeIP = parent.homeIP;
25		} else {
26			myHomeIP = "";
27		}
28	} catch(e) {
29		myHomeIP = "";
30	}
31} 
32var directorioRecursos = myHomeIP + "/img";
33//Margen de seguridad para el cálculo de la altura del arbol
34var safeMargin = 50;
35//Listado de categorias del arbol se emplea para calcular la altura del mismo
36var treeCategories = [];
37
38/*************************************************************************************/
39/**Funciones definidas en homeMapa						    **/
40/*************************************************************************************/
41function getIcono(item, opened) {
42        if(item.root){
43            return "diagramIcon";
44        } else {
45    	if(!item.children){
46		return "icono";
47	}
48        }
49
50    }
51
52function getStyle(item, opened){
53    if(!item.root){
54    	if(!item.children){
55    	    return {backgroundImage: "url(//www.zaragoza.es/contenidos/iconos/" + item.claseIcono + ".png)"};
56        }
57    }
58        return '';
59}
60
61function treeOnClick(item) {
62	var node = this.selectedNode;
63	if(!item.root && item.url != undefined){
64		try{
65			javascript:cambiarVisibilidad(item, node);
66		} catch(ex) {
67			try{
68				javascript:parent.cambiarVisibilidad(item, node);
69			} catch(ex1) {
70				
71			}
72		}
73	}
74}
75
76function getAccordionElementImageNode(item) {
77	var index;
78	var elem = 0;
79	if (treeControlActualidad) {
80		elem = elem + 1;
81	}
82	if (treeControlMovilidad) {
83		elem = elem + 1;
84	}
85	if (treeControlEquipamientos) {
86		elem = elem + 1;
87	}
88	if (treeControlActualidad && item.domNode == treeControlActualidad.domNode) {
89		index = ((treeControlActualidadOrder != null) ? treeControlActualidadOrder : 0);
90	} else if (treeControlMovilidad && item.domNode == treeControlMovilidad.domNode) {
91		index = ((treeControlMovilidadOrder != null) ? treeControlMovilidadOrder : 1);
92	} else if (treeControlEquipamientos && item.domNode == treeControlEquipamientos.domNode) {
93		index = ((treeControlEquipamientosOrder != null) ? treeControlEquipamientosOrder : 2);
94	} else if (item.domNode == panelLocalizarDireccion.domNode) {
95		index = ((panelLocalizarDireccionOrder != null) ? panelLocalizarDireccionOrder : elem);
96	} else {
97		return;
98	}
99	return aContainer.domNode.childNodes[index].children[0].children[0].children[0];
100}
101
102function itemOnShow() {
103	var node = getAccordionElementImageNode(this);
104	var className = node.className;
105	className = className.replace("dijitAccordionArrow", "dijitAccordionArrowOn");
106	node.className = className;
107}
108
109function itemOnHide() {
110	var node = getAccordionElementImageNode(this);
111	var className = node.className;
112	className = className.replace("dijitAccordionArrowOn", "dijitAccordionArrow");
113	node.className = className;
114}
115
116/*
117	iaaa: 08-03-2013
118	Se modifica la funcion para que se puedan actualizar los nodos expandibles
119*/
120function treeOnLoad() {
121	var elem;
122	var nodoId;
123	for (var itera in this._itemNodesMap) {
124		var nodo = this._itemNodesMap[itera];
125		if (nodo && nodo[0] && nodo[0].item) {
126			if (nodo[0].item.clase=='visible') {
127				nodo[0].contentNode.children[0].style.filter = 'alpha(opacity=100)';
128				nodo[0].contentNode.children[0].style.opacity = 1;
129			} else {
130				nodo[0].contentNode.children[0].style.filter = 'alpha(opacity=20)';
131				nodo[0].contentNode.children[0].style.opacity = 0.2;
132			}
133		}
134	}
135}
136
137/*************************************************************************************/
138/**Funciones auxiliares								    **/
139/*************************************************************************************/
140//Funcion de geocoder, busca la función definida en homeMapa "seleccion2visualizador"
141//si no la encuentra busca en el facade del visor
142function seleccionToVisualizador(calle,x,y){
143	try{
144		seleccion2visualizador(calle,x,y);
145	}catch(e){
146		try{
147			parent.seleccion2visualizador(calle,x,y);
148		} catch (ex) {
149			try {
150				getFacade().georreferenciarCalle(calle, x, y, "EPSG:23030");
151			} catch(ex2) {
152			}
153		}
154	}
155}
156
157/*************************************************************************************/
158/**Modificación de comportamiento del árbol de capas				    **/
159/*************************************************************************************/
160//Abrir todos los nodos
161expandAll = function()
162{
163    var _this = this;
164    function expand(node){
165        var def = new dojo.Deferred();
166        // Expand the node
167        _this._expandNode(node).addCallback(function(){
168            // When node has expanded, call expand() recursively on each non-leaf child
169            var childBranches = dojo.filter(node.getChildren() || [], function(node){
170                return node.isExpandable;
171            }),
172            defs = dojo.map(childBranches, expand);
173            // And when all those recursive calls finish, signal that I'm finished
174            new dojo.DeferredList(defs).addCallback(function(){
175                def.callback();
176            });
177        });
178        return def;
179    }
180    return expand(this.rootNode);
181};
182
183//Cerrar todos los nodos
184collapseAll = function(){
185    var _this = this;
186    function collapse(node) {
187        // never collapse root node, otherwise hides whole tree !
188        if ( _this.showRoot==false)
189                            if(node != _this.rootNode)
190            _this._collapseNode(node);
191        var childBranches = dojo.filter(node.getChildren() || [], function(node)
192        {
193            return node.isExpandable;
194        });
195        var def = new dojo.Deferred();
196        defs = dojo.map(childBranches, collapse);
197    }
198    return collapse( _this.rootNode);
199};
200
201/*
202	iaaa:
203		Se redefine una función de la librería de dojo para permitir el soporte de uso de 
204		scroll en los elementos del árbol en los navegadores de dispositivos móviles que lo
205		soporten, solucionando un problema que surge en Opera
206*/
207dojoOverwriteFunctions = {};
208dojoOverwriteFunctions["dijit.layout.AccordionContainer"] = {};
209dojoOverwriteFunctions["dijit.layout.AccordionContainer"]["_transition"] = 
210function(/*dijit._Widget?*/ newWidget, /*dijit._Widget?*/ oldWidget, /*Boolean*/ animate){
211	// Overrides StackContainer._transition() to provide sliding of title bars etc.
212	var isMobileNavigator;
213	try {
214		isMobileNavigator = mobileNavigator;
215	} catch(e) {
216		isMobileNavigator = false;
217	}
218	if (isMobileNavigator) {
219		try {
220			if (getFacade && getFacade() && getFacade().deshabilitarRedimensionMapa) {
221				getFacade().deshabilitarRedimensionMapa();
222			}
223		} catch(e) {}
224	}
225	if (dojo.isIE < 8){
226		// workaround animation bugs by not animating; not worth supporting animation for IE6 & 7
227		animate = false;
228	}
229
230	if(this._animation){
231		// there's an in-progress animation.  speedily end it so we can do the newly requested one
232		this._animation.stop(true);
233		delete this._animation;
234	}
235
236	var self = this;
237
238	if(newWidget){
239		newWidget._wrapperWidget.set("selected", true);
240		
241		if(newWidget._wrapperWidget &&
242		   newWidget._wrapperWidget.contentWidget && 
243		   newWidget._wrapperWidget.contentWidget.collapseAll) {
244			newWidget._wrapperWidget.contentWidget.collapseAll();
245		}
246
247		var d = this._showChild(newWidget);	// prepare widget to be slid in
248
249		// Size the new widget, in case this is the first time it's being shown,
250		// or I have been resized since the last time it was shown.
251		// Note that page must be visible for resizing to work.
252		if(this.doLayout && newWidget.resize){
253			newWidget.resize(this._containerContentBox);
254		}
255	}
256	
257	if(oldWidget){
258		oldWidget._wrapperWidget.set("selected", false);
259		if(!animate){
260			this._hideChild(oldWidget);
261		}
262	}
263
264	if(animate){
265		var newContents = newWidget._wrapperWidget.containerNode,
266			oldContents = oldWidget._wrapperWidget.containerNode;
267
268		// During the animation we will be showing two dijitAccordionChildWrapper nodes at once,
269		// which on claro takes up 4px extra space (compared to stable AccordionContainer).
270		// Have to compensate for that by immediately shrinking the pane being closed.
271		var wrapperContainerNode = newWidget._wrapperWidget.containerNode,
272			wrapperContainerNodeMargin = dojo._getMarginExtents(wrapperContainerNode),
273			wrapperContainerNodePadBorder = dojo._getPadBorderExtents(wrapperContainerNode),
274			animationHeightOverhead = wrapperContainerNodeMargin.h + wrapperContainerNodePadBorder.h;
275
276		oldContents.style.height = (self._verticalSpace - animationHeightOverhead) + "px";
277		
278		this._animation = new dojo.Animation({
279			node: newContents,
280			duration: this.duration,
281			curve: [1, this._verticalSpace - animationHeightOverhead - 1],
282			onAnimate: function(value){
283				value = Math.floor(value);	// avoid fractional values
284				newContents.style.height = value + "px";
285				oldContents.style.height = (self._verticalSpace - animationHeightOverhead - value) + "px";
286			},
287			onEnd: function(){
288				delete self._animation;
289				if (isMobileNavigator) {
290					try {
291						if (navigator.appName.toLowerCase().indexOf("opera") != -1) {
292							oldWidget._wrapperWidget.containerNode.style.display = "none";
293							self._hideChild(oldWidget);
294							try{javascript:recalcularAlturasArbol();}catch(ex){javascript:parent.recalcularAlturasArbol();}
295						} else {
296							newContents.style.height = "auto";
297							oldWidget._wrapperWidget.containerNode.style.display = "none";
298							oldContents.style.height = "auto";
299							self._hideChild(oldWidget);
300							/*
301								iaaa: 08-03-2013
302								Modificaciones para mejorar la representación del arbol
303								se corrigen problemas de altura y anchura
304							*/
305							var alt = obtenerAlturaContenedor();
306							if(parseInt(newContents.clientHeight) > alt) {
307								try{
308									javascript:inicializarAlturasArbol(alt);
309								}catch(ex){
310									javascript:parent.inicializarAlturasArbol(alt);
311								}
312							}
313						}
314					} catch(e) {
315						newContents.style.height = "auto";
316						oldWidget._wrapperWidget.containerNode.style.display = "none";
317						oldContents.style.height = "auto";
318						self._hideChild(oldWidget);
319					}
320					try {
321						if (getFacade && getFacade() && getFacade().habilitarRedimensionMapa) {
322			    			getFacade().habilitarRedimensionMapa();
323			    		}
324					} catch(e) {}
325				} else {
326					newContents.style.height = "auto";
327					oldWidget._wrapperWidget.containerNode.style.display = "none";
328					oldContents.style.height = "auto";
329					self._hideChild(oldWidget);
330					/*
331						iaaa: 08-03-2013
332						Modificaciones para mejorar la representación del arbol
333						se corrigen problemas de altura y anchura
334					*/
335					var alt = obtenerAlturaContenedor();
336					if(parseInt(newContents.clientHeight) > alt) {
337						try{
338							javascript:inicializarAlturasArbol(alt);
339						}catch(ex){
340							javascript:parent.inicializarAlturasArbol(alt);
341						}
342					}
343				}
344				if (newContents.children && newContents.children.length && 
345				   (newContents.children[0].id.toLowerCase().indexOf("layout_accordionpane") != -1)) {
346					var node = newContents.children[0];
347					try{
348						actualizarAnchuraContenedor(newContents, node);
349					} catch(e) {
350						try{
351							parent.actualizarAnchuraContenedor(newContents, node);
352						}catch(ex){}
353					}
354				}
355			}
356		});
357		this._animation.onStop = this._animation.onEnd;
358		this._animation.play();
359	}
360
361	return d;	// If child has an href, promise that fires when the widget has finished loading
362};
363
364/*
365	iaaa: 08-03-2013
366	Modificaciones para poder actualizar el icono de capa visible de nodos hijos de nodos expandibles
367*/
368dojoOverwriteFunctions["dijit._TreeNode"] = {};
369dojoOverwriteFunctions["dijit._TreeNode"]["expand"] = function(){
370	// summary:
371	//		Show my children
372	// returns:
373	//		Deferred that fires when expansion is complete
374
375	// If there's already an expand in progress or we are already expanded, just return
376	if(this._expandDeferred){
377		return this._expandDeferred;		// dojo.Deferred
378	}
379
380	// cancel in progress collapse operation
381	this._wipeOut && this._wipeOut.stop();
382
383	// All the state information for when a node is expanded, maybe this should be
384	// set when the animation completes instead
385	this.isExpanded = true;
386	dijit.setWaiState(this.labelNode, "expanded", "true");
387	if(this.tree.showRoot || this !== this.tree.rootNode){
388		dijit.setWaiRole(this.containerNode, "group");
389	}
390	dojo.addClass(this.contentNode,'dijitTreeContentExpanded');
391	this._setExpando();
392	this._updateItemClasses(this.item);
393	if(this == this.tree.rootNode){
394		dijit.setWaiState(this.tree.domNode, "expanded", "true");
395	}
396
397	var pointer = this;
398	var def,
399		wipeIn = dojo.fx.wipeIn({
400			node: this.containerNode, duration: dijit.defaultDuration,
401			onBegin: function(){
402				def.callback(true);
403				var children = [];
404				if (pointer && pointer.item && pointer.item.children && pointer.item.children.length) {
405					children = pointer.item.children;
406				}
407				for (var i=0, len=pointer.item.children.length; i<len; i++) {
408					var item = pointer.item.children[i];
409					if (item.id) {
410						var nodeId = item.id[0];
411						if (pointer.tree && pointer.tree._itemNodesMap && pointer.tree._itemNodesMap[nodeId]) {
412							var img = pointer.tree._itemNodesMap[nodeId][0].contentNode.children[0];
413							var visibility = (item.clase == 'visible');
414							if (visibility) {
415								img.style.filter = 'alpha(opacity=100)';
416								img.style.opacity = 1;
417							} else {
418								img.style.filter = 'alpha(opacity=20)';
419								img.style.opacity = 0.2;
420							}
421						}
422					}
423				}
424			}
425		});
426
427	// Deferred that fires when expand is complete
428	def = (this._expandDeferred = new dojo.Deferred(function(){
429		// Canceller
430		wipeIn.stop();
431	}));
432
433	wipeIn.play();
434
435	return def;		// dojo.Deferred
436}
437
438if(navigator.appName == "Microsoft Internet Explorer"){
439	//Resolver un problema de posicionamiento en nodos expandibles
440	dojoOverwriteFunctions["dijit._TreeNode"] = {};
441	dojoOverwriteFunctions["dijit._TreeNode"]["_setIndentAttr"] = function(indent){
442		// summary:
443		//		Tell this node how many levels it should be indented
444		// description:
445		//		0 for top level nodes, 1 for their children, 2 for their
446		//		grandchildren, etc.
447	
448		// Math.max() is to prevent negative padding on hidden root node (when indent == -1)
449		var pixels = (Math.max(indent, 0) * this.tree._nodePixelIndent) + "px";
450		
451		if(parseInt(pixels) == 1900) {
452			pixels = "19px";
453		}
454		
455		dojo.style(this.domNode, "backgroundPosition",	pixels + " 0px");
456		dojo.style(this.rowNode, this.isLeftToRight() ? "paddingLeft" : "paddingRight", pixels);
457	
458		dojo.forEach(this.getChildren(), function(child){
459			child.set("indent", indent+1);
460		});
461		
462		this._set("indent", indent);
463	};
464}
465
466//Redefinir funciones de dojo
467function redefinirFuncionesDojo() {
468	var object;
469	for (var i in dojoOverwriteFunctions) {
470		try {
471			object = eval(i);
472			for (var j in dojoOverwriteFunctions[i]) {
473				if (object) {
474					object.prototype[j] = dojoOverwriteFunctions[i][j];
475				}
476			}
477		} catch (e) {
478		}
479	}
480}
481
482/*************************************************************************************/
483/**Funciones de configuracion e inicializacion del arbol							**/
484/*************************************************************************************/
485//Definir categorías del árbol, se emplea la lista de categorías para calcular la altura del árbol
486function definirCategoriasArbol(categories) {
487	try {
488		if(categories) {
489			treeCategories = categories;
490			for (var i=0, iLen = treeCategories.length; i<iLen; i++){
491				if (treeCategories[i] && treeCategories[i].id && 
492					(treeCategories[i].id.toLowerCase().indexOf("tree")!=-1)) {
493					treeCategories[i].collapseAll = collapseAll;
494					treeCategories[i].expandAll = expandAll;
495				}
496			}
497		}
498	} catch (e) {
499	}
500}
501
502/*
503	iaaa: 08-03-2013
504	Modificaciones para redimensionar el arbol correctamente
505*/
506//Abrir/cerrar el árbol al iniciarlo
507function abrirArbolAlInicializar(valor){
508	try {
509			colapsar();
510			resizeElements(true);
511			if (getFacade && getFacade().redimensionarArbol) {
512				getFacade().redimensionarArbol();
513			}
514			if(valor) {
515				//Para que el árbol salga correctamente abierto (todos sus elementos colocados
516				//y redimensionados correctamente se cierra y se vuelve a abrir)
517				colapsar();
518			}
519	} catch(ex) {
520			try {
521				parent.colapsar();
522				parent.resizeElements(true);
523				if (parent.getFacade && parent.getFacade().redimensionarArbol) {
524					parent.getFacade().redimensionarArbol();
525				}
526				if (valor) {
527					//Para que el árbol salga correctamente abierto (todos sus elementos colocados
528					//y redimensionados correctamente se cierra y se vuelve a abrir)
529					parent.colapsar();
530				}
531			} catch(ex1){
532				//no se ecuentra la funcion
533			}
534	}
535}
536
537//Mostrar el boede del árbol redondeado
538var treeParentNodeId = null;
539function mostrarBordeRedondeado(altura, parentNodeId, borderNodeId, borderFillId, borderUpId, borderDownId){
540	if (parentNodeId && borderNodeId && borderFillId && borderUpId && borderDownId) {
541		treeParentNodeId = parentNodeId;
542		var treeNodeRound = document.createElement('div');
543		treeNodeRound.setAttribute('id', borderNodeId);
544		var treeNodeRoundImgUp = document.createElement('img');
545		treeNodeRoundImgUp.setAttribute('id', borderUpId);
546		treeNodeRoundImgUp.src = directorioRecursos + "/tree_corner_up.gif";
547		treeNodeRound.appendChild(treeNodeRoundImgUp);
548		var treeNodeRoundInner = document.createElement('div');
549		treeNodeRoundInner.setAttribute('id', borderFillId);
550		//Internet explorer requiere que se defina el ancho del div
551		treeNodeRoundInner.style.width = "13px";
552		treeNodeRound.appendChild(treeNodeRoundInner);
553		var treeNodeRoundImgDown = document.createElement('img');
554		treeNodeRoundImgDown.setAttribute('id', borderDownId);
555		treeNodeRoundImgDown.src = directorioRecursos + "/tree_corner_down.gif";
556		treeNodeRound.appendChild(treeNodeRoundImgDown);
557		if (parentNodeId) {
558			document.getElementById(parentNodeId).appendChild(treeNodeRound);
559		} else {
560			document.body.appendChild(treeNodeRound);
561		}
562		treeNodeRound.style.height=altura+"px";
563		treeNodeRoundInner.style.height=(altura-26)+"px";
564	}
565}
566/*
567	iaaa: 08-03-2013
568	Variables que almacenan información para el cálculo de altura del árbol
569*/
570var treeNodesNumber = 0;
571var treeNodesSize = 0;
572var treeMargin = 0;
573var treeMarginTop = 0;
574var treeMarginBottom = 0;
575//Inicializar la altura de cada uno de los contenedores de los nodos del arbol
576function inicializarAlturaNodosArbol(altura, numHijos, tamHijo, margen){
577	altura = ((altura != undefined) && (altura != null))?altura:10;
578	numHijos = ((numHijos != undefined) && (numHijos != null))?numHijos:0;
579	tamHijo = ((numHijos != undefined) && (numHijos != null))?tamHijo:0;
580	margen = ((margen != undefined) && (margen != null))?margen:0;
581	
582	treeNodesNumber = numHijos;
583	treeNodesSize = tamHijo;
584	if ((typeof margen).toLowerCase() == "number") {
585		treeMarginTop = margen;
586		treeMarginBottom = margen;
587	} else {
588		treeMarginTop = margen.top;
589		treeMarginBottom = margen.bottom;
590	}
591	
592	var alt = altura - (numHijos*tamHijo + safeMargin) - margen - margen;
593
594	if (alt < 0) {
595		alt = 3;
596	}
597		
598	/*
599		iaaa 21-2-2013:
600		Se fuerza el tamaño de los contenedores de las listas de capas 
601	*/
602	try {
603		inicializarAlturasArbol(alt);
604	} catch(ex) {
605		try {
606			parent.inicializarAlturasArbol(alt);
607		} catch(ex1) {
608		}
609	}
610}
611
612//Inicializar el árbol
613function inicializarArbol(abierto, categorias, altura, tamCat, margen) {
614	try {
615		categorias = (categorias?categorias:[]);
616		/*
617		iaaa: 08-03-2013
618			Informa de que el arbol se ha cargado
619		*/
620		try{
621			setArbolCargado(true);
622		} catch(ex) {
623			try {
624				parent.setArbolCargado(true);
625			} catch(ex1) {
626			}
627		}
628		abrirArbolAlInicializar(abierto);
629		definirCategoriasArbol(categorias);
630		inicializarAlturaNodosArbol(altura, categorias.length, tamCat, margen);
631	} catch(ex2) {
632		//alert("Error al cargar el arbol de capas: \n" + ex2);
633	}
634}
635
636/*
637	iaaa: 08-03-2013
638	Funcion para obtener la actura actual del arbol
639*/
640function obtenerAlturaContenedor(){
641	try {
642		var altura = document.getElementById(treeParentNodeId).clientHeight;
643		var alt = altura - (treeNodesNumber*treeNodesSize + safeMargin) - treeMarginTop - treeMarginBottom - 5;
644		return alt;
645	} catch(e) {
646		return 0;
647	}
648}
649
650/*************************************************************************************/
651/**Funciones de interaccion con el árbol 					    **/
652/*************************************************************************************/
653//Cerrar todos los nodos hijos del nodo seleccionado
654function collapseSelectedTree(){
655	try {
656		for (var i = 0, iLen = treeCategories.length; i<iLen; i++) {
657			if(treeCategories[i] && treeCategories[i].selected && treeCategories[i].collapseAll){
658				treeCategories[i].collapseAll();
659			}	
660		}
661	} catch(e) {
662		//
663	}
664}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.