<?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>iuttu &#187; javascript</title> <atom:link href="http://www.iuttu.com/category/javascript/feed/" rel="self" type="application/rss+xml" /><link>http://www.iuttu.com</link> <description>Desarrollo web</description> <lastBuildDate>Mon, 23 Jan 2012 16:52:04 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Script de calendario de Aeron Glemann compatible con IE9</title><link>http://www.iuttu.com/2011/11/script-de-calendario-de-aeron-glemann-compatible-con-ie9/</link> <comments>http://www.iuttu.com/2011/11/script-de-calendario-de-aeron-glemann-compatible-con-ie9/#comments</comments> <pubDate>Sun, 06 Nov 2011 16:02:44 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[javascript]]></category> <guid
isPermaLink="false">http://www.iuttu.com/?p=841</guid> <description><![CDATA[Después de mucho tiempo de utilizar el fantástico script de calendario creado por Aeron Glemann (que funciona con Mootools), ha llegado Internet Explorer 9 y la revisión de una web en el mismo&#8230; y al comprobar el funcionamento de la misma, vemos que el javascript nos tira un error: SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5). Al parecer, [...]]]></description> <content:encoded><![CDATA[<p>Después de mucho tiempo de utilizar el fantástico script de calendario creado por <a
href="http://electricprism.com/aeron/" target="_blank">Aeron Glemann</a> (que funciona con Mootools), ha llegado Internet Explorer 9 y la revisión de una web en el mismo&#8230; y al comprobar el funcionamento de la misma, vemos que el javascript nos tira un error: <strong>SCRIPT5022: DOM Exception: INVALID_CHARACTER_ERR (5). </strong>Al parecer, IE9, cumple demasiado extrictamente los estandards, y al parecer mootools (versión 1.2.4) utiliza una forma de crear elementos que no gusta a IE9, por lo que lo único que tenemos que hacer es transformar las creaciones de elementos como esta:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #003366; font-weight: bold;">var</span> test <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Element<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;text&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>a la forma más lenta:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">  <span style="color: #003366; font-weight: bold;">var</span> test <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Element<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  test.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;id&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;text&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>y ya funcionará&#8230;</p><p>Podéis descargaros el código de <a
href="http://snipplr.com/view/60588/aeron-glemamn-calendarjs-fixed-for-ie9-vs-mootools-124/" target="_blank">aquí</a></p> ]]></content:encoded> <wfw:commentRss>http://www.iuttu.com/2011/11/script-de-calendario-de-aeron-glemann-compatible-con-ie9/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Centrado de una imagen de fondo que ocupa todo el ancho y alto</title><link>http://www.iuttu.com/2011/04/centrado-de-una-imagen-de-fondo-que-ocupa-todo-el-ancho-y-alto/</link> <comments>http://www.iuttu.com/2011/04/centrado-de-una-imagen-de-fondo-que-ocupa-todo-el-ancho-y-alto/#comments</comments> <pubDate>Sun, 03 Apr 2011 19:02:28 +0000</pubDate> <dc:creator>admin</dc:creator> <category><![CDATA[javascript]]></category> <category><![CDATA[maquetación]]></category> <category><![CDATA[Programación]]></category> <guid
isPermaLink="false">http://www.iuttu.com/?p=602</guid> <description><![CDATA[Para más de un proyecto hemos necesitado colocar una imagen de fondo (habitualmente administrable), que ocupase todo el espacio del navegador -sea cual fuere el ratio de ancho y alto del mismo-, por lo que compartimos con todos el código necesario para hacerlo (para el ejemplo hemos utilizado mootools 1.3. El html: &#60;div id=&#34;fondo_pagina&#34;&#62;&#60;img id=&#34;imagen_fondo_pagina&#34; [...]]]></description> <content:encoded><![CDATA[<p>Para más de un proyecto hemos necesitado colocar una imagen de fondo (habitualmente administrable), que ocupase todo el espacio del navegador -sea cual fuere el ratio de ancho y alto del mismo-, por lo que compartimos con todos el código necesario para hacerlo (para el ejemplo hemos utilizado mootools 1.3.</p><p>El html:</p><div
class="wp_syntax"><div
class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fondo_pagina&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;imagen_fondo_pagina&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Imagen ejemplo&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;foto.jpg&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Imagen ejemplo&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div><p>Nada que comentar, una capa al primer nivel del <strong>body</strong> y la imagen dentro, ambos con el <strong>id</strong> informado para poder hacer referencia desde el <strong>javascript</strong>.</p><p>El CSS:</p><div
class="wp_syntax"><div
class="code"><pre class="css" style="font-family:monospace;">body<span style="color: #00AA00;">,</span>html <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>margin<span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#fondo_pagina</span> img <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">fixed</span><span style="color: #00AA00;">;</span>top<span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>left<span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>bottom<span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>right<span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>z-index<span style="color: #00AA00;">:</span>-<span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>overflow<span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></div><p>Posicionamos la imagen con el tipo fixed en la posición inicial arriba a la izquierda ocupando el máximo del navegador. Finalmente vemos el código javascript que será el mayor responsable de todo:</p><div
class="wp_syntax"><div
class="code"><pre class="javascript" style="font-family:monospace;">window.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'load'</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>
	window.<span style="color: #660066;">fireEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'resize'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
window.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'resize'</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: #003366; font-weight: bold;">var</span> espacio_navegador_vertical <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">body</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">y</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> espacio_navegador_horizontal <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>document.<span style="color: #660066;">body</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">x</span>
	<span style="color: #003366; font-weight: bold;">var</span> anchura_imagen <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;imagen_fondo_pagina&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">x</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> altura_imagen <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;imagen_fondo_pagina&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">y</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Resize de foto de fondo y/o cambio de aspect ratio</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>espacio_navegador_horizontal <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> anchura_imagen<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;imagen_fondo_pagina&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setStyles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'width'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'100%'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'height'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'auto'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'left'</span><span style="color: #339933;">:</span><span style="color: #CC0000;">0</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>espacio_navegador_vertical <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> altura_imagen<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;imagen_fondo_pagina&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setStyles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'width'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'auto'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'height'</span> <span style="color: #339933;">:</span> <span style="color: #3366CC;">'100%'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'top'</span><span style="color: #339933;">:</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Refrescamos los tamaños de la imagen</span>
	anchura_imagen <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;imagen_fondo_pagina&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">x</span><span style="color: #339933;">;</span>
	altura_imagen <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;imagen_fondo_pagina&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">y</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Centrado de imagen vertical</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;imagen_fondo_pagina&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'top'</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>altura_imagen<span style="color: #339933;">-</span>espacio_navegador_vertical<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Centrado de imagen horizontal</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;imagen_fondo_pagina&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'left'</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>anchura_imagen<span style="color: #339933;">-</span>espacio_navegador_horizontal<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</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></div></div><p>Hemos incluido todo el código al controlar el evento de redimensionado de la pàgina, para cambiar el ratio de la imagen de fondo cuando el usuario redimensione el navegador. Para ser llamado al cargar la página, sólo tenemos que disparar el evento de redimensionado para que se se procese todo.</p><p>El funcionamiento del algoritmo es sencillo, primero comprobamos si el ancho de la pantalla es mayor que el ancho de la imagen. Si es así, redimensionamos la imagen para que sea tan ancha como la pantalla. Entonces pueden pasar dos cosas: que la imagen sea suficientemente alta para cubrir todo el alto del navegador o que no lo sea. Si no lo es, entonces ajustamos la imagen a la máxima altura del navegador (el ancho nos lo cubrirá seguro).</p><p>Después, lo único que nos queda por hacer es centrar la imagen en el navegador para que siempre se vea la parte central de la misma y no la parte superior izquierda.</p><p>Os podéis <a
href="http://www.iuttu.com/wp-content/uploads/2011/04/ejemplo_fondo.zip">descargar el ejemplo aquí</a></p> ]]></content:encoded> <wfw:commentRss>http://www.iuttu.com/2011/04/centrado-de-una-imagen-de-fondo-que-ocupa-todo-el-ancho-y-alto/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Limitar la longitud de un texto a un determinado número de líneas</title><link>http://www.iuttu.com/2009/06/limitar-longitud-de-texto-determinado-numero-lineas/</link> <comments>http://www.iuttu.com/2009/06/limitar-longitud-de-texto-determinado-numero-lineas/#comments</comments> <pubDate>Sun, 28 Jun 2009 12:29:50 +0000</pubDate> <dc:creator>iuttu</dc:creator> <category><![CDATA[javascript]]></category> <category><![CDATA[maquetación]]></category> <category><![CDATA[Programación]]></category> <guid
isPermaLink="false">http://blog.iuttu.com/?p=194</guid> <description><![CDATA[En ocasiones, nos podemos encontrar que un determinado diseño nos obliga a limitar el número de líneas que puede tener un texto. Esto es imposible de realizar del lado del servidor, con lo que hemos hecho un pequeño javascript que recorta el texto del elemento deseado en las líneas que queramos. El javascript es el [...]]]></description> <content:encoded><![CDATA[<p>En ocasiones, nos podemos encontrar que un determinado diseño nos obliga a limitar el número de líneas que puede tener un texto. Esto es imposible de realizar del lado del servidor, con lo que hemos hecho un pequeño javascript que recorta el texto del elemento deseado en las líneas que queramos. El javascript es el siguiente:</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
30
31
32
33
34
35
36
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;">$$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.maxlines&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #990000;">each</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">var</span> numLines <span style="color: #339933;">=</span> element<span style="color: #339933;">.</span>getProperty<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rel&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>substring<span style="color: #009900;">&#40;</span>element<span style="color: #339933;">.</span>getProperty<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rel&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>indexOf<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'['</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>element<span style="color: #339933;">.</span>getProperty<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;rel&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>indexOf<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">']'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">var</span> htmlCode <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// determinamos altura una linea</span>
    $<span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'-'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> oneLineHeight <span style="color: #339933;">=</span> element<span style="color: #339933;">.</span>getStyle<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>toInt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    element<span style="color: #339933;">.</span>set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html'</span><span style="color: #339933;">,</span> htmlCode<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Si tenemos más lineas que las permitidas</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>element<span style="color: #339933;">.</span>getStyle<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>toInt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> oneLineHeight <span style="color: #339933;">&gt;</span> numLines<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        point1 <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        point2 <span style="color: #339933;">=</span> Math<span style="color: #339933;">.</span><span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span>htmlCode<span style="color: #339933;">.</span>length<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        point3 <span style="color: #339933;">=</span> htmlCode<span style="color: #339933;">.</span>length<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Recortamos texto hasta que coja</span>
        <span style="color: #b1b100;">do</span><span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">var</span> newHtml <span style="color: #339933;">=</span> htmlCode<span style="color: #339933;">.</span>substring<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> point2<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">'...'</span><span style="color: #339933;">;</span>
            element<span style="color: #339933;">.</span>set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html'</span><span style="color: #339933;">,</span> newHtml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">.</span>getStyle<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>toInt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>oneLineHeight <span style="color: #339933;">&gt;</span> numLines<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                point3 <span style="color: #339933;">=</span> point2<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
                point1 <span style="color: #339933;">=</span> point2<span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            point2 <span style="color: #339933;">=</span> Math<span style="color: #339933;">.</span><span style="color: #990000;">round</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>point3<span style="color: #339933;">-</span>point1<span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span>point1<span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>point3<span style="color: #339933;">-</span>point1<span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>element<span style="color: #339933;">.</span>getStyle<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'height'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>toInt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">/</span>oneLineHeight <span style="color: #339933;">&gt;</span> numLines<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            element<span style="color: #339933;">.</span>set<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html'</span><span style="color: #339933;">,</span> htmlCode<span style="color: #339933;">.</span>substring<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> point3<span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">'...'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <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>y en el html lo debemos usar así:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
</pre></td><td
class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;maxlines&quot;</span>&gt;</span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div><p>la capa del texto debe incluir el class=&#8221;maxlines&#8221; y la propiedad rel=&#8221;maxLines[]&#8221; donde la cifra entre corchetes es el número de líneas que se tienen que mostrar.</p><p>El funcionamiento básico del script es el siguiente:</p><ul><li>Coloca en la capa un sólo carácter.</li><li>Calcula la altura de esta capa.</li><li>Usando el <a
href="http://es.wikipedia.org/wiki/Algoritmo_divide_y_vencer%C3%A1s">algoritmo de divide y vencerás</a> vamos reduciendo a mitades la cadena para encontrar rápidamente por donde partir el texto.</li></ul><p>y listos&#8230; se acaba de maquetar añadiendo puntos suspensivos y listos.</p><p>Todo esto funciona conjuntamente con la versión 1.2.2 de <a
title="Mootools" href="http://mootools.net/">Mootools</a></p> ]]></content:encoded> <wfw:commentRss>http://www.iuttu.com/2009/06/limitar-longitud-de-texto-determinado-numero-lineas/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>De Mootools a jQuery: comprobar si un elemento existe</title><link>http://www.iuttu.com/2009/03/de-mootools-a-jquery-comprobar-si-un-elemento-existe/</link> <comments>http://www.iuttu.com/2009/03/de-mootools-a-jquery-comprobar-si-un-elemento-existe/#comments</comments> <pubDate>Sun, 15 Mar 2009 11:26:01 +0000</pubDate> <dc:creator>iuttu</dc:creator> <category><![CDATA[javascript]]></category> <category><![CDATA[Programación]]></category> <category><![CDATA[dojo]]></category> <category><![CDATA[frameworks]]></category> <category><![CDATA[jquery]]></category> <category><![CDATA[mootools]]></category> <guid
isPermaLink="false">http://blog.iuttu.com/?p=190</guid> <description><![CDATA[Para los que estamos acostumbrados a mootools, nos es habitual comprobar si un elemento (tag html con id) existe antes de lanzar los scripts, siempre lo hacemos de la misma manera: 1 if &#40;$&#40;&#34;elemento&#34;&#41;&#41; &#123; alert&#40;&#34;adelaaaaaaaanteee&#34;&#41;; &#125; Pero si pasamos a jQuery, vemos que si lo hacemos así, la expresión siempre devolverá cierto. Ya que [...]]]></description> <content:encoded><![CDATA[<p>Para los que estamos acostumbrados a <a
href="http://www.mootools.net">mootools</a>, nos es habitual comprobar si un elemento (tag html con id) existe antes de lanzar los scripts, siempre lo hacemos de la misma manera:</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;elemento&quot;</span><span style="color: #009900;">&#41;</span><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;">&quot;adelaaaaaaaanteee&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>Pero si pasamos a <a
href="http://jquery.com">jQuery</a>, vemos que si lo hacemos así, la expresión siempre devolverá <strong>cierto</strong>. Ya que la función $(&#8220;&#8221;) en <a
href="http://jquery.com">jQuery</a> siempre devuelve un array de elementos. Sabiendo esto, lo que tenemos que comprobar para saber si un elemento existe, es comprobar la longitud del array que  nos devuelve:</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;elemento&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span><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;">&quot;adelaaaaaanteee&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p>Ya puestos, en <a
href="http://www.dojotoolkit.org/">dojo</a> tendríamos que hacer esto:</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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>dojo.<span style="color: #660066;">byId</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'elemento'</span><span style="color: #009900;">&#41;</span><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;">&quot;adelaaaaaanteee&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div> ]]></content:encoded> <wfw:commentRss>http://www.iuttu.com/2009/03/de-mootools-a-jquery-comprobar-si-un-elemento-existe/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Uso de contextos en Zend Framework</title><link>http://www.iuttu.com/2009/01/contextos-ajax-zend-framework/</link> <comments>http://www.iuttu.com/2009/01/contextos-ajax-zend-framework/#comments</comments> <pubDate>Tue, 20 Jan 2009 13:18:49 +0000</pubDate> <dc:creator>iuttu</dc:creator> <category><![CDATA[javascript]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Programación]]></category> <category><![CDATA[ajax]]></category> <category><![CDATA[php]]></category> <category><![CDATA[zend framework]]></category> <guid
isPermaLink="false">http://blog.iuttu.com/?p=135</guid> <description><![CDATA[En un proyecto web, habitualmente hacemos llamadas al mismo código pero necesitamos que los resultados se muestren de forma diferente. Zend Framework ofrece varios mecanismos para facilitar esta tarea. Uno de ellos son las vistas parciales (PartialView) que permiten separar una parte de la presentación y aislarlas del contexto. Esto nos permite reutilizar una porción [...]]]></description> <content:encoded><![CDATA[<p>En un proyecto web, habitualmente hacemos llamadas al mismo código pero necesitamos que los resultados se muestren de forma diferente. Zend Framework ofrece varios mecanismos para facilitar esta tarea.</p><p>Uno de ellos son las vistas parciales (<em>PartialView</em>) que permiten separar una parte de la presentación y aislarlas del contexto. Esto nos permite reutilizar una porción de html y definir un contexto concreto para cada llamada.</p><p>El contexto es otro mecanismo que también nos permite ejecutar un código discriminando la salida. El siguiente ejemplo utiliza <em>AjaxContext</em>, un helper que hereda de <em>ContextSwitch</em> y que se especializa en llamadas Ajax.</p><p>Para empezar, tendremos que inicializar el contexto:</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
</pre></td><td
class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> ControladorController <span style="color: #000000; font-weight: bold;">extends</span> Zeb_Controller_Action<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$ajaxContext</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> _helper <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">getHelper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AjaxContext'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$ajaxContext</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">addActionContext</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'index'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'html'</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">initContext</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    parent<span style="color: #339933;">::</span><span style="color: #004000;">init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #339933;">...</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div><p><em>addActionContext()</em> nos permite añadir un nuevo contexto a un action (en este caso <em>index</em>). El primer parámetro es el nombre del action y el segundo el tipo de contexto. <em>initContext()</em> inicializa el contexto.</p><p>Sólo con estas lineas ya habremos definido e inicializado un nuevo contexto. Toda las llamadas al action <em>index</em> se trataran de la forma habitual, excepto aquellas que cambien de contexto. ¿Y cómo cambiamos de contexto? El siguiente ejemplo de código JavaScript utiliza Mootools para realizar una llamada Ajax activando el contexto:</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: #003366; font-weight: bold;">var</span> myRequest <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Request.<span style="color: #660066;">HTML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  url <span style="color: #339933;">:</span> requestUrl<span style="color: #339933;">,</span>
  update <span style="color: #339933;">:</span> <span style="color: #3366CC;">'content-div'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #3366CC;">'format'</span><span style="color: #339933;">:</span><span style="color: #3366CC;">'html'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...</pre></td></tr></table></div><p>Donde <em>requestUrl</em> será la url de nuestro action (Controlador &#8211; index) y <em>content-div</em> la capa que se actualizará con el resultado de la llamada. El parámetro <em>format</em> es el que activará el cambio de contexto en nuestro action.</p><p>Al realizar esta llamada nuestro action ejecutará el código e irá a buscar una view con el formato de nombre <em>/[controlador]/[action].ajax.phtml</em> en lugar del habitual <em>/[controlador]/[action].phtml. Además desactivará los layouts por defecto, siendo la situación ideal para una llamada de este tipo.</p><p>Ya está todo preparado. A partir de ahora las llamadas a /controlador/index se gestionarán como siempre, pero cuando realicemos una llamada desde Ajax podremos mostrar sólo una vista parcial. Esta solución es perfecta para mostrar una ficha: al realizar la llamada /controlador/index mostramos la ficha con cabecera, menú, pie, etc.. y al llamar por Ajax cambiamos de vista y sólo mostramos el contenido del elemento para incluirlo en otra vista.</p><p>Unas consideraciones finales:</p><ul><li><em>AjaxContext</em> añade un tercer contexto <em>html</em> a los dos (<em>json</em> y <em>xml</em>) ofrecidos por <em>ContextSwitch</em>, aunque podemos crear nuestros propios contextos.</li><li>Una llamada con el parámetro <em>format</em> no cambiará al contexto <em>AjaxContext</em> si no se ha realizado mediante XmlHttpRequest (que es lo que nos interesa)</li><li>Zend proporciona una serie de métodos para afinar nuestro código y que nos permitirán añadir headers, serializar respuestas Json, activar layouts, etc&#8230; en función del contexto</li></ul> ]]></content:encoded> <wfw:commentRss>http://www.iuttu.com/2009/01/contextos-ajax-zend-framework/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Reproductor mp3 controlado con javascript</title><link>http://www.iuttu.com/2008/12/reproductor-mp3-controlado-con-javascript/</link> <comments>http://www.iuttu.com/2008/12/reproductor-mp3-controlado-con-javascript/#comments</comments> <pubDate>Thu, 18 Dec 2008 08:21:33 +0000</pubDate> <dc:creator>iuttu</dc:creator> <category><![CDATA[actionscript]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[Programación]]></category> <guid
isPermaLink="false">http://blog.iuttu.com/?p=102</guid> <description><![CDATA[Para un proyecto reciente tenía la necesidad de reproducir archivos mp3 desde un listado de canciones. La red está llena de javascripts en flash para reproducir mp3s externos, pero no llegué a encontrar alguno que además de poder cargar mp3s te diese la posibilidad de pausar las canciones. Partimos de la página html: 1 2 [...]]]></description> <content:encoded><![CDATA[<p>Para un proyecto reciente tenía la necesidad de reproducir archivos mp3 desde un listado de canciones. La red está llena de javascripts en flash para reproducir mp3s externos, pero no llegué a encontrar alguno que además de poder cargar mp3s te diese la posibilidad de pausar las canciones.</p><p><span
id="more-102"></span></p><p>Partimos de la página html:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td
class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span> xml:<span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;es-ES&quot;</span> <span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;es-ES&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- nuestro flash reproductor de mp3 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;flash&quot;</span></span>
<span style="color: #009900;">	&lt;<span style="color: #000000; font-weight: bold;">object</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span> <span style="color: #000066;">data</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;audio.swf&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;audio&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;allowScriptAccess&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;all&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;movie&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;audio.swf&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">object</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div><p>vemos el ActionScript del flash:</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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td
class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">external</span>.<span style="color: #006600;">ExternalInterface</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// allowscriptaccess = samedomain</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> my_sound:<span style="color: #0066CC;">Sound</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Sound</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> soundStatus = <span style="color: #cc66cc;">0</span>;
<span style="color: #000000; font-weight: bold;">var</span> soundStarted = <span style="color: #000000; font-weight: bold;">false</span>;
<span style="color: #000000; font-weight: bold;">var</span> currentPosition = <span style="color: #cc66cc;">0</span>;
<span style="color: #000000; font-weight: bold;">var</span> currentPlay;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> playSound<span style="color: #66cc66;">&#40;</span>param<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	currentPlay = param;
&nbsp;
	my_sound = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Sound</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	my_sound.<span style="color: #0066CC;">loadSound</span><span style="color: #66cc66;">&#40;</span>param, <span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">&#41;</span>;
	my_sound.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	soundStatus = <span style="color: #cc66cc;">1</span>;
	soundStarted = <span style="color: #000000; font-weight: bold;">true</span>;
	currentPosition = my_sound.<span style="color: #0066CC;">position</span>;
&nbsp;
	my_sound.<span style="color: #0066CC;">onSoundComplete</span> = <span style="color: #000000; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		soundStatus = <span style="color: #cc66cc;">0</span>;
&nbsp;
		currentPosition = <span style="color: #cc66cc;">0</span>;
		<span style="color: #808080; font-style: italic;">// Avisamos a la página</span>
		soundStarted = <span style="color: #000000; font-weight: bold;">false</span>;
		<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> togglePause<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>soundStatus == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> <span style="color: #808080; font-style: italic;">// Lo pausamos</span>
		currentPosition = my_sound.<span style="color: #0066CC;">position</span>;
		my_sound.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		soundStatus = <span style="color: #cc66cc;">0</span>;
		<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>soundStarted<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
			my_sound.<span style="color: #0066CC;">start</span><span style="color: #66cc66;">&#40;</span>currentPosition<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">1000</span><span style="color: #66cc66;">&#41;</span>;
			soundStatus = <span style="color: #cc66cc;">1</span>;
			<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> stopSound<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>soundStatus == <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		my_sound.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		soundStatus = <span style="color: #cc66cc;">0</span>;
		<span style="color: #0066CC;">this</span>.<span style="color: #0066CC;">stop</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
ExternalInterface.<span style="color: #006600;">addCallback</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;playSound&quot;</span>, <span style="color: #0066CC;">this</span>, playSound<span style="color: #66cc66;">&#41;</span>;
ExternalInterface.<span style="color: #006600;">addCallback</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;togglePause&quot;</span>, <span style="color: #0066CC;">this</span>, togglePause<span style="color: #66cc66;">&#41;</span>;
ExternalInterface.<span style="color: #006600;">addCallback</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;stop&quot;</span>, <span style="color: #0066CC;">this</span>, stopSound<span style="color: #66cc66;">&#41;</span>;</pre></td></tr></table></div><p>Ahora imaginemos que tenemos 3 archivos mp3 llamados &#8220;mp3_1.mp3&#8243;, &#8220;mp3_2.mp3&#8243; y &#8220;mp3_3.mp3&#8243;, vamos a presentar la página html para poder reproducir las 3 canciones:</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
</pre></td><td
class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span> xml:<span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;es-ES&quot;</span> <span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;es-ES&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!-- nuestro flash reproductor de mp3 --&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;flash&quot;</span></span>
<span style="color: #009900;">	&lt;<span style="color: #000000; font-weight: bold;">object</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;application/x-shockwave-flash&quot;</span> <span style="color: #000066;">data</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;audio.swf&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;audio&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;allowScriptAccess&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;all&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">param</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;movie&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;audio.swf&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">object</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:reproduce('mp3_1.mp3')&quot;</span>&gt;</span>Canción 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:reproduce('mp3_2.mp3')&quot;</span>&gt;</span>Canción 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:reproduce('mp3_3.mp3')&quot;</span>&gt;</span>Canción 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div><p>tendríamos que añadir la función javascript que llame al flash:</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>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;">function</span> reproduce<span style="color: #009900;">&#40;</span>_cual<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;audio&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">playSound</span><span style="color: #009900;">&#40;</span>_cual<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div><p>Ahora podríamos añadir los botones de pausa/play y stop:</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="html4strict" style="font-family:monospace;">...
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:reproduce('mp3_1.mp3')&quot;</span>&gt;</span>Canción 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:reproduce('mp3_2.mp3')&quot;</span>&gt;</span>Canción 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:reproduce('mp3_3.mp3')&quot;</span>&gt;</span>Canción 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:play_pause();&quot;</span>&gt;</span>play/pausa<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:stop();&quot;</span>&gt;</span>stop<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div><p>y sus funciones:</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
</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;">function</span> reproduce<span style="color: #009900;">&#40;</span>_cual<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;audio&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">playSound</span><span style="color: #009900;">&#40;</span>_cual<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> play_pause<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;audio&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">togglePause</span><span style="color: #009900;">&#40;</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> <span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;audio&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</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> onSoundComplete<span style="color: #009900;">&#40;</span><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;">&quot;Canción completada!!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div><p>y ya tendremos lo básico (pero más importante) para crearnos un reproductor de mp3 controlado por javascript !!</p><p><a
href="http://blog.iuttu.com/wp-content/uploads/2008/12/audio.zip">Descárgate los archivos del tutorial</a></p> ]]></content:encoded> <wfw:commentRss>http://www.iuttu.com/2008/12/reproductor-mp3-controlado-con-javascript/feed/</wfw:commentRss> <slash:comments>11</slash:comments> </item> <item><title>Cambiar evento onChange de un select con mootools</title><link>http://www.iuttu.com/2008/10/cambiar-evento-onchange-de-un-select-con-mootools/</link> <comments>http://www.iuttu.com/2008/10/cambiar-evento-onchange-de-un-select-con-mootools/#comments</comments> <pubDate>Wed, 08 Oct 2008 19:23:48 +0000</pubDate> <dc:creator>iuttu</dc:creator> <category><![CDATA[javascript]]></category> <category><![CDATA[Programación]]></category> <category><![CDATA[mootools]]></category> <guid
isPermaLink="false">http://blog.iuttu.com/?p=47</guid> <description><![CDATA[En un proyecto reciente, tenímos la necesidad de que, dependiendo de X factores, la función a la que llamase el evento onChange de varios combos Select debía ir cambiando: 1 2 3 4 &#60;select id=&#34;slSelect&#34; onchange=&#34;alert(1)&#34;&#62; &#60;option value=&#34;1&#34;&#62;hola&#60;/option&#62; &#60;option value=&#34;2&#34;&#62;que tal&#60;/option&#62; &#60;/select&#62; En mootools, tenemos varias funciones para eliminar eventos de objetos: $(element).removeEvent() y $(element).removeEvents(), [...]]]></description> <content:encoded><![CDATA[<p>En un proyecto reciente, tenímos la necesidad de que, dependiendo de X factores, la función a la que llamase el evento <strong>onChange</strong> de varios combos <strong>Select</strong> debía ir cambiando:</p><div
class="wp_syntax"><table><tr><td
class="line_numbers"><pre>1
2
3
4
</pre></td><td
class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slSelect&quot;</span> <span style="color: #000066;">onchange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;alert(1)&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>hola<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span>&gt;</span>que tal<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span></pre></td></tr></table></div><p>En mootools, tenemos varias funciones para eliminar eventos de objetos: $(element).<a
href="http://www.mootools.net/docs/Element/Element.Event#Element:removeEvent" target="_blank">removeEvent</a>() y $(element).<a
href="http://www.mootools.net/docs/Element/Element.Event#Element:removeEvents" target="_blank">removeEvents</a>(), pero, misteriosamente, no tienen ningún efecto cuando se aplica a un objeto de tipo <strong>Select</strong>. ¿Y si en vez de un evento, el código <strong>onchange=&#8221;alert(1)&#8221;</strong> fuera interpretado como una propiedad de objeto? Pues efectivamente, la única forma de quitar (para después añadir otro) un evento <strong>onchange</strong> es anulando la propiedad del objeto, en <a
href="http://www.mootools.net" target="_blank">mootools</a> sería así:</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;">&quot;slSelect&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeProperty</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;onchange&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div><p>Probado en FF3, IE6, IE7 y Safari. En la página siguiente os dejo el código del ejemplo&#8230;</p><p><span
id="more-144"></span></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="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>TEST<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mootools.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">charset</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;utf-8&quot;</span>&gt;</span>
function changeOnChange() {
    $(&quot;slSelect&quot;).removeProperty(&quot;onchange&quot;);
}
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slSelect&quot;</span> <span style="color: #000066;">onchange</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;alert(1)&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;1&quot;</span>&gt;</span>hola<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">option</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;2&quot;</span>&gt;</span>que tal<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">option</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">select</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;button&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cambia onchange&quot;</span> <span style="color: #000066;">onclick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;changeOnChange();&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div> ]]></content:encoded> <wfw:commentRss>http://www.iuttu.com/2008/10/cambiar-evento-onchange-de-un-select-con-mootools/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 1/27 queries in 0.028 seconds using disk: basic

Served from: www.iuttu.com @ 2012-02-06 15:08:28 -->
