Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/web/utiles.js
blob: 221be4a9a595741bdad52104c694bb53bab06dfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198

	function popup(popup_url,name,popup_width,popup_height) {
	 	var tmp = window.open(popup_url,name,'resizable=no,menubar=no,location=no,toolbar=no,status=yes,scrollbars=yes,directories=no,width='+popup_width+',height='+popup_height);
	}

	function mostrar(symbol,nombre,name,peso,numero,wiki) { 
	   if (!mostrado) {	
			mostrado = true;
			document.elementData.elementName.value = nombre;
			document.elementData.editedText.value = readTextElement(nombre);
			$("#textPopup").html("<p>"+
							"<b>Elemento:</b>&nbsp;"+nombre+" "+
							"(en inglés:&nbsp;"+name+")<br/>"+
							"<b>S&iacute;mbolo:</b>&nbsp;"+symbol+" "+
							"<b>Peso at&oacute;mico:</b>&nbsp;"+peso+" "+
							"<b>N&uacute;mero at&oacute;mico:</b>&nbsp;"+numero+"<br/>"+
							"<a href='javascript:openWiki(\""+wiki+"\")'>Wikipedia</a>"+
							"</p>"							);
			$("#pop").fadeIn('slow');
	   }	
	} 

	function popupText(text) {
		$("#textPopup").html(text);
		$("#pop").fadeIn('slow');
		mostrado = true;
    }

	function openWiki(url) {
   	    document.getElementById("wikiBody").src = url;
		$("#wiki").fadeIn('slow');
	}

	function cerrarWiki() { 
		$("#wiki").fadeOut('slow'); 
	}

	function cerrarMisNotas() { 
		$("#misNotas").fadeOut('slow'); 
	}

	function verMisNotas() { 
		misNotasText = "";
		for (i = 0;i < textos.length; i++) {
			textoElemento = textos[i];
			misNotasText = misNotasText + "<b>"+textoElemento[0]+"</b><br/>"+textoElemento[1]+"<br/><br/>";				
		}
		$("#textMisNotas").html(misNotasText);
		$("#misNotas").fadeIn('slow'); 
	}



	function cerrar() { 
		$("#pop").fadeOut('slow'); 
		mostrado = false;
		if (document.elementData.editedText.value != '') {
			writeTextElement(document.elementData.elementName.value,document.elementData.editedText.value);
		}
	}

	function readTextElement(element) {
		for(var i=0; i<textos.length; i++){
			textoElemento = textos[i];
	        if(textoElemento[0] == element) {
				return textoElemento[1];
            }
        }
		return '';
	}	

	function writeTextElement(element,text) {
		existe = false;
		for(var i=0; i<textos.length; i++){
			textoElemento = textos[i];
	        if(textoElemento[0] == element) {
				existe = true;
				textoElemento[1] = text;
            }
        }
		if (!existe) {
			textos.push(new Array(element,text));
		}
    }


	function debug(element) {
		debugText = '';
		for(var i=0; i<textos.length; i++){
			textoElemento = textos[i];
			debugText = debugText+ '  ' +textoElemento[0]+'='+textoElemento[1];
        }
		popupText(debugText);
	}	


 	XO.register('read', function(content) {
       // Your code to consume the supplied content
		if (content != '') {
			try {
			    //$("#loading").html(content);
				eval(content);		
			} catch(err) {
				textos = new Array();
			}
		}
		$("#loading").fadeOut('slow'); 
		mostrado = false;
		
    })


    XO.register('write', function() {
       // Your code to return the content to save
	   persistent = "textos = new Array(";
		for(var i=0; i<textos.length; i++){
			textoElemento = textos[i];
			persistent = persistent+"new Array('"+textoElemento[0]+"','"+textoElemento[1]+"')";
			if (i < (textos.length -1) ) {
				persistent = persistent +",";
			} else {
				persistent = persistent +");";
			}
        }
       return persistent;
    })

// Tooltip (basado en http://www.dynamicdrive.com/dynamicindex5/dhtmltooltip.htm)

    var offsetxpoint=-60; //Customize x offset of tooltip
    var offsetypoint=20; //Customize y offset of tooltip
    var ie=document.all;
    var ns6=document.getElementById && !document.all;
    var enabletip=false;
    
    if (ie||ns6) 
        var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

    function ietruebody() {
        return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
    }

    function ddrivetip(thetext, thecolor, thewidth) {
        if (ns6||ie){
            if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
                if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
                    tipobj.innerHTML=thetext;
                enabletip=true;
            return false;
        }
    }

    function positiontip(e) {
        if (enabletip) {
            var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
            var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
            //Find out how close the mouse is to the corner of the window
            var rightedge=ie&&!window.opera? ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20;
            var bottomedge=ie&&!window.opera? ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20;

            var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000;

            //if the horizontal distance isn't enough to accomodate the width of the context menu
            if (rightedge<tipobj.offsetWidth)
            //move the horizontal position of the menu to the left by it's width
                tipobj.style.left=ie? ietruebody().scrollLeft+event.clientX-tipobj.offsetWidth+"px" : window.pageXOffset+e.clientX-tipobj.offsetWidth+"px"
            else if (curX<leftedge)
                tipobj.style.left="5px";
            else
                //position the horizontal position of the menu where the mouse is positioned
                tipobj.style.left=curX+offsetxpoint+"px";

            //same concept with the vertical position
            if (bottomedge<tipobj.offsetHeight)
                tipobj.style.top=ie? ietruebody().scrollTop+event.clientY-tipobj.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-tipobj.offsetHeight-offsetypoint+"px";
            else
                tipobj.style.top=curY+offsetypoint+"px";
                tipobj.style.visibility="visible";
        }
    }

    function hideddrivetip() {
        if (ns6||ie) {
            enabletip=false;
            tipobj.style.visibility="hidden";
            tipobj.style.left="-1000px";
            tipobj.style.backgroundColor='';
            tipobj.style.width='';
        }
    }

    document.onmousemove=positiontip;