<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Polar Geek &#187; javascript</title>
	<atom:link href="http://www.polargeek.net/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.polargeek.net</link>
	<description>Desarrollo web, tips, diseño, php, javascript...</description>
	<lastBuildDate>Thu, 29 Jul 2010 09:33:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Cómo crear un plugin en jQuery</title>
		<link>http://www.polargeek.net/como-crear-un-plugin-en-jquery/</link>
		<comments>http://www.polargeek.net/como-crear-un-plugin-en-jquery/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 06:00:21 +0000</pubDate>
		<dc:creator>José</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[plugin]]></category>

		<guid isPermaLink="false">http://www.polargeek.net/?p=1705</guid>
		<description><![CDATA[Hoy construiremos un plugin en jQuery, por supuesto iremos paso a paso y si no has construido nunca ninguno al final del tutorial te aseguro que podrás. ¿Empezamos? ¿Para qué sirve un plugin de jQuery? Antes que nada, tenemos que saber para qué nos sirve hacer un plugin y por qué tiene ventajas sobre hacer [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy construiremos un plugin en jQuery, por supuesto iremos paso a paso y si no has construido nunca ninguno al final del tutorial te aseguro que podrás. ¿Empezamos?</p>
<h2>¿Para qué sirve un plugin de jQuery?</h2>
<p>Antes que nada, tenemos que saber para qué nos sirve hacer un plugin y por qué tiene ventajas sobre hacer un par de funciones, por ejemplo. Lo primero que debemos recordar es que <strong>plug in</strong> significa <strong>conectar</strong>, es decir, haremos algo que luego podremos conectar a distintos sitios.</p>
<p>Teniendo esto en mente, nos podemos imaginar el plugin como una caja negra, que hará algo y nos devolverá el resultado (o realizará una acción simplemente).</p>
<div class="img"><img src="http://static.polargeek.net/uploads/jquery/pluginjquery.jpg" alt="Plugin jQuery" /></div>
<p>Por tanto un plugin tendrá la posibilidad de aceptar una entrada y producir un resultado, y esta &#8220;caja&#8221; que se ve en el esquema <strong>se podrá llevar a cualquier proyecto</strong>, sin ninguna modificación, aceptando allí otra salida. Esa es la clave de los plugin, que son reutilizables en cualquier sitio, sin tener que preocuparnos por cómo está hecho ni siquiera, simplemente &#8220;conectándolo&#8221; e invocándolo con datos de entrada.</p>
<p>Además, la invocación de este plugin será la misma que hacemos cuando usamos cualquier método de jQuery: </p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#caja'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">acortar</span><span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//acortar será el nombre del plugin</span></pre></div></div>

<h2>Nuestro primer plugin</h2>
<h3>Qué vamos a hacer</h3>
<p>Este plugin reducirá el texto en una caja, y con un click en un enlace lo expandirá. Así de simple, aunque como veremos después la implementación va a ser un pelín más larga de lo que debería para ser nuestro primer plugin, pero sin problema, poco a poco lo haremos. Si te quedan dudas sobre qué vamos a hacer tienes un enlace al demo <a href="http://www.polargeek.net/wp-content/uploads/demos/plugin/index.html">aquí</a> y al final del post.</p>
<h3>Primeros pasos al construir un plugin</h3>
<p>Cuando se construye un plugin hay una serie de pasos generales, que se hacen para todos los plugin que construyamos y que son los siguientes:</p>
<h4>Declaración del plugin</h4>
<p>El primer paso al hacer un plugin es declararlo, extender la serie de métodos que tiene jQuery originalmente. Para ello escribimos lo siguiente:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">acortar</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>Línea 1</strong>. Pasamos a nuestra declaración &#8220;jQuery&#8221;, el objeto, de tal forma que lo podemos usar como $, sin que interfiera con otras librerías.</p>
<p><strong>Línea 2</strong>. Extendemos el objeto jQuery con nuevo método llamado acortar.</p>
<p><strong>Línea 3</strong>. Recorremos todos los objetos que se le pasen a nuestro plugin. Recordemos que un selector puede seleccionar varios elementos, como todos los h1, por ejemplo. Aquí los recorremos y aplicamos la función que hagamos en nuestro plugin a cada uno de ellos.</p>
<p>Esto lo vamos a tener que hacer para todos los plugins que programemos, así que intenta entederlo bien. Lógicamente, cambiaremos el nombre dependiendo del plugin, en este caso lo llamaremos &#8220;acortar&#8221;.</p>
<h4>Parámetros que aceptaremos como opciones del plugin</h4>
<p>Casi todos los plugin tienen opciones, si estamos realizando un plugin que acorte el texto de una caja para que no se vea tan grande algunos parámetros que tenemos que permitir configurar al usuario pueden ser los siguientes:</p>
<ul>
<li>nCaracteres: Número de caracteres a mostrar. Ocultaremos el resto.</li>
<li>nExtra: Para evitar acortar un texto sólo por unos caracteres. El número exacto es este parámetro.</li>
<li>textoSuspense: String que se mostrará para hacer notar que hay más texto.</li>
<li>textoContraer: Texto mostrado como link para contraer.</li>
<li>linkExpandir: Texto mostrado como link para expandir</li>
</ul>
<p>Así el usuario podrá personalizar el plugin sin tener que preocuparse de cómo está hecho por dentro. Empecemos por procesar la entrada:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">acortar</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>opciones<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> parametrosPorDefecto <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	  nCaracteres<span style="color: #339933;">:</span> <span style="color: #CC0000;">300</span><span style="color: #339933;">,</span>
	  nExtra<span style="color: #339933;">:</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">,</span>
	  textoSuspense<span style="color: #339933;">:</span> <span style="color: #3366CC;">'...'</span><span style="color: #339933;">,</span>
	  textoContraer<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Contrae'</span><span style="color: #339933;">,</span>
	  linkExpandir<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Click para Expandir'</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>                   
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> opciones <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>parametrosPorDefecto<span style="color: #339933;">,</span> opciones<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Por tanto cuando tengamos que acceder a uno de los parámetros de entrada haremos, por ejemplo,  opciones.nExtra, así de simple.</p>
<h4>Copiar el objeto que nos pasan a variable local</h4>
<p>Cuando nos metemos en el bucle each, que puedes ver en la última sección de código, estamos procesando todos los elementos que han sido seleccionados al llamar el plugin. En ese preciso momento, cuando empezamos el bucle con un objeto, el objeto seleccionado está en la palabra reservada <strong>this</strong>, así que debemos guardarlo para referirnos siempre a él y no liarla cuando cambiemos el contexto (<i>scope</i>).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">acortar</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>opciones<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> parametrosPorDefecto <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	  nCaracteres<span style="color: #339933;">:</span> <span style="color: #CC0000;">300</span><span style="color: #339933;">,</span>
	  nExtra<span style="color: #339933;">:</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">,</span>
	  textoSuspense<span style="color: #339933;">:</span> <span style="color: #3366CC;">'...'</span><span style="color: #339933;">,</span>
	  textoContraer<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Contrae'</span><span style="color: #339933;">,</span>
	  linkExpandir<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Click para Expandir'</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>                    
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> opciones <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>parametrosPorDefecto<span style="color: #339933;">,</span> opciones<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>         
	  objeto <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Implementando nuestro plugin</h3>
<p>Bien, ya tenemos lo que queremos hacer, qué vamos a permitirle al usuario y cómo declarar el plugin. Empecemos ahora a implementar la funcionalidad en sí de éste. Esto por supuesto es propio de cada uno, así que intentaré no pararme demasiado en esta parte, porque, al fin y al cabo, ya sabemos crear un plugin genérico y la dificultad del resto dependerá de lo que queramos hacer.</p>
<h4>Procesar texto</h4>
<p>En este punto necesitamos ver si realmente tenemos que acortar el texto porque sobrepasa lo permitido (dado por el parámetro nCaracteres) y si es así ejecutamos toda la funcionalidad del plugin. A partir de aquí consideremos que estamos dentro del bucle que hemos mencionado antes (a partir de la línea 12 del último código). Veremos hasta los puntos suspensivos, dónde empezaremos en el siguiente punto.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> texto <span style="color: #339933;">=</span> objeto.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> longitudPermitida <span style="color: #339933;">=</span> opciones.<span style="color: #660066;">nCaracteres</span> <span style="color: #339933;">+</span> opciones.<span style="color: #660066;">nExtra</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//Si tenemos un texto más corto no tenemos que hacer nada</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>texto.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> longitudPermitida<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> lugarCorte <span style="color: #339933;">=</span> texto.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color: #339933;">,</span> opciones.<span style="color: #660066;">nCaracteres</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>lugarCorte <span style="color: #339933;">!=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//Sacamos el texto hasta el lugar de corte</span>
    <span style="color: #003366; font-weight: bold;">var</span> str1 <span style="color: #339933;">=</span> texto.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>lugarCorte<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #006600; font-style: italic;">//Sacamos el resto del texto, que vamos a esconder</span>
  	<span style="color: #003366; font-weight: bold;">var</span> str2 <span style="color: #339933;">=</span> texto.<span style="color: #660066;">substring</span><span style="color: #009900;">&#40;</span>lugarCorte<span style="color: #339933;">,</span>texto.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//Por último insertamos el enlace para ver más texto</span>
	objeto.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>str1 <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;a href=&quot;#&quot; class=&quot;textoSuspense&quot;&gt;'</span> <span style="color: #339933;">+</span> 
				opciones.<span style="color: #660066;">textoSuspense</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/a&gt;'</span> <span style="color: #339933;">+</span> 
				<span style="color: #3366CC;">'&lt;span class=&quot;oculto&quot;&gt;'</span> <span style="color: #339933;">+</span> str2 <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/span&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//Ocultamos el resto con el método hide de jQuery</span>
	$.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.oculto'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'fast'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #006600; font-style: italic;">//Enlace para expandir o contraer el texto</span>
    objeto.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>
	  <span style="color: #3366CC;">'&lt;div class=&quot;clearboth&quot;&gt;'</span> <span style="color: #339933;">+</span>
	    <span style="color: #3366CC;">'&lt;a href=&quot;#&quot; class=&quot;anchorTexto&quot;&gt;'</span> <span style="color: #339933;">+</span> opciones.<span style="color: #660066;">linkExpandir</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/a&gt;'</span> <span style="color: #339933;">+</span>
	  <span style="color: #3366CC;">'&lt;/div&gt;'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                                                                                      
<span style="color: #006600; font-style: italic;">//...</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ahora, sigamos en el siguiente apartado por donde están los puntos suspensivos (ya queda poco).</p>
<h4>Manejando el evento onClick para ampliar o reducir el texto</h4>
<p>Lo que falta por hacer es manejar que cuando se le da al link para ver más efectivamente se vea el resto del texto, además de que el texto se oculte. Hagamos esto entonces: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// ... Lo anterior ...</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> ControlLink <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.anchorTexto'</span><span style="color: #339933;">,</span> objeto<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> restoTexto <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.oculto'</span><span style="color: #339933;">,</span> objeto<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> suspense <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.textoSuspense'</span><span style="color: #339933;">,</span> objeto<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
ControlLink.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>ControlLink.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> opciones.<span style="color: #660066;">linkExpandir</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    restoTexto.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'normal'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ControlLink.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>opciones.<span style="color: #660066;">textoContraer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    suspense.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;display&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;none&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    restoTexto.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'normal'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ControlLink.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>opciones.<span style="color: #660066;">linkExpandir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    suspense.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;display&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;inline&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #006600; font-style: italic;">// ... Cierre de llaves abiertas antes....</span></pre></td></tr></table></div>

<p>En esta última parte vemos si tenemos el texto oculto o no. Y si está abierto cambiamos el texto al hacer click y lo ocultamos. Y viceveras si es al revés. Recuerda que estamos controlando el evento click en el enlace para expandir o contraer el texto, simplemento eso.</p>
<h3>Recapitulación</h3>
<p>Y eso es todo, hemos creado nuestro plugin que realmente funciona haciendo algo y además es configurable hasta cierto punto. Para llamarlo (puedes ver el código en el ejemplo) haremos lo siguiente, como hemos dicho al principio:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> language<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;Javascript&quot;</span><span style="color: #339933;">&gt;</span>
  $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">acortar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  	nCaracteres<span style="color: #339933;">:</span> <span style="color: #CC0000;">300</span><span style="color: #339933;">,</span>
  	nExtra<span style="color: #339933;">:</span> <span style="color: #CC0000;">20</span><span style="color: #339933;">,</span>
  	textoSuspense<span style="color: #339933;">:</span> <span style="color: #3366CC;">'...'</span><span style="color: #339933;">,</span>
  	textoContraer<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Contrae'</span><span style="color: #339933;">,</span>
  	linkExpandir<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Click para Expandir'</span>
  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Estos son los parámetros por defecto, por tanto si se los pasamos no pasa nada, pero es sólo un ejemplo, puedes pasarle otros.</p>
<div class="descarga">
<a href="http://static.polargeek.net/uploads/jquery/PrimerPlugin.zip" class="descargar"></a><a href="http://www.polargeek.net/wp-content/uploads/demos/plugin/index.html" class="demo"></a>
</div>
<h2>Conclusiones</h2>
<p>Por último destacar que lo más importante es que te quedes con cómo se construye cualquier plugin, más que con la implementación en concreto que hemos realizado. Aquí dejo los sitios que han ayudado a este post, sobre todo el de Jeremy Martin, de donde he sacado la idea del plugin y lo he modificada y separado para que sea más entendible. </p>
<ul>
<li><a href="http://blog.jeremymartin.name/2008/02/jtruncate-in-action.html">Blog de Jeremy Martin</a> | Plugin original.</li>
<li><a href="http://docs.jquery.com/Core">Explicación del Core de jQuery</a> | Documentación oficial.</li>
<li><a href="http://kamikaze00x.deviantart.com/art/Dropbox-FUSION-124352929">Autor de la &#8220;caja&#8221;</a> | DevianArt</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.polargeek.net/como-crear-un-plugin-en-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Buenas prácticas de JavaScript por Google</title>
		<link>http://www.polargeek.net/buenas-practicas-de-javascript-por-google/</link>
		<comments>http://www.polargeek.net/buenas-practicas-de-javascript-por-google/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 04:00:35 +0000</pubDate>
		<dc:creator>José</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.polargeek.net/?p=1636</guid>
		<description><![CDATA[Introducción Javascript, como quizá ya he dicho alguna vez, es el lenguaje con mayor relación de uso y desconocimiento del mismo, y cuando falla, la gente se sorprende, a pesar de que hayan empezado a programar en JavaScript sin tener ni idea del asunto. Aquí vemos una serie de buenas prácticas traidas de Google, en [...]]]></description>
			<content:encoded><![CDATA[<h2>Introducción</h2>
<p>Javascript, como quizá ya he dicho alguna vez, es el lenguaje con mayor relación de uso y desconocimiento del mismo, y cuando falla, la gente se sorprende, a pesar de que hayan empezado a programar en JavaScript sin tener ni idea del asunto.</p>
<div class="img"><img src="http://static.polargeek.net/uploads/javascript/google_logo.png" alt="Logo Google" /></div>
<p>Aquí vemos una serie de buenas prácticas traidas de Google, en su mayoría, que nos aclararán muchas ideas y nos ayudarán a mejorar nuestro código.</p>
<h2>Buenas prácticas</h2>
<h3>Uso de la palabra var</h3>
<p>A pesar de que se puede declarar una variable dentro de una función sin var, no es recomendable, porque no está claro en que contexto podemos acceder a ella. De tal forma, que no hay colisiones de nombres entre diferentes variables.</p>
<h3>Uso de punto y coma</h3>
<p>Quizá no sepas que JavaScript tiene por defecto lo que se llama <i>implicit insertion</i>, esto significa que por defecto inserta punto y coma el solito antes de cada salto de línea. Esto, que en principio podría parecer bueno y cómodo se convierte en un auténtico dolor de cabeza en ciertos casos, como este: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">MyClass.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">myMethod</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #CC0000;">42</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// Sin punto y coma</span>
&nbsp;
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #006600; font-style: italic;">// Inicialización de variables aquí</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Declaramos un método (no nos paremos a lo de prototype, ya lo explicaré en otro post) y después usamos una función anónima, pues bien, a la función primera se le pasa la segunda como parámetro, ¿intuitivo al máximo verdad? Pues para evitarlo sólo tenemos que tener en mente que siempre tenemos que usar los puntos y comas cuando acabemos una línea.</p>
<h3>Usar objetos para tipos primitivos</h3>
<p>Si queremos tener una variable de tipo booleana, o de un tipo primitivo hacer esto puede liar bastante las cosas: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Boolean<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hi'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Intuitivamente pensaríamos que no se va a imprimir nada, pero lo cierto es que si ejecutas el código, verás el alert con el texto &#8216;hi&#8217;.</p>
<p>Por tanto cuando queramos iniciar una variable de tipo primitivo, como &#8220;Boolean&#8221;, debemos usar la siguiente sintaxis: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> x <span style="color: #339933;">=</span> Boolean<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hi'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Y ahora no veremos el &#8216;hi&#8217;. De hecho si usamos el typeof para ver el tipo de datos que tenemos podemos comprobar que lo que estábamos creando antes no era un booleano, sino un objeto.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">typeof</span> Boolean<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'boolean'</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">typeof</span> <span style="color: #003366; font-weight: bold;">new</span> Boolean<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'object'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Ambas son true, así que tienes que tener claro cuando estás haciendo una variable de tipo objeto y cuando del tipo primitivo boolean.</p>
<h3>Los estándares se deben imponer</h3>
<p>Usa funciones o métodos estándar antes que otros que no lo son, porque favoreceran la compatibilidad entre navegadores y tu código se podrá integrar en otros más fácilmente, por ejemplo es preferible usar string.charAt(3) que string[3].</p>
<h2>Reglas de Estilo</h2>
<p>En todo lenguaje hay una serie de buenas prácticas, pero también un cierto estilo que nos ayuda a poder entender mejor el código y a adquirir una serie de reglas que hacen que el código sea igual en estilos en cualquier lugar.</p>
<h3>Nombres</h3>
<p>Siempre todo junto y cuando son varias palabras pues con mayúsculas a partir de la segunda.</p>
<ul>
<li>Funciones: estoEsUnaFuncion</li>
<li>Variables: estoEsUnaVariable</li>
<li>Clases: estoEsUnaClase</li>
<li>Enumerados: enumeradoTres</li>
<li>Métodos: estoEsUnMetodo</li>
<li>Constantes: ESTO_ES_UNA_CONSTANTE</li>
</ul>
<h3>Strings</h3>
<p>Preferiblemente con &#8221; (comillas simples) en vez con &#8220;&#8221; (comillas dobles), sobre todo de cara a que cuando escribimos HTML en un string, no tenemos que &#8220;escapar&#8221; las comillas.</p>
<h3>Paréntesis</h3>
<p>Solo cuando hagan falta, por ejemplo, no uses paréntesis en operadores como delete, typeof o void, o después de palabras reservadas como return, throw, case o new.</p>
<h3>Se consciente de lo que es true o false </h3>
<p>Uno de tantos problemas tontos con los que te encuentras cuando programas en JavaScript es asumir que ciertas cosas son verdaderas o falsas. Aquí tienes una lista: </p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">null</span> <span style="color: #006600; font-style: italic;">//false</span>
undefined  <span style="color: #006600; font-style: italic;">//false</span>
<span style="color: #3366CC;">''</span> string vacío <span style="color: #006600; font-style: italic;">//false</span>
<span style="color: #CC0000;">0</span> como número <span style="color: #006600; font-style: italic;">//false</span>
&nbsp;
<span style="color: #3366CC;">'0'</span> cero como string  <span style="color: #006600; font-style: italic;">//true</span>
<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> array vacío  <span style="color: #006600; font-style: italic;">//true</span>
<span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span> objeto vacío  <span style="color: #006600; font-style: italic;">//true</span></pre></td></tr></table></div>

<h3>Comenta con estilo</h3>
<p>Cuando se comenta el código además de hacer la razón por la que hacemos algo tenemos la posibilidad de generar documentación a la vez de manera sencilla, siguiendo una serie de reglas. Google lo hace así, y muchos desarrolladores lo recomiendan, en concreto podemos usar <a href="http://code.google.com/p/jsdoc-toolkit/">JSDoc</a>, y si todos lo hiciéramos sería más sencillo leer el código de otros y entenderlo, así que adelante con ello.</p>
<h2>Más información</h2>
<p>Tienes más consejos y buenas prácticas <a href="http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Visibility__private_and_protected_fields_">aquí</a>, hay muchos más, solo he destacado los más importantes y relativamente fáciles de explicar para no irme mucho del tema.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.polargeek.net/buenas-practicas-de-javascript-por-google/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacer una fila de una tabla clickable en HTML</title>
		<link>http://www.polargeek.net/hacer-una-fila-de-una-tabla-clickable-en-html/</link>
		<comments>http://www.polargeek.net/hacer-una-fila-de-una-tabla-clickable-en-html/#comments</comments>
		<pubDate>Wed, 12 May 2010 23:27:49 +0000</pubDate>
		<dc:creator>José</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tabla]]></category>

		<guid isPermaLink="false">http://www.polargeek.net/?p=1360</guid>
		<description><![CDATA[Filas en HTML y enlaces Este es el típico problema que hasta que no te pasa, ni siquiera sabías que existía. La cuestión es la siguiente: 1 2 3 4 5 6 7 &#60;table border=&#34;0&#34; width=&#34;&#34;&#62; &#60;tr&#62; &#60;td&#62;Uno&#60;/td&#62; &#60;td&#62;Dos&#60;/td&#62; &#60;td&#62;Tres&#60;/td&#62; &#60;/tr&#62; &#60;/table&#62; Teniendo una tabla en HTML como la de arriba queremos que una fila [...]]]></description>
			<content:encoded><![CDATA[<h2>Filas en HTML y enlaces</h2>
<p><img src="http://static.polargeek.net/uploads/san_diego.jpg" alt="San Diego (USA)" border="0" /></p>
<p>Este es el típico problema que hasta que no te pasa, ni siquiera sabías que existía. La cuestión es la siguiente:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">table</span> <span style="color: #000066;">border</span><span style="color: #66cc66;">=</span><span style="color: #5485C4;">&quot;0&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #5485C4;">&quot;&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Uno<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Dos<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">td</span>&gt;</span>Tres<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">td</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">tr</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">table</span>&gt;</span></pre></td></tr></table></div>

<p>Teniendo una tabla en HTML como la de arriba queremos que una fila entera se comporte como un enlace hacia otra página, es decir, como si estuviera entre la etiqueta anchor de HTML (<a href="#"></a>).</p>
<h2>Lo más intuitivo pero incorrecto</h2>
<p>Pues metes el elemento &#8216;table row&#8217; (tr) entre la etiqueta anchor y listo.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>table border<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;0&quot;</span> width<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;link.html&quot;</span><span style="color: #339933;">&gt;</span>			
<span style="color: #339933;">&lt;</span>tr<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>Uno<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>Dos<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;</span>Tres<span style="color: #339933;">&lt;/</span>td<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>tr<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>table<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Por desgracia esto no funciona, así que mal asunto. A partir de este punto es cuestión de echarle mucha imaginación o de intentar pensar un poco, en ambos casos no llegaremos a la solución perfecta, pero cerca nos quedaremos.</p>
<h2>Imaginación al poder</h2>
<p>Una solución es crear un anchor que se vaya moviendo por encima de cada fila según el mouse vaya pasando por ellas. Como puedes suponer, esta solución está en JavaScript, concretamente se ha usado jQuery y se ha realizado un plugin. Su uso es tan sencillo como:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'table#mitabla tr'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">superLink</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'a:last'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Pros</h3>
<p>Pues probablemente que es una solución con mucha imaginación detrás y su uso es realmente sencillo. Puedes ver el demo <a rel="external nofollow" href="http://james.padolsey.com/demos/plugins/jQuery/superLink/">aquí</a>, donde también hay un enlace donde el autor explica su idea.</p>
<h3>Contras</h3>
<p>Pues que al usar CSS y definir :hover (para cuando se pase el ratón por encima) no funciona. Es decir que el comportamiento normal que tiene un anchor en una página con respecto al CSS no existe. Además de eso, lo cierto es que tiene demasiada complejidad para una cosa que en principio puede parecer tan simple.</p>
<h2>Solución intuitiva</h2>
<p>Esta segunda opción viene dada por <a rel="external nofollow" href="http://radio.javaranch.com/pascarello/2005/05/19/1116509823591.html">Eric</a>. Lo cierto es que es bastante más sencilla, tiene en cuenta que realmente lo que queremos es que al hacer click en cualquier punto de una fila nos lleve a otra página. Así que con algo tan sencillo como esto no tendríamos que complicarnos más la vida:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #000066;">onload</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    ConvertRowsToLinks<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;table1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> ConvertRowsToLinks<span style="color: #009900;">&#40;</span>xTableId<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #006600; font-style: italic;">//Seleccionamos todas las table row (filas) del documento</span>
    <span style="color: #003366; font-weight: bold;">var</span> rows <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>xTableId<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tr&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">//Las recorremos con un for</span>
    <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>rows.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #006600; font-style: italic;">//Buscamos dentro de cada table row (tr) un elemento a</span>
        <span style="color: #003366; font-weight: bold;">var</span> link <span style="color: #339933;">=</span> rows<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>link.<span style="color: #660066;">length</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            <span style="color: #006600; font-style: italic;">//Si lo encontramos asociamos el evento click con la redirección</span>
            rows<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">onclick</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Function</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;document.location.href='&quot;</span> <span style="color: #339933;">+</span> link<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">href</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Pros</h3>
<p>Su simplicidad en cuanto a codificación, y que si respeta el problema del CSS. He preparado un ejemplo sencillo con Google Code PlayGround (del que hice <a href="http://www.polargeek.net/ejecutar-codigo-javascript-online-con-google/">un post</a> hace un tiempo). El ejemplo está <a href="http://savedbythegoog.appspot.com/?id=daf334169986a3bdfee67f9a3114f2402684372a">aquí</a> (el enlace lo he puesto con #1 y #2 para no salir de la página al hacer click pero puedes ver que funciona en la barra de direcciones <img src='http://www.polargeek.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ). Además esto está en JavaScript plano, por lo que no necesitamos incluir jQuery, como pasaba con el anterior.</p>
<h3>Contras</h3>
<p>Cuando el usuario no ejecuta el click sino intenta ir a la página de otra forma (por ejemplo pinchando con la rueda para abrir en otra pestaña) pues no lo podemos detectar. Hay varios eventos asociados a un anchor que nos pueden ser útiles (middle-click para el caso de la rueda, por decir alguno), pero tendríamos que definir la función asociado a cada evento y eso no es muy cómodo que digamos.</p>
<h2>Conclusión</h2>
<p>Hay tantas soluciones como se te puedan ocurrir, de hecho hay más plugins de jQuery por ahí con la misma función que el mostrado en el ejemplo primero, pero estas dos soluciones me parecieron las más destacables. ¿Tienes alguna otra?</p>
<p>Foto de <a href="http://www.flickr.com/photos/wouterpostma/1069260173/">Wouter</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.polargeek.net/hacer-una-fila-de-una-tabla-clickable-en-html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Diseño de esquemas con HTML y Javascript</title>
		<link>http://www.polargeek.net/diseno-de-esquemas-con-html-javascript/</link>
		<comments>http://www.polargeek.net/diseno-de-esquemas-con-html-javascript/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 02:32:31 +0000</pubDate>
		<dc:creator>José</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jsPlumb]]></category>

		<guid isPermaLink="false">http://www.polargeek.net/?p=1342</guid>
		<description><![CDATA[HTML + Javascript Con los avances en el desarrollo web se van a poder hacer cosas sencillamente impresionantes. Una de ellas es los gráficos con canvas. Por desgracia la mayoría de los avances van a tardar mucho en implantarse realmente en el mundo web (la primera versión de Internet Explorer 6.0 salió hace 9 años [...]]]></description>
			<content:encoded><![CDATA[<h2>HTML + Javascript</h2>
<p>Con los avances en el desarrollo web se van a poder hacer cosas sencillamente impresionantes. Una de ellas es los gráficos con canvas.</p>
<p>Por desgracia la mayoría de los avances van a tardar mucho en implantarse realmente en el mundo web (la primera versión de Internet Explorer 6.0 salió hace 9 años y todavía nos estamos pegando con él). </p>
<p>Esa es la mala noticia, la buena es que los millones de personas que están trabajando para el desarrollo de Internet quieren los avances ya, y no cuando los usuarios dejen de un lado navegadores antiguos. Es por ello que esta utilidad que os presento hoy es cross-browser, es decir que se puede utilizar en casi todos los navegadores. </p>
<h1>jsPlumb</h1>
<p>jsPlumb es un plugin que permite hacer cosas muy interesantes con esquemas gráficos bastante presentables.</p>
<div class="padding"><img src="http://static.polargeek.net/uploads/jsplumb.gif" border="0" /></div>
<p>El plugin, como he dicho requiere varias cosas, pero para todas hay una solución que permite que se vea en todos los navegadores:</p>
<ul>
<li>jQuery (1.3+)</li>
<li>jQuery IU (1.7+)</li>
<li>Explorer Canvas</li>
</ul>
<h2>Ejemplo sencillo</h2>
<p>Hay muchísimos ejemplos en la documentación pero para ir abriendo boca, un código sencillo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Se conecta el div con id window1 con el div con id window2</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#window1&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">plumb</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>target<span style="color: #339933;">:</span><span style="color: #3366CC;">'window2'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>Enlaces</h2>
<ul class="padding">
<li><a href="http://morrisonpitt.com/jsPlumb/doc/usage.html#basic">Documentación</a></li>
<li><a href="http://morrisonpitt.com/jsPlumb/html/demo.html">Demo</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.polargeek.net/diseno-de-esquemas-con-html-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Notificaciones estilo Growl con Jquery</title>
		<link>http://www.polargeek.net/notificaciones-estilo-growl-con-jquery/</link>
		<comments>http://www.polargeek.net/notificaciones-estilo-growl-con-jquery/#comments</comments>
		<pubDate>Mon, 22 Feb 2010 10:45:03 +0000</pubDate>
		<dc:creator>José</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jgrowl]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.polargeek.net/?p=1273</guid>
		<description><![CDATA[Growl en Mac Growl es un sistema de notificaciones usado en Mac OS X, que es bastante elegante y permite que todas las aplicaciones permitan dar el mismo tipo de notificaciones. En la imagen puedes ver su apariencia: Lo cierto es que es una de tantas posibilidades para notificar algo en un sistema operativo. La [...]]]></description>
			<content:encoded><![CDATA[<h2>Growl en Mac</h2>
<p>Growl es un sistema de notificaciones usado en Mac OS X, que es bastante elegante y permite que todas las aplicaciones permitan dar el mismo tipo de notificaciones. En la imagen puedes ver su apariencia:<br />
<img src="http://static.polargeek.net/uploads/growl-notifications.png" alt="" /></p>
<p>Lo cierto es que es una de tantas posibilidades para notificar algo en un sistema operativo. La cuestión es que dados los avances en desarrollo web de los últimos años se puede trasladar este tipo de apariencia y funcionalidad a la web de manera similar.</p>
<h2>jGrowl (Growl con jQuery)</h2>
<p>El proyecto se llama jGrowl y la descarga es gratuita (al final del post tienes los enlaces). Lo cierto es que una vez que incluyas los archivos javascript y css en el html, su uso es muy sencillo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// Hola Mundo simple</span>
$.<span style="color: #660066;">jGrowl</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Hello world!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Se queda en la esquina sin quitarse</span>
$.<span style="color: #660066;">jGrowl</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Stick this!&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> sticky<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Mensaje con un header en el mismo rectángulo</span>
$.<span style="color: #660066;">jGrowl</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;A message with a header&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> header<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Important'</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Estableciendo el tiempo que se muestra antes de ocultarse</span>
$.<span style="color: #660066;">jGrowl</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;A message that will live a little longer.&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> life<span style="color: #339933;">:</span> <span style="color: #CC0000;">10000</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// También puedes controlar cuando se va a abrir para hacer algo</span>
$.<span style="color: #660066;">jGrowl</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;A message with a beforeOpen callback and a different opening animation.&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
    beforeClose<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #339933;">,</span>m<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'About to close this notification!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
    animateOpen<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
        height<span style="color: #339933;">:</span> <span style="color: #3366CC;">'show'</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Su apariencia es también bastante buena:</p>
<div class="img"><img src="http://static.polargeek.net/uploads/jgrowl.png" alt="" /></div>
<h2>Enlaces</h2>
<p><a href="http://www.stanlemon.net/projects/jgrowl.html">Documentación y descarga</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.polargeek.net/notificaciones-estilo-growl-con-jquery/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Javascript cross-domain resuelto con PHP</title>
		<link>http://www.polargeek.net/javascript-cross-domain-resuelto-con-php/</link>
		<comments>http://www.polargeek.net/javascript-cross-domain-resuelto-con-php/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 18:23:35 +0000</pubDate>
		<dc:creator>José</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cross-domain]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.polargeek.net/?p=1240</guid>
		<description><![CDATA[Problema cross-domain en Javascript De una forma sencilla, digamos que en principio no es posible acceder desde el javascript de una página en el dominio A a otra en el dominio B. Es decir, si desde javascript queremos hacer una petición desde www.ejemplo.com/index.html a www.midominio.com/index.html, por motivos de seguridad no podemos. Hay una forma de [...]]]></description>
			<content:encoded><![CDATA[<h2>Problema cross-domain en Javascript</h2>
<p>De una forma sencilla, digamos que en principio no es posible acceder desde el javascript de una página en el dominio A a otra en el dominio B. </p>
<p>Es decir, si desde javascript queremos hacer una petición desde www.ejemplo.com/index.html a www.midominio.com/index.html, por motivos de seguridad no podemos.</p>
<p>Hay una forma de acceder a esos datos, y es que si lo hacemos a través del formato JSONP, no hay mayor problema, pero como sabrás, no todas las páginas a las que queremos acceder por lo que sea, tienen el formato JSONP disponible.</p>
<p>¿Cómo se resuelve esto? Pues aquí es cuando entra Simple PHP Proxy.</p>
<h2>Simple PHP Proxy</h2>
<p>Para acceder a una página que no está en nuestro dominio y no tiene el formato JSONP, utilizamos esta clase. </p>
<p>La idea es que el servidor donde se va a ejecutar nuestro código haga una copia local de la página a la que vamos a acceder a través de Javascript, y así no estamos haciendo cross-domain, estamos en nuestro servidor! </p>
<p><img src="http://static.polargeek.net/uploads/cross-domain.jpg" border="0" /><br />
Te podrías plantear la duda de: ¿y por qué no lo hago a mano? Bueno el problema es que las páginas cambian y hacerlo de manera manual, cada vez que quieras acceder a otro dominio te va a ser casi imposible.</p>
<h2>Cómo utilizar Simple PHP Proxy</h2>
<p>En la <a href="http://benalman.com/code/projects/php-simple-proxy/examples/simple/">página de ejemplo</a> podemos ver como funciona y el código en sí, en el que se utiliza para mostrar las cabeceras de un dominio que se le pase a través de Javascript, lo que demuestra que ha podido acceder a ese dominio superando así el problema del cross-domain.</p>
<h2>Enlaces</h2>
<p>Página del proyecto | <a href="http://benalman.com/projects/php-simple-proxy/">benalman.com</a><br />
Código y seguimiento | <a href="http://github.com/cowboy/php-simple-proxy">Github</a><br />
Documentación más exhaustiva | <a href="http://benalman.com/code/projects/php-simple-proxy/docs/files/ba-simple-proxy-php.html">benalman.com</a><br />
Código fuente de Simple PHP Proxy | <a href="http://github.com/cowboy/php-simple-proxy/raw/master/ba-simple-proxy.php">Descarga</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.polargeek.net/javascript-cross-domain-resuelto-con-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ejecutar Código Javascript Online con Google</title>
		<link>http://www.polargeek.net/ejecutar-codigo-javascript-online-con-google/</link>
		<comments>http://www.polargeek.net/ejecutar-codigo-javascript-online-con-google/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 23:36:48 +0000</pubDate>
		<dc:creator>José</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[playground]]></category>

		<guid isPermaLink="false">http://www.polargeek.net/?p=1156</guid>
		<description><![CDATA[El concepto La idea parte, de Google, más concretamente, está realizada por Ben Lisbakken. La explicación más en profundidad de como funciona esto la puedes ver abajo, en la conferencia que da el propio Ben Lisbakken (también habla sobre otras cosas, como por ejemplo reducir el tiempo de carga de tus páginas). Así que el [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://static.polargeek.net/uploads/2010/19/google_code.jpg"/></p>
<h2>El concepto</h2>
<p>La idea parte, de Google, más concretamente, está realizada por Ben Lisbakken. </p>
<p>La explicación más en profundidad de como funciona esto la puedes ver abajo, en la conferencia que da el propio Ben Lisbakken (también habla sobre otras cosas, como por ejemplo reducir el tiempo de carga de tus páginas).<br />
Así que el concepto es el siguiente: Una aplicación web donde puedes&#8230;</p>
<ul>
<li>Ver ejemplos de código Javascript (principalmente utilizando las API&#8217;s AJAX de Google).</li>
<li>Editar tu propio código.</li>
<li>Hacer debug de éste con la ayuda de Firebug.</li>
<li>Compartir el código con todo el mundo, con una url que no se borrará y que podrás pasar a quien quieras.</li>
</ul>
<h2>Utilización</h2>
<p>La utilización es bastante sencilla, simplemente vamos a <a href="http://code.google.com/apis/ajax/playground/">http://code.google.com/apis/ajax/playground/</a> y empezamos a ver los ejemplos. Cuando quieras cambiar algo, escribe en el cuadro de la derecha y haces click en &#8220;Run Code&#8221;. (Para exportarlo, botón de la flecha a la derecha).</p>
<p>El debug se hace con firebug, así que puedes poner breakpoints en el código y ver el contenido de las variables u objetos en cada momento.</p>
<p>Dejo una imagen:<br />
<img src="http://static.polargeek.net/uploads/2010/19/ajax-api-playground.jpg" alt="" width="606" height="464" border="0" /></p>
<h2>Conferencia</h2>
<h2 class="h2_listado">Vídeo</h2>
<p><object width="626" height="532"><param name="movie" value="http://www.youtube-nocookie.com/v/s4Lppyuu4nI&#038;hl=es_ES&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube-nocookie.com/v/s4Lppyuu4nI&#038;hl=es_ES&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="626" height="532"></embed></object></p>
<h2 class="h2_listado">Transparencias</h2>
<p><object id="doc_279240292463082" name="doc_279240292463082" height="500" width="450" type="application/x-shockwave-flash" data="http://d1.scribdassets.com/ScribdViewer.swf" style="outline:none;" ><param name="movie" value="http://d1.scribdassets.com/ScribdViewer.swf"><param name="wmode" value="opaque"><param name="bgcolor" value="#ffffff"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="FlashVars" value="document_id=16935754&#038;access_key=key-h60i26pn2sxg7fkp8c8&#038;page=1&#038;viewMode=slideshow"></object></p>
<h2>Enlaces</h2>
<ul class="padding">
<li><a href="http://code.google.com/apis/ajax/playground/">Ajax Playground</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.polargeek.net/ejecutar-codigo-javascript-online-con-google/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Controlar vídeos de Youtube con Javascript</title>
		<link>http://www.polargeek.net/controlar-videos-de-youtube-con-javascript/</link>
		<comments>http://www.polargeek.net/controlar-videos-de-youtube-con-javascript/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 07:10:22 +0000</pubDate>
		<dc:creator>José</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.polargeek.net/?p=1095</guid>
		<description><![CDATA[Introducción Tras un tiempo trasteando con API&#8217;s llegó el momento de trabajar con la del reproductor de Youtube, y lo cierto es que su uso es bastante sencillo. En este post veremos una serie de funciones más o menos avanzadas, que nos permitirán controlar casi todos los aspectos del reproductor de Youtube. Primeros pasos En [...]]]></description>
			<content:encoded><![CDATA[<h2>Introducción</h2>
<p>Tras un tiempo trasteando con API&#8217;s llegó el momento de trabajar con la del reproductor de  Youtube, y lo cierto es que su uso es bastante sencillo.</p>
<p><img src="http://static.polargeek.net/uploads/2010/01/3341867340_478f9b8c49_m.jpg" alt="" title="Youtube logo" width="240" height="170" class="aligncenter size-full wp-image-1097" /></p>
<p>En este post veremos una serie de funciones más o menos avanzadas, que nos permitirán controlar casi todos los aspectos del reproductor de Youtube.</p>
<h2>Primeros pasos</h2>
<p>En primer lugar, necesitamos <i>swfobject</i>, un proyecto de código abierto, que permite integrar un archivo swf (de Flash) en nuestra página con un pequeño archivo Javascript. </p>
<p>Así que nos lo <a href="http://code.google.com/p/swfobject/">descargamos</a> y subimos el archivo js a nuestro servidor. </p>
<p>Además, para poder utilizar la API de Youtube, en la url del vídeo que queramos insertar, tenemos que añadir el parámetro <i>enablejsapi=1</i> y <i>playerapiid=ytplayer</i></p>
<p>Viendo un ejemplo, integremos un vídeo para permitir el uso de funciones (<i>VIDEO_ID</i> es la id del vídeo lógicamente)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;swfobject.js&quot;&gt;&lt;/script&gt;    
 &lt;div id=&quot;ytapiplayer&quot;&gt;
   Se necesita una versión de Flash Player superior a 8 
	y Javascript, para ver este video.
 &lt;/div&gt;
&nbsp;
 <span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
   <span style="color: #003366; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> allowScriptAccess<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;always&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> atts <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> id<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;myytplayer&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
   swfobject.<span style="color: #660066;">embedSWF</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;http://www.youtube.com/v/&lt;strong&gt;VIDEO_ID&lt;/strong&gt;&amp;enablejsapi=1&amp;playerapiid=ytplayer&quot;</span><span style="color: #339933;">,</span> 
                      <span style="color: #3366CC;">&quot;ytapiplayer&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;425&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;356&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;8&quot;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> params<span style="color: #339933;">,</span> atts<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>La función <i>swfobject.embedSWF</i> viene, como ya supondrás, del archivo swfobject.js, que hemos descargado previamente, (al final tienes enlaces a la documentación).</p>
<p>Bien, una vez que tenemos el reproductor integrado, necesitamos obtener el objeto que representa el reproductor para poder hacer llamadas, la función <i>onYouTubePlayerReady</i> se ejecutará cuando el reproductor está completamente cargado y la API está lista para recibir llamadas.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"> <span style="color: #003366; font-weight: bold;">function</span> onYouTubePlayerReady<span style="color: #009900;">&#40;</span>playerId<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      ytplayer <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;myytplayer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Funciones básicas</h2>
<p>Ahora que tenemos nuestro objeto <i>ytplayer</i> podemos llamar a las funciones. Por ejemplo, si queremos tener un enlace que reproduzca el vídeo simplemente añadimos</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"> <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript:ytplayer.playVideo()&quot;</span><span style="color: #339933;">&gt;</span>Reproducir<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>O para pausar el reproductor&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"> <span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript:ytplayer.pauseVideo()&quot;</span><span style="color: #339933;">&gt;</span>Pausar<span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Hay <a href="http://code.google.com/intl/es/apis/youtube/js_api_reference.html#Functions">muchas funciones</a>, estas dos son solo un ejemplo.</p>
<h2>Ejemplo práctico y documentación</h2>
<p>Hay un ejemplo en <a href="http://code.google.com/intl/es/apis/youtube/js_example_1.html">esta página</a> en la que podemos ver más funciones aplicadas. Si observamos el código usa la famosa Google AJAX Libraries API que básicamente lo que hace es cargar las librerías más usadas, como jQuery o Mootools y además permite cargar otras. En este caso&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;!--</span> <span style="color: #003366; font-weight: bold;">Use</span> the Google AJAX Libraries API<span style="color: #339933;">:</span> 
	 http<span style="color: #339933;">:</span><span style="color: #006600; font-style: italic;">//code.google.com/apis/ajaxlibs/ --&gt; </span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://www.google.com/jsapi&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span> 
<span style="color: #339933;">&lt;</span>script<span style="color: #339933;">&gt;</span> 
	google.<span style="color: #660066;">load</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;swfobject&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;2.1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Carga la de swfobject con la función <i>google.load(librería,versión)</i>.</p>
<h2>Conclusión</h2>
<p>Bien, eso es todo, aquí dejo unos enlaces de documentación y para cualquier duda comenta.</p>
<ul>
<li><a href="http://code.google.com/intl/es/apis/youtube/js_api_reference.html">Documentación de la API de Youtube</a> (en español)</li>
<li><a href="http://www.mediavilla.name/index.php/jr/post/swfobject_2/es">Documentación de swfobject 2</a> (en español)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.polargeek.net/controlar-videos-de-youtube-con-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recibir varios datos por Ajax con Javascript</title>
		<link>http://www.polargeek.net/javascript-recibir-varios-datos-por-ajax-post/</link>
		<comments>http://www.polargeek.net/javascript-recibir-varios-datos-por-ajax-post/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 23:01:48 +0000</pubDate>
		<dc:creator>José</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.polargeek.net/?p=989</guid>
		<description><![CDATA[Introducción Cuando se trata de recibir varios datos tras hacer una petición Ajax, surge un problema, solo se puede recibir una cadena de texto, y ya está, esto se debe a la naturaleza de Ajax, pero a eso dedicaré otro post más adelante. Con el método GET, existe una función (jQuery.getJSON), pero este método no [...]]]></description>
			<content:encoded><![CDATA[<h2>Introducción</h2>
<p><a href="http://www.flickr.com/photos/codydildy/1031912100/"><img src="http://static.polargeek.net/uploads/datos-con-ajax.jpg" alt="Golden Gate" /></a><br />
Cuando se trata de recibir varios datos tras hacer una petición Ajax, surge un problema, solo se puede recibir una cadena de texto, y ya está, esto se debe a la naturaleza de Ajax, pero a eso dedicaré otro post más adelante.</p>
<p>Con el método GET, existe una función (<em>jQuery.getJSON</em>), pero este método no es el más elegante a mi entender en muchos proyectos. (El artículo POST vs. GET está en proceso de fabricación&#8230;).</p>
<p>Así que necesitamos alguna manera de pasar X datos desde un script a una función javascript que nos ha hecho la petición Ajax.</p>
<h2>JSON</h2>
<p>Bueno amigos, JSON es nuestro aliado en este caso. JSON es simplemente una manera de juntar datos en forma de string, con un estándar, claro.</p>
<p>¿Y cuál es el punto fuerte de esto? Pues que al ser estándar en muchos lenguajes existen funciones que nos facilitan la vida (PHP, Javascript, Python, Perl&#8230;). </p>
<p>Veremos un ejemplo con PHP, aunque en realidad no importa el lenguaje, la idea se puede extrapolar con scripts de otros lenguajes siempre y cuando implementen funciones de JSON.</p>
<h2>Caso práctico</h2>
<p>En un script de PHP (<em>prueba.php</em>) tenemos el siguiente código:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
 <span style="color: #000088;">$array_datos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;direccion&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Calle Inventada&quot;</span><span style="color: #339933;">,</span>
                       <span style="color: #0000ff;">&quot;ciudad&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Hong Kong&quot;</span>
                     <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000088;">$array_datos_json</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array_datos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Lo codificamos en JSON</span>
 <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$array_datos_json</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Bien, tenemos la siguiente petición por Ajax, con el método POST al script anterior.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;prueba.php&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;func&quot;</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;conseguirDireccionCiudad&quot;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
  <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">direccion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Dato 1</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>data.<span style="color: #660066;">ciudad</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Dato 2</span>
  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Como se puede ver se decodifica directamente con la función $.post(), que permite especificar el tipo de dato que vamos a obtener en el 4º parámetro. </p>
<h2>Documentación</h2>
<p>Jquery + Ajax | <a href="http://docs.jquery.com/Ajax">Jquery.com</a><br />
JSON | <a href="http://www.json.org/json-es.html">Documentación oficial</a><br />
JSON | <a href="http://es.wikipedia.org/wiki/JSON">Documentación útil</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.polargeek.net/javascript-recibir-varios-datos-por-ajax-post/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>[Javascript] Gráficas sin flash ni imágenes</title>
		<link>http://www.polargeek.net/javascript-graficas-sin-flash-ni-imagenes/</link>
		<comments>http://www.polargeek.net/javascript-graficas-sin-flash-ni-imagenes/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 20:51:20 +0000</pubDate>
		<dc:creator>José</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[graficas]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.polargeek.net/?p=920</guid>
		<description><![CDATA[Introducción Las gráficas en el desarrollo web son un mundo, existe multitud de formas de realizarla, pero a mi entender la más elegante es con Javascript. Y como usar código ya hecho si nos sirve siempre es una ventaja veremos dos casos prácticos. HighCharts Uso 1 2 3 4 5 6 7 8 9 10 [...]]]></description>
			<content:encoded><![CDATA[<h2 style="text-align: left;">Introducción</h2>
<p style="text-align: left;">Las gráficas en el desarrollo web son un mundo, existe multitud de formas de realizarla, pero a mi entender la más elegante es con Javascript. Y como usar código ya hecho si nos sirve siempre es una ventaja veremos dos casos prácticos.</p>
<h2 style="text-align: left;">HighCharts</h2>
<p style="text-align: center;">
<img src="http://static.polargeek.net/uploads/2009/12/highcharts.png" alt="highcharts" title="highcharts" width="515" height="84" class="aligncenter size-full wp-image-928" /></p>
<h3>Uso</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Incluimos lo que nos descargamos + Jquery</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;jquery.min.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;highcharts.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;excanvas.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> chart1 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Highcharts.<span style="color: #660066;">Chart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		chart<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
			renderTo<span style="color: #339933;">:</span> <span style="color: #3366CC;">'chart-container-1'</span><span style="color: #339933;">,</span>
			defaultSeriesType<span style="color: #339933;">:</span> <span style="color: #3366CC;">'bar'</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		title<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>   <span style="color: #006600; font-style: italic;">//Título de la gráfica</span>
			text<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Fruit Consumption'</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		xAxis<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//Categorías en el eje de las x</span>
			categories<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'Apples'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Bananas'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Oranges'</span><span style="color: #009900;">&#93;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		yAxis<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//Título del eje de las ys</span>
			title<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
  				text<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Fruit eaten'</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		series<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//Aquí especificamos los datos</span>
			<span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'Jane'</span><span style="color: #339933;">,</span>
			data<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">4</span><span style="color: #009900;">&#93;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">name</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'John'</span><span style="color: #339933;">,</span>
			data<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">5</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">7</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #009900;">&#93;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Descarga</h3>
<p><a href="http://www.highcharts.com/download">Pincha aquí para descargar</a></p>
<h2>Emprise JavaScript Charts</h2>
<p><img src="http://static.polargeek.net/uploads/headerbg.jpg" alt="ejschart" title="ejschart" class="aligncenter size-full wp-image-941" /></p>
<h3>Uso</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #003366; font-weight: bold;">var</span> myChart6 <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> EJSC.<span style="color: #660066;">Chart</span><span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'myChart1a'</span> <span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">// TItulo de la gráfica</span>
	title<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Sample Function Chart&quot;</span> <span style="color: #339933;">,</span>   
	<span style="color: #006600; font-style: italic;">// Para ver ambos ejes</span>
	axis_bottom<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>         
		caption<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;X Value&quot;</span> <span style="color: #339933;">,</span>
		zero_plane<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> show<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> color<span style="color: #339933;">:</span> <span style="color: #3366CC;">'rgb(0,0,0)'</span> <span style="color: #339933;">,</span> thickness<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span> <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #339933;">,</span>
		axis_left<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
			caption<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Y Value&quot;</span> <span style="color: #339933;">,</span>
			zero_plane<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span> show<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> color<span style="color: #339933;">:</span> <span style="color: #3366CC;">'rgb(0,0,0)'</span> <span style="color: #339933;">,</span> thickness<span style="color: #339933;">:</span> <span style="color: #CC0000;">1</span> <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">// Aqui añadimos funciones para dibujarlas</span>
	myChart6.<span style="color: #660066;">addSeries</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> EJSC.<span style="color: #660066;">FunctionSeries</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #339933;">,</span> 
	<span style="color: #009900;">&#123;</span> title<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Function x^2&quot;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	myChart6.<span style="color: #660066;">addSeries</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> EJSC.<span style="color: #660066;">FunctionSeries</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> Math.<span style="color: #660066;">pow</span><span style="color: #009900;">&#40;</span>x<span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #339933;">,</span>
	<span style="color: #009900;">&#123;</span> title<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Function x^3&quot;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	myChart6.<span style="color: #660066;">addSeries</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">new</span> EJSC.<span style="color: #660066;">FunctionSeries</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>x<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000066; font-weight: bold;">return</span> x<span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #339933;">,</span>
	<span style="color: #009900;">&#123;</span> title<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;Function x&quot;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>            
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h3>Descarga</h3>
<p><a href="http://www.ejschart.com/pricing.php">Pincha aquí para descargar</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.polargeek.net/javascript-graficas-sin-flash-ni-imagenes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
