<?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>Lecciones Prácticas &#187; javascript</title>
	<atom:link href="http://www.leccionespracticas.com/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leccionespracticas.com</link>
	<description>informática y bibliotecas 2.0</description>
	<lastBuildDate>Mon, 06 Feb 2012 13:36:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>jQuery en 10 minutos &#124; guia para impacientes</title>
		<link>http://www.leccionespracticas.com/javascript/jquery-en-10-minutos-guia-para-impacientes/</link>
		<comments>http://www.leccionespracticas.com/javascript/jquery-en-10-minutos-guia-para-impacientes/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 09:38:52 +0000</pubDate>
		<dc:creator>Miguel</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[guia]]></category>
		<category><![CDATA[impacientes]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[resumen]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.leccionespracticas.com/?p=1743</guid>
		<description><![CDATA[¿Quieres aprender jQuery rápido, gratis y fácilmente? Si sabes ya algo de javascript, esto va a ser coser y cantar. Incluir la librería Siempre es recomendable delegar el hosting de la librería a google. ¿Por qué? lee esto. &#60;script type=&#34;text/javascript&#34; src=&#34;https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js&#34;&#62;&#60;/script&#62; Acceder a un elemento del DOM Hay varias formas de acceder a los elementos [...]
Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/cds-invenio/cds-invenio-implementing-autocomplete-for-authors-with-jquery-and-php-solved/' rel='bookmark' title='CDS-Invenio: implementing autocomplete for authors with jQuery and php [SOLVED]'>CDS-Invenio: implementing autocomplete for authors with jQuery and php [SOLVED]</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-sistemas-y-servidores/backuppc-gestion-de-backups-guia-de-instalacion-para-bobos/' rel='bookmark' title='BackupPC &#8211; gestión de backups. Guía de instalación para bobos.'>BackupPC &#8211; gestión de backups. Guía de instalación para bobos.</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/' rel='bookmark' title='DeepZoom &amp; SEADragon (II)'>DeepZoom &#038; SEADragon (II)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>¿Quieres aprender jQuery rápido, gratis y fácilmente? Si sabes ya algo de javascript, esto va a ser coser y cantar.</p>
<h2>Incluir la librería</h2>
<p>Siempre es recomendable delegar el hosting de la librería a google. ¿Por qué? <a href="http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/">lee esto</a>.</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> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p></p>
<h2>Acceder a un elemento del DOM</h2>
<p>Hay varias formas de acceder a los elementos del DOM. Las más comunes son por <b>id</b>, por <b>clase</b> o por <b>elemento</b>. </p>
<p>Si quieres, puedes consultar <a href="http://api.jquery.com/category/selectors/">el listado completo de selectores en la web oficial</a>.</p>
<p>Si eres impaciente, empieza viendo un ejemplo tonto de acceso de las tres formas.</p>
<h3>Acceso por id</h3>
<p>Asi se accede al elemento del DOM identificado por id=identificador</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;">&quot;#identificador&quot;</span><span style="color: #009900;">&#41;</span>.<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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;hola&quot;</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>

<h3>Acceso por clase</h3>
<p>Asi se accede a los elementos del DOM que sean de clase=&#8217;miclase&#8217;</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;">&quot;.miClase&quot;</span><span style="color: #009900;">&#41;</span>.<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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;hola&quot;</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>

<h3>Acceso por nombre elemento</h3>
<p>Asi se accede al PRIMER elemento del dom que sea un &lt;a&gt;</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;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span>.<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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;hola&quot;</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>

<h3>Acceso por otros métodos: name</h3>
<p>Y una forma algo más elaborada de acceder a otros elementos. Por ejemplo, acceder al PRIMER input con name=first_name dentro del primer form que se encuentre:</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;">&quot;input[name=first_name]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>El método de arriba es un poco lento porque hay que recorrer tooooodos los (posibles) forms del DOM. Es mejor atacar directamente al form en cuestión. Supongamos que el form id=myform.</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;">&quot;#myform input[name=first_name]&quot;</span><span style="color: #009900;">&#41;</span></pre></div></div>

<h2>Funciones que se ejecutarán tan pronto como el DOM esté listo</h2>
<p>Imagina que deseas que se cargue el dom completo antes de ejecutar algunas funciones. Lo harás asi:</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><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: #006600; font-style: italic;">// aqui defino lo que quiero que se ejecute cuando el DOM esté listo</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">// Cambio el comportamiento del div con id=jeje ante el evento 'click'</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#jeje&quot;</span><span style="color: #009900;">&#41;</span>.<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;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Has hecho click en la zona identificada por id=jeje'</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>
&nbsp;
                        <span style="color: #006600; font-style: italic;">// también puedo llamar a funciones definidas en otro js</span>
                        mifuncion<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<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>

<h2>Prevenir la reacción estándar del navegador ante un evento</h2>
<p>Los navegadores tienen un comportamiento predefinido frente a algunos eventos. Con jQuery podermos anularlo asi:</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;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span>.<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>event<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    event.<span style="color: #660066;">preventDefault</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;">// mas codigo</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>Callbacks</h2>
<p>Funciones que se pasan como parámetro a otra función y se ejecutan cuando la función padre termina.</p>
<h3>Callback sin parámetros</h3>
<p>Ejemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myhtmlpage'</span><span style="color: #339933;">,</span>myCallback<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Callback con parámetros</h3>
<p>Ojo, <b>hazlo asi</b>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myhtmlpage'</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>
  myCallBack<span style="color: #009900;">&#40;</span>param1<span style="color: #339933;">,</span>param2<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Y <b>no asi</b></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'myhtmlpage'</span><span style="color: #339933;">,</span>myCallBack<span style="color: #009900;">&#40;</span>param1<span style="color: #339933;">,</span>param2<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Si haces lo segundo, se pasará como nombre de función callback el resultado de ejecutar myCallBack(param1,param2)&#8230; lo que NO es correcto!</p>
<p>Además de pasar parámeotros por <em>GET</em> (<a href="http://api.jquery.com/jQuery.get/">$.get</a>), también se admiten peticiones por <em>POST</em> (<a href="http://api.jquery.com/jQuery.post/">$.post</a>) y otras. <a href="http://api.jquery.com/category/ajax/shorthand-methods/">Consulta la lista de shorthand-methods completa en la web de jQuery</a></p>
<h2>AJAX en jQuery</h2>
<p>jQuery admite las peticiones asíncronas con la <a href="http://api.jquery.com/jQuery.ajax/">función jQuery.ajax</a>. Por ejemplo este trozo de código llama a la url especificada y cuando se termina la ejecución del código de la misma, se ejecuta la función success. En data tendremos el resultado de la ejecución de la url.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'ajax/test.html'</span><span style="color: #339933;">,</span>
  success<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: #009900;">&#40;</span><span style="color: #3366CC;">'.result'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Load was performed.'</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;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Un ejemplo algo más completo de esto mismo (con su HTML y tal)</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">    &lt;html&gt;
    &lt;head&gt;
        &lt;script type=&quot;text/javascript&quot; src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js&quot;&gt;&lt;/script&gt;
        <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: #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: #006600; font-style: italic;">// Inicializo controlador del div con id=jeje</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#jeje&quot;</span><span style="color: #009900;">&#41;</span>.<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: #660066;">ajax</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
                    url<span style="color: #339933;">:</span> <span style="color: #3366CC;">'callback.php'</span><span style="color: #339933;">,</span>
                    success<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: #009900;">&#40;</span><span style="color: #3366CC;">'#botones'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #006600; font-style: italic;">//alert('Load was performed. Data = '+data+'.');</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: #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>
        <span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span>
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div id=&quot;jeje&quot; style=&quot;background-color: #ff0000; width: 150px; height: 150px; border:1px solid;&quot;&gt;
            Haz click por aqui dentro...
        &lt;/div&gt;
        &lt;div id=&quot;botones&quot;&gt;
            Al hacer click arriba en esta zona aparecerán los botones
      &lt;/div&gt;       
    &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>Y el código php al que llamamos (callback.php) podría ser tan simple como:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;input type=&quot;button&quot; id=&quot;aficha&quot; value=&quot;Añadir Ficha&quot; /&gt;'</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h2>Eventos en jQuery</h2>
<p>Si habéis leido hasta aqui, veréis que he usado varias veces el evento <a href="http://api.jquery.com/click/">.click()</a>. Hay muchos más eventos (<a href="http://api.jquery.com/category/events/">consulta el listado completo de eventos</a>). Su invocación y uso es similar al .click()<br />
Es importante notar que no todos se pueden aplicar a todo tipo de elementos. Por ejemplo, el <a href="http://api.jquery.com/select/">.select()</a> solo es aplicable a elementos input-text y textareas de un form.</p>
<h2>Manipulación del DOM</h2>
<p>El siguiente grupo de elementos son los que hacen referencia a la <b>manipulación</b> del DOM.<br />
El <a href="http://api.jquery.com/category/manipulation/">manual completo con todas las funciones se puede ver aqui</a></p>
<p>Por ejemplo, podemos añadir clase a un determinado elemento:</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;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;miclase&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>pasando de:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;mipagina.html&quot;&gt;mipagina&lt;/a&gt;</pre></div></div>

<p>a</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a class=&quot;miclase&quot; href=&quot;mipagina.html&quot;&gt;mipagina&lt;/a&gt;</pre></div></div>

<p>De forma similar, podemos eliminar una clase:</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;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;miclase&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Se pueden combinar ambas para obtener interesantes efectos:</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;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;inactive&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;active&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Incluso poner clases múltiples:</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;">&quot;a&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;miclase activo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Otro de los manipuladores interesantes es <a href="http://api.jquery.com/attr/">.attr()</a>, con el que podemos obtener y cambiar el valor de un atributo.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> eltitulo <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;title&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;_modificado&quot;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;div&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;title&quot;</span><span style="color: #339933;">,</span> eltitulo<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">/* o lo que es lo mismo, $(&quot;div&quot;).attr(&quot;title&quot;) = eltitulo; */</span></pre></div></div>

<p>Incluso podemos cambiar varios atributos con una sola llamada:</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;">&quot;div&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
  title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'mititulo'</span><span style="color: #339933;">,</span>
  alt<span style="color: #339933;">:</span> <span style="color: #3366CC;">'texto alternativo'</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Podemos hacer también un <em>loop</em> por los atributos usando <a href="http://api.jquery.com/each/">.each()</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>target.<span style="color: #660066;">attributes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>index<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;Attribute name: &quot;</span> <span style="color: #339933;">+</span> target.<span style="color: #660066;">attributes</span><span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span>.<span style="color: #000066;">name</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; Attribute value: &quot;</span> <span style="color: #339933;">+</span> target.<span style="color: #660066;">attributes</span><span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">value</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>

<h2>Efectos</h2>
<p>El último grupo importante que nos falta por ver. Por ejemplo, si queremos que un div se oculte, podemos usar <a href="http://api.jquery.com/hide/">.hide()</a>. Incluso nos permite ajustar la velocidad con que queremos que se produzca este &#8220;escondido&#8221;.</p>
<p>Otros <a href="http://api.jquery.com/category/effects/basics/">efectos básicos</a> son <a href="http://api.jquery.com/show/">.show()</a> y <a href="http://api.jquery.com/toggle/">.toggle()</a>.</p>
<p>Pero hay muchos más efectos (algunos bastante complejos). Podéis consultar el <a href="http://api.jquery.com/category/effects/">listado completo de efectos en la web de jQuery</a>.</p>
<p>Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/cds-invenio/cds-invenio-implementing-autocomplete-for-authors-with-jquery-and-php-solved/' rel='bookmark' title='CDS-Invenio: implementing autocomplete for authors with jQuery and php [SOLVED]'>CDS-Invenio: implementing autocomplete for authors with jQuery and php [SOLVED]</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-sistemas-y-servidores/backuppc-gestion-de-backups-guia-de-instalacion-para-bobos/' rel='bookmark' title='BackupPC &#8211; gestión de backups. Guía de instalación para bobos.'>BackupPC &#8211; gestión de backups. Guía de instalación para bobos.</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/' rel='bookmark' title='DeepZoom &amp; SEADragon (II)'>DeepZoom &#038; SEADragon (II)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leccionespracticas.com/javascript/jquery-en-10-minutos-guia-para-impacientes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SMF 2.0 RC3: Flickr HTML code to BBCode mod [working]</title>
		<link>http://www.leccionespracticas.com/informatica-web/smf-2-0-rc3-flickr-html-code-to-bbcode-mod-working/</link>
		<comments>http://www.leccionespracticas.com/informatica-web/smf-2-0-rc3-flickr-html-code-to-bbcode-mod-working/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 07:30:47 +0000</pubDate>
		<dc:creator>Miguel</dc:creator>
				<category><![CDATA[Informática - web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[bbcode]]></category>
		<category><![CDATA[custom]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[iframe]]></category>
		<category><![CDATA[simple machines forum]]></category>
		<category><![CDATA[SMF]]></category>
		<category><![CDATA[write]]></category>

		<guid isPermaLink="false">http://www.leccionespracticas.com/?p=1229</guid>
		<description><![CDATA[We are developing a photographic website (with an SMF 2.0 RC3 forum) and most of our users have their photos hosted in Flickr. (Note: I have installed WYSIWYG Quick Reply v2 RC3 package) So I&#8217;d like to make their lifes easier when sharing their photos by adding a custom button (here in the post wysiwyg [...]
Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/dfgallery-2-0-flickr-this-photo-is-currently-unavailable-solved/' rel='bookmark' title='dfgallery 2.0: Flickr &#8220;this photo is currently unavailable&#8221; [SOLVED]'>dfgallery 2.0: Flickr &#8220;this photo is currently unavailable&#8221; [SOLVED]</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/' rel='bookmark' title='DeepZoom &amp; SEADragon (II)'>DeepZoom &#038; SEADragon (II)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/spoiler-div-con-html-and-javascript/' rel='bookmark' title='Spoiler div con HTML and Javascript'>Spoiler div con HTML and Javascript</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>We are developing a photographic website (with an SMF 2.0 RC3 forum) and most of our users have their photos hosted in Flickr. </p>
<p>(Note: I have installed <em>WYSIWYG Quick Reply v2  	RC3</em> package)</p>
<p>So I&#8217;d like to make their lifes easier when sharing their photos by adding a custom button (here in the post wysiwyg editor) which converts this html structure (the code snippet flickr shows to the user):</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;a href=&quot;URL1&quot; title=&quot;this_is_the_title&quot;&gt;&lt;img src=&quot;IMGURL&quot; width=&quot;342&quot; height=&quot;500&quot; alt=&quot;alt_text&quot; /&gt;&lt;/a&gt;</pre></div></div>

<p>To something like:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #007800;">url</span>=URL1<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>img<span style="color: #7a0874; font-weight: bold;">&#93;</span>IMGURL<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>img<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000; font-weight: bold;">/</span>url<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<h3>How to do this?</h3>
<p>* Edit your <code>Themes/default/GenericControls.template.php</code><br />
<strong>* Locate:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> template_control_richedit<span style="color: #009900;">&#40;</span><span style="color: #000088;">$editor_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$smileyContainer</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$bbcContainer</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$context</span><span style="color: #339933;">,</span> <span style="color: #000088;">$settings</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #339933;">,</span> <span style="color: #000088;">$txt</span><span style="color: #339933;">,</span> <span style="color: #000088;">$modSettings</span><span style="color: #339933;">,</span> <span style="color: #000088;">$scripturl</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$editor_context</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$context</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'controls'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'richedit'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$editor_id</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>* Add after</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">?&gt;
	&lt;script language=&quot;javascript&quot;&gt;
	    function convierteCode(){
	    	// dado un codigo tipo flickr lo convierte a BBCode (def en GenericControls.template.php)
                        var flickr = document.getElementById(&quot;flickrcodeinput&quot;).value;
			flickr = flickr.replace('&lt;a href=&quot;','[url=');
			flickr = flickr.replace('&quot; /&gt;&lt;/a&gt;','[/img][/url]');
			flickr = flickr.replace(/&quot;(.)+title(.)*&gt;&lt;img(.)+src=&quot;/,'][img]');
			flickr = flickr.replace(/&quot;(.)+width(.)*\[/,'[');
			flickr = flickr.replace('[/url]','[/img][/url]');											 
			document.getElementById(&quot;message&quot;).value += flickr;
			window.frames[0].document.write(flickr);
	    }
	&lt;/script&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span></pre></div></div>

<p><strong>*Locate:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
		&lt;div&gt;
			&lt;div&gt;
				&lt;textarea class=&quot;editor&quot;</span></pre></div></div>

<p><strong>* Replace with:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
		&lt;div&gt;
			&lt;div&gt;
			    &lt;!-- flickr input and button--&gt;
                               &lt;input type=&quot;text&quot; id=&quot;flickrcodeinput&quot; width=&quot;100px&quot;&gt;&lt;/input&gt;&amp;nbsp;
                               &lt;input type=&quot;button&quot; value=&quot;Inserta IMG flickr&quot; onClick=&quot;convierteCode();&quot;&gt;&lt;/input&gt;
                               &lt;br /&gt;&lt;br /&gt;
                            &lt;!--flickr input and button end --&gt;
				&lt;textarea class=&quot;editor&quot;</span></pre></div></div>

<p>* Upload the new GenericControls.template.php</p>
<p>(Note for curious people: I also tried this by adding a custom button which would produce a new bbcode like [flickr][/flickr] and blahblahblah, but I could not make it work. More details <a href="http://www.simplemachines.org/community/index.php?action=profile;area=showposts;u=248890">here</a>)</p>
<p>Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/dfgallery-2-0-flickr-this-photo-is-currently-unavailable-solved/' rel='bookmark' title='dfgallery 2.0: Flickr &#8220;this photo is currently unavailable&#8221; [SOLVED]'>dfgallery 2.0: Flickr &#8220;this photo is currently unavailable&#8221; [SOLVED]</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/' rel='bookmark' title='DeepZoom &amp; SEADragon (II)'>DeepZoom &#038; SEADragon (II)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/spoiler-div-con-html-and-javascript/' rel='bookmark' title='Spoiler div con HTML and Javascript'>Spoiler div con HTML and Javascript</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leccionespracticas.com/informatica-web/smf-2-0-rc3-flickr-html-code-to-bbcode-mod-working/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Javascript &#8211; sort tables (by column values) [easy and opensource]</title>
		<link>http://www.leccionespracticas.com/javascript/javascript-sort-tables-by-column-values/</link>
		<comments>http://www.leccionespracticas.com/javascript/javascript-sort-tables-by-column-values/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 08:33:58 +0000</pubDate>
		<dc:creator>Miguel</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[sortable]]></category>
		<category><![CDATA[sorttable]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[tables]]></category>

		<guid isPermaLink="false">http://www.leccionespracticas.com/?p=1106</guid>
		<description><![CDATA[If you see a table in a client-side application, you&#8217;ll expect to be able to click on the headers and have the table sort, would you not? I know it always annoys me when you can&#8217;t. A fair few web applications do allow this; most of them, which are pulling this data by submitting a [...]
Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/javascript/w3c-validator-issues-with-ampersand-in-javascript-location-href/' rel='bookmark' title='W3C validator issues with ampersand (&amp;) in javascript location.href'>W3C validator issues with ampersand (&#038;) in javascript location.href</a></li>
<li><a href='http://www.leccionespracticas.com/javascript/browser-detection-with-javascript/' rel='bookmark' title='Browser detection with javascript'>Browser detection with javascript</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/javascript-depurando-errores/' rel='bookmark' title='Javascript: depurando errores'>Javascript: depurando errores</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>If you see a <b>table</b> in a client-side application, you&#8217;ll expect to be able to click on the headers and have the <b>table sort</b>, would you not? I know it always annoys me when you can&#8217;t. A fair few web applications do allow this; most of them, which are pulling this data by submitting a <b>SQL</b> query to a relational database (an environment eminently suited to tabular data) implement this by resubmitting the whole page with something like ordercolumn=4 in the URL, and then adding an <em>ORDER BY</em> clause to their SQL query to return the data from the DB ordered by the specified column.</p>
<p>Resubmit the page? Just to sort data we already have? I&#8217;m sure we can do better than that: just using javascript!</p>
<p>Take a look at <a href="http://www.kryogenix.org/code/browser/sorttable/">sorrtable javascript library</a> and follow the simple steps to have a sortable table.</p>
<p>   1. <a href="http://www.kryogenix.org/code/browser/sorttable/sorttable.js">Download the Javascript library</a><br />
   2. Include the <a href="http://www.kryogenix.org/code/browser/sorttable/sorttable.js">Javascript library</a>, by putting a link to it in the HEAD of your page, like so:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">      &lt;script src=&quot;sorttable.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>   3. Mark your table as a sortable one by giving it a class of &#8220;sortable&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">         &lt;table class=&quot;sortable&quot;&gt;</pre></div></div>

<p>Note that the library&#8217;s JavaScript file is called sorttable (two Ts), but the class you add to the table is sortable (one T).</p>
<p>Easy, isn&#8217;t it? <img src='http://www.leccionespracticas.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/javascript/w3c-validator-issues-with-ampersand-in-javascript-location-href/' rel='bookmark' title='W3C validator issues with ampersand (&amp;) in javascript location.href'>W3C validator issues with ampersand (&#038;) in javascript location.href</a></li>
<li><a href='http://www.leccionespracticas.com/javascript/browser-detection-with-javascript/' rel='bookmark' title='Browser detection with javascript'>Browser detection with javascript</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/javascript-depurando-errores/' rel='bookmark' title='Javascript: depurando errores'>Javascript: depurando errores</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leccionespracticas.com/javascript/javascript-sort-tables-by-column-values/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>W3C validator issues with ampersand (&amp;) in javascript location.href</title>
		<link>http://www.leccionespracticas.com/javascript/w3c-validator-issues-with-ampersand-in-javascript-location-href/</link>
		<comments>http://www.leccionespracticas.com/javascript/w3c-validator-issues-with-ampersand-in-javascript-location-href/#comments</comments>
		<pubDate>Sat, 19 Sep 2009 12:13:11 +0000</pubDate>
		<dc:creator>Miguel</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[ampersand]]></category>
		<category><![CDATA[cdata]]></category>
		<category><![CDATA[decode]]></category>
		<category><![CDATA[dtd]]></category>
		<category><![CDATA[encode]]></category>
		<category><![CDATA[location.href]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[strict]]></category>
		<category><![CDATA[validator]]></category>
		<category><![CDATA[w3c]]></category>

		<guid isPermaLink="false">http://www.leccionespracticas.com/?p=771</guid>
		<description><![CDATA[When I tried to validate the code for http://www.hyips.es (one of my freelance projects) the validator kept complaining: cannot generate system identifier for general entity langpair. This error is caused by the validator parsing the code inside of a &#60;script> tag. Below are the lines which were producing the error (related to a function which [...]
Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/joomla-informatica-web/joomla-1-5-ampersands-and-w3c-validator/' rel='bookmark' title='joomla 1.5, ampersands and W3C validator'>joomla 1.5, ampersands and W3C validator</a></li>
<li><a href='http://www.leccionespracticas.com/cds-invenio/cds-invenio-oai-xml-validator-content-is-not-allowed-in-prolog/' rel='bookmark' title='CDS Invenio, OAI XML Validator: Content is not allowed in prolog'>CDS Invenio, OAI XML Validator: Content is not allowed in prolog</a></li>
<li><a href='http://www.leccionespracticas.com/javascript/browser-detection-with-javascript/' rel='bookmark' title='Browser detection with javascript'>Browser detection with javascript</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When I tried to validate the code for <a href="http://www.hyips.es">http://www.hyips.es</a> (one of my freelance projects) the validator kept complaining:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">cannot generate system identifier <span style="color: #000000; font-weight: bold;">for</span> general entity langpair.</pre></div></div>

<p>This error is caused by the validator parsing the code inside of a &lt;script> tag. Below are the lines which were producing the error (related to a function which translates the page from spanish to english using google translator):</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot;&gt; 
function es2eng(){
  location.href = &quot;http://translate.google.com/translate?u=&quot; + this.location.href + &quot;&amp;langpair=es|en&amp;h1=es&amp;ie=UTF-8&quot;; 
}
&lt;/script&gt;
&lt;a href=&quot;#&quot; onclick=&quot;es2eng();&quot;&gt;&lt;img style=&quot;border: medium none; margin:1px;&quot; src=&quot;/images/banderas/england-flag.gif&quot; alt=&quot;translate to english&quot; height=&quot;20&quot; width=&quot;30&quot; /&gt;&lt;/a&gt;</pre></div></div>

<p>After reading a lot of confussing comments (like <em>Try to change &#8216;&#038;&#8217; to &#8216;&amp;amp;&#8217; or to &#8216;%26&#8242;</em>), and just when I was about to define the function in an external js file (not a big fan of this, because the function was only one line long&#8230;), I came to <a href="http://www.webmasterworld.com/forum91/353.htm">this revealing post in webmasterworld.com</a>.</p>
<p>The problem can be solved as easy as this: change</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot;&gt;
your script is here
&lt;/script&gt;</pre></div></div>

<p>To:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot;&gt;
// &lt;![CDATA[
your script is here
// ]]&gt;
&lt;/script&gt;</pre></div></div>

<p>The change stops W3C&#8217;s validator from parsing the code inside the <code>script</code> tags, therefore the error disappears! <img src='http://www.leccionespracticas.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/joomla-informatica-web/joomla-1-5-ampersands-and-w3c-validator/' rel='bookmark' title='joomla 1.5, ampersands and W3C validator'>joomla 1.5, ampersands and W3C validator</a></li>
<li><a href='http://www.leccionespracticas.com/cds-invenio/cds-invenio-oai-xml-validator-content-is-not-allowed-in-prolog/' rel='bookmark' title='CDS Invenio, OAI XML Validator: Content is not allowed in prolog'>CDS Invenio, OAI XML Validator: Content is not allowed in prolog</a></li>
<li><a href='http://www.leccionespracticas.com/javascript/browser-detection-with-javascript/' rel='bookmark' title='Browser detection with javascript'>Browser detection with javascript</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leccionespracticas.com/javascript/w3c-validator-issues-with-ampersand-in-javascript-location-href/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Browser detection with javascript</title>
		<link>http://www.leccionespracticas.com/javascript/browser-detection-with-javascript/</link>
		<comments>http://www.leccionespracticas.com/javascript/browser-detection-with-javascript/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 10:38:12 +0000</pubDate>
		<dc:creator>Miguel</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[detect]]></category>
		<category><![CDATA[detection]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[mozilla]]></category>
		<category><![CDATA[netscape]]></category>

		<guid isPermaLink="false">http://www.leccionespracticas.com/?p=635</guid>
		<description><![CDATA[In a perfect world, all the major browsers would co-exist happily together, supporting the same set of objects and features. But then again, in that world, I&#8217;d be on an island enjoying the sun. Before we reach that place, this tutorial looks at how to detect support for a particular JavaScript property or method before [...]
Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iv/' rel='bookmark' title='DeepZoom &amp; SEADragon (IV)'>DeepZoom &#038; SEADragon (IV)</a></li>
<li><a href='http://www.leccionespracticas.com/javascript/javascript-sort-tables-by-column-values/' rel='bookmark' title='Javascript &#8211; sort tables (by column values) [easy and opensource]'>Javascript &#8211; sort tables (by column values) [easy and opensource]</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/spoiler-div-con-html-and-javascript/' rel='bookmark' title='Spoiler div con HTML and Javascript'>Spoiler div con HTML and Javascript</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In a perfect world, all the major browsers would co-exist happily together, supporting the same set of objects and features. But then again, in that world, I&#8217;d be on an island enjoying the sun. </p>
<p>Before we reach that place, this tutorial looks at how to detect support for a particular JavaScript property or method before attempting to invoke it. It serves as an alternate, in many cases, superior way to strict browser detection for creating cross browser friendly scripts.</p>
<p>Here is an small example of how to detect the browser &#038; version:<br />
<code></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="html" style="font-family:monospace;">&lt;html&gt;
&lt;body&gt;
&nbsp;
&lt;script type=&quot;text/javascript&quot;&gt;
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
&nbsp;
document.write(&quot;Browser name: &quot;+ browser);
document.write(&quot;&lt;br /&gt;&quot;);
document.write(&quot;Browser version: &quot;+ version);
&lt;/script&gt;
&nbsp;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p></code></p>
<p>Another (more practical) way to discriminate the browser can be done like this:<br />
<code></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;">  <span style="color: #003366; font-weight: bold;">var</span> browser<span style="color: #339933;">=</span>navigator.<span style="color: #660066;">appName</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>browser<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;Netscape&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #006600; font-style: italic;">// mozilla, netscape, chrome, ...</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>browser<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;Microsoft Internet Explorer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #006600; font-style: italic;">// Internet Explorer 4 or Opera with IE user agent</span>
  <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p></code></p>
<p>Have fun <img src='http://www.leccionespracticas.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iv/' rel='bookmark' title='DeepZoom &amp; SEADragon (IV)'>DeepZoom &#038; SEADragon (IV)</a></li>
<li><a href='http://www.leccionespracticas.com/javascript/javascript-sort-tables-by-column-values/' rel='bookmark' title='Javascript &#8211; sort tables (by column values) [easy and opensource]'>Javascript &#8211; sort tables (by column values) [easy and opensource]</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/spoiler-div-con-html-and-javascript/' rel='bookmark' title='Spoiler div con HTML and Javascript'>Spoiler div con HTML and Javascript</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leccionespracticas.com/javascript/browser-detection-with-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DeepZoom &amp; SEADragon (IV)</title>
		<link>http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iv/</link>
		<comments>http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iv/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 08:10:46 +0000</pubDate>
		<dc:creator>Miguel</dc:creator>
				<category><![CDATA[Informática - web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[seadragon]]></category>

		<guid isPermaLink="false">http://www.leccionespracticas.com/?p=616</guid>
		<description><![CDATA[IMHO SEADragon should include some controls to go to next/previous image and not restrict the navigation between images to clicking the thumnails. So I decided to build these new custom buttons. Documentation Before you continue reading these post you should be familiar with SEADragon, DeepZoom and jCarousel. If you are not, please read the following [...]
Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/' rel='bookmark' title='DeepZoom &amp; SEADragon (II)'>DeepZoom &#038; SEADragon (II)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iii/' rel='bookmark' title='DeepZoom &amp; SEADragon (III)'>DeepZoom &#038; SEADragon (III)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/' rel='bookmark' title='DeepZoom &amp; SEADragon (I)'>DeepZoom &#038; SEADragon (I)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>IMHO SEADragon should include some controls to go to next/previous image and not restrict the navigation between images to clicking the thumnails. So I decided to build these new custom buttons.</p>
<h3>Documentation</h3>
<p>Before you continue reading these post you should be familiar with SEADragon, DeepZoom and jCarousel. If you are not, please read the following posts:<br />
<a href="http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/">[1] DeepZoom &#038; SEADragon part one</a> (build basic html page with the viewer)<br />
<a href="http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/">[2] DeepZoom &#038; SEADragon part two</a> (use jCarousel to display thumbs)<br />
<a href="http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/">[3] DeepZoom &#038; SEADragon part three</a> (remove SEADragon logo).</p>
<h3>Adding custom controls to the viewer: some &#8220;easy&#8221; example</h3>
<p>Before changing my code I decided to ask google if someone had added custom buttons to the viewer, and google, as usual, answered my question. In <a href="http://www.ajaxdaddy.com/demo-jquery-carousel.html">ajaxdaddy.com</a> I found this -great- example of how to do it. It&#8217;s quite well explained there. Please read it carefully.</p>
<h3>Adding custom controls to the viewer: integration with jCarousel</h3>
<p>The example shown above is great. But I had a slightly diferent problem: I had to integrate the next/previous button behaviour with my thumbs carousel, so it moved forwards and backwards when necessary.</p>
<p>We well part from the <a href="http://www.leccionespracticas.com/programas/DeepZoom/index8.html">previous example code</a> to explain all the modifications.</p>
<ol>
<li>Change <code>doOpen</code> function: this function had two parameters, the first one was the <code>item</code> to show. I changed this parameter so it was the index to read, and not the item itself.<br />
I also defined a new global variable (I know, it is not the best choice, but it works) called <code>selectedIndex</code> to know what is the index corresponding to the shown image at any time. I did all this in order to make easier the next steps <img src='http://www.leccionespracticas.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>This was my code *before* the modifications:<br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> doOpen<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> anchor<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>selectedItem<span style="color: #009900;">&#41;</span>
        selectedItem.<span style="color: #660066;">button</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> thumbsPath <span style="color: #339933;">+</span> selectedItem.<span style="color: #660066;">thumb</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'_rest.png'</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        viewer.<span style="color: #660066;">openDzi</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">dzi</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        titleDiv.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">title</span><span style="color: #339933;">;</span>
        descDiv.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">desc</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">button</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> thumbsPath <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">thumb</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'_selected.png'</span><span style="color: #339933;">;</span>
        selectedItem <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>anchor<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               window.<span style="color: #660066;">location</span>.<span style="color: #660066;">hash</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;#&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">thumb</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></div></div>

<p></code></p>
<p>*After* the mods, my code is:<br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> selectedIndex <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;">function</span> doOpen<span style="color: #009900;">&#40;</span>index<span style="color: #339933;">,</span> anchor<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">item</span> <span style="color: #339933;">=</span> data<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>selectedItem<span style="color: #009900;">&#41;</span>
           selectedItem.<span style="color: #660066;">button</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> thumbsPath <span style="color: #339933;">+</span> selectedItem.<span style="color: #660066;">thumb</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'_rest.png'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
           viewer.<span style="color: #660066;">openDzi</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">dzi</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">xml</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
           titleDiv.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">title</span><span style="color: #339933;">;</span>
           descDiv.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">desc</span><span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">button</span>.<span style="color: #660066;">src</span> <span style="color: #339933;">=</span> thumbsPath <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">thumb</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'_selected.png'</span><span style="color: #339933;">;</span>
           selectedItem <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">;</span>
	   selectedIndex <span style="color: #339933;">=</span> index<span style="color: #339933;">;</span>
&nbsp;
           <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>anchor<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                window.<span style="color: #660066;">location</span>.<span style="color: #660066;">hash</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;#&quot;</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">thumb</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></div></div>

<p></code></p>
<p>Of course the way of calling these functions also changes. Again, a before&#038;after:<br />
*before*: <code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">doOpen<span style="color: #009900;">&#40;</span>dataMap<span style="color: #009900;">&#91;</span>hash<span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> data<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></code><br />
*after*: <code></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">doOpen<span style="color: #009900;">&#40;</span>hash <span style="color: #339933;">||</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p></code>
</li>
<li>Download two images for the buttons. For instance, you can take this two:<br />
<a href="http://www.leccionespracticas.com/programas/DeepZoom/img/load_next_image.png">Next</a><br />
<a href="http://www.leccionespracticas.com/programas/DeepZoom/img/load_prev_image.png">Previous</a></p>
<p>Place them in <code>./img</code> &nbsp; folder and name them <code>load_next_image.png</code> and <code>load_prev_image.png</code>.
</li>
<li>Now, we have to add the new buttons and their behaviour, which is done by the following code (i show only the part for the &#8220;next&#8221; button, since the &#8220;prev&#8221; is pretty similar):<br />
<code></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="javascript" style="font-family:monospace;">	<span style="color: #003366; font-weight: bold;">var</span> nextControl <span style="color: #339933;">=</span> makeControlNEXT<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	nextControl.<span style="color: #660066;">style</span>.<span style="color: #660066;">marginLeft</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;4px&quot;</span><span style="color: #339933;">;</span>
	nextControl.<span style="color: #660066;">style</span>.<span style="color: #660066;">marginBottom</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;4px&quot;</span><span style="color: #339933;">;</span>
	viewer.<span style="color: #660066;">addControl</span><span style="color: #009900;">&#40;</span>nextControl<span style="color: #339933;">,</span> Seadragon.<span style="color: #660066;">ControlAnchor</span>.<span style="color: #660066;">TOP_RIGHT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>				
&nbsp;
	<span style="color: #006600; font-style: italic;">/*
	* Creates the new &quot;next&quot; button which does:
	* (1) Show -if available- the next image in the SeaDragon viewer
	* (2) Moves forwards -if necessary- the JCarousel so the
	*/</span>
        <span style="color: #003366; font-weight: bold;">function</span> makeControlNEXT<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> controlNEXT <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</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>
            <span style="color: #003366; font-weight: bold;">var</span> controlImg <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElement</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'img'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	    controlImg.<span style="color: #660066;">src</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;./img/load_next_image.png&quot;</span><span style="color: #339933;">;</span>
	    controlImg.<span style="color: #660066;">className</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;thumb&quot;</span><span style="color: #339933;">;</span>
	    controlImg.<span style="color: #660066;">title</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;next&quot;</span><span style="color: #339933;">;</span>
            controlNEXT.<span style="color: #660066;">href</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// so browser shows it as link</span>
	    controlNEXT.<span style="color: #660066;">id</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;controlNEXT2&quot;</span><span style="color: #339933;">;</span>  <span style="color: #006600; font-style: italic;">// this is QUITE important for the next part!! (jCarousel)</span>
            controlNEXT.<span style="color: #660066;">className</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;controlNEXT&quot;</span><span style="color: #339933;">;</span>
            controlNEXT.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>controlImg<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            Seadragon.<span style="color: #660066;">Utils</span>.<span style="color: #660066;">addEvent</span><span style="color: #009900;">&#40;</span>controlNEXT<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;click&quot;</span><span style="color: #339933;">,</span> doOpenNEXT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000066; font-weight: bold;">return</span> controlNEXT<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #003366; font-weight: bold;">function</span> doOpenNEXT<span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
             Seadragon.<span style="color: #660066;">Utils</span>.<span style="color: #660066;">cancelEvent</span><span style="color: #009900;">&#40;</span>event<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>    <span style="color: #006600; font-style: italic;">// so link isn't processed</span>
&nbsp;
             <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>viewer.<span style="color: #660066;">isOpen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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: #339933;">;</span>
             <span style="color: #009900;">&#125;</span>
&nbsp;
             <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#40;</span>selectedIndex<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> count<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// if there is a next image to show...show it!</span>
		 doOpen<span style="color: #009900;">&#40;</span>selectedIndex<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	     <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p></code></p>
<p>Note the <code>controlNEXT.id = "controlNEXT2";</code> in line 18. We will use this in next section to &#8220;connect&#8221; this to the function that must be executed in jCarousel.
</li>
<li>At this point you should have both buttons working with SEADragon. This is, when you click next button the viewer will show the next image. But there still remains something: notice the jCarousel in the bottom, it does not move forwards nor backwards when the displayed image changes! This is not a problem if you only have three images, but I&#8217;ll assume you&#8217;ll have more than three. So lets get to work.</li>
<p></p>
<li>Modify the way jCarousel is built. Again, a before&#038;after is shown:<br />
*before:<br />
<code></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><span style="color: #339933;">&gt;</span> 
    jQuery<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>
         jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mycarousel'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">jcarousel</span><span style="color: #009900;">&#40;</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: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p></code></p>
<p>*after:<br />
<code></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="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> mycarousel_initCallback<span style="color: #009900;">&#40;</span>carousel<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.jcarousel-control a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</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>
                   carousel.<span style="color: #000066;">scroll</span><span style="color: #009900;">&#40;</span>jQuery.<span style="color: #660066;">jcarousel</span>.<span style="color: #660066;">intval</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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;
             jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#controlNEXT2'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</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: #660066;">balance</span> <span style="color: #339933;">=</span> selectedIndex<span style="color: #339933;">%</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
		    $.<span style="color: #660066;">bloquear</span> <span style="color: #339933;">=</span> selectedIndex<span style="color: #339933;">;</span>
		    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">balance</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">&amp;&amp;</span> $.<span style="color: #660066;">bloquear</span><span style="color: #339933;">!=</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// must the carousel be moved?</span>
  			carousel.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</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;
  	      jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#controlPREV2'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</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: #660066;">balance</span> <span style="color: #339933;">=</span> selectedIndex<span style="color: #339933;">%</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
		    $.<span style="color: #660066;">bloquear</span> <span style="color: #339933;">=</span> selectedIndex<span style="color: #339933;">;</span>
		    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">balance</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">&amp;&amp;</span> $.<span style="color: #660066;">bloquear</span><span style="color: #339933;">!=</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  		        carousel.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</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>
   <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
   jQuery<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: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">balance</span> <span style="color: #339933;">===</span> undefined<span style="color: #009900;">&#41;</span> $.<span style="color: #660066;">balance</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
           jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mycarousel'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">jcarousel</span><span style="color: #009900;">&#40;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">scroll</span><span style="color: #339933;">:</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span>
                        initCallback<span style="color: #339933;">:</span> mycarousel_initCallback
		<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>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p></code></p>
<p>Notice the <code>controNEXT2</code> in line 17? It is the same id that we had in section 3, line 18.
</li>
</ol>
<p>So, the behaviour when clicking &#8220;next&#8221; or &#8220;previous&#8221; buttons in the top of the viewer is:<br />
- First, call <code>doOpenNEXT</code> or <code>doOpenPREV</code> which makes SEADragon viewer to show the next / previous image.<br />
- Second, call the function defined in section 5, line 18 which makes jCarousel to move forwards or backwards if necesary.<br />
- We use <code>selectedIndex</code> variable to decide if the jCarousel must or mustn&#8217;t move.</p>
<p>You can <a href="http://www.leccionespracticas.com/programas/DeepZoom/index18.html">see a FULL EXAMPLE HERE</a>.</p>
<h3> Solving the browser issues: IE8 vs Mozilla</h3>
<p>If you run the example above in a Mozilla/Netscape browser it will work fine. But if you try to do it in a Internet Explorer browser, the jCarousel will not move when it has to.</p>
<p>This is related with the order of execution of functions:<br />
- Mozilla: it executes first <code>doOpenNEXT</code> / <code>doOpenPREV</code> and then the function next of jCarousel.<br />
- IE8: the order of execution is first the function of jCarousel and then the others. </p>
<p>So selectedIndex is not updated when it has to be in IE8 and it fails to move the jCarousel when it has to.</p>
<p>Please read my <a href="http://www.leccionespracticas.com/javascript/browser-detection-with-javascript/">browser detection with javascript post</a> before doing anything. Then modify the jCarousel functions as in:<br />
<code></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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/* browser detection! */</span>
<span style="color: #003366; font-weight: bold;">var</span> browser<span style="color: #339933;">=</span>navigator.<span style="color: #660066;">appName</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> b_version<span style="color: #339933;">=</span>navigator.<span style="color: #660066;">appVersion</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> version<span style="color: #339933;">=</span>parseFloat<span style="color: #009900;">&#40;</span>b_version<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#controlNEXT2'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</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;">if</span> <span style="color: #009900;">&#40;</span>browser<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;Netscape&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #006600; font-style: italic;">// mozilla, netscape, ...</span>
	  $.<span style="color: #660066;">balance</span> <span style="color: #339933;">=</span> selectedIndex<span style="color: #339933;">%</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
	  $.<span style="color: #660066;">bloquear</span> <span style="color: #339933;">=</span> selectedIndex<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>browser<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;Microsoft Internet Explorer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #006600; font-style: italic;">// Internet Explorer 4 or Opera with IE user agent</span>
          $.<span style="color: #660066;">balance</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>selectedIndex<span style="color: #339933;">+</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
	  $.<span style="color: #660066;">bloquear</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>selectedIndex<span style="color: #339933;">+</span><span style="color: #CC0000;">1</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>$.<span style="color: #660066;">balance</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">&amp;&amp;</span> $.<span style="color: #660066;">bloquear</span><span style="color: #339933;">!=</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  	     carousel.<span style="color: #660066;">next</span><span style="color: #009900;">&#40;</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;
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#controlPREV2'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</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;">if</span> <span style="color: #009900;">&#40;</span>browser<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;Netscape&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $.<span style="color: #660066;">balance</span> <span style="color: #339933;">=</span> selectedIndex<span style="color: #339933;">%</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
	$.<span style="color: #660066;">bloquear</span> <span style="color: #339933;">=</span> selectedIndex<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>browser<span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;Microsoft Internet Explorer&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $.<span style="color: #660066;">balance</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>selectedIndex<span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">%</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">;</span>
        $.<span style="color: #660066;">bloquear</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>selectedIndex<span style="color: #339933;">-</span><span style="color: #CC0000;">1</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>$.<span style="color: #660066;">balance</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">2</span> <span style="color: #339933;">&amp;&amp;</span> $.<span style="color: #660066;">bloquear</span><span style="color: #339933;">!=</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       carousel.<span style="color: #660066;">prev</span><span style="color: #009900;">&#40;</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></pre></td></tr></table></div>

<p></code></p>
<p>Now it works fine!<br />
Visit the <a href="http://www.leccionespracticas.com/programas/DeepZoom/index20.html">FULL FINAL EXAMPLE!</a></p>
<p>Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/' rel='bookmark' title='DeepZoom &amp; SEADragon (II)'>DeepZoom &#038; SEADragon (II)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iii/' rel='bookmark' title='DeepZoom &amp; SEADragon (III)'>DeepZoom &#038; SEADragon (III)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/' rel='bookmark' title='DeepZoom &amp; SEADragon (I)'>DeepZoom &#038; SEADragon (I)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iv/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DeepZoom &amp; SEADragon (III)</title>
		<link>http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iii/</link>
		<comments>http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iii/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 07:35:47 +0000</pubDate>
		<dc:creator>Miguel</dc:creator>
				<category><![CDATA[Informática - web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[deep zoom]]></category>
		<category><![CDATA[deepzoom]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[logo]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[seadragon]]></category>

		<guid isPermaLink="false">http://www.leccionespracticas.com/?p=612</guid>
		<description><![CDATA[These days we were talking about DeepZoom, SeaDragon and jCarousel. Refer to [1] DeepZoom &#038; SEADragon part one and [2] DeepZoom &#038; SEADragon part two. How to remove the SEADragon logo from the viewer? Well, that is REALLY simple indeed First, open your seadragon-branded.js (in my examples it is located under ajax/0.8/. Go to line [...]
Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ajax-add-new-button-with-on-hover-changing-style/' rel='bookmark' title='DeepZoom &amp; Seadragon AJAX: add new button with on-hover-changing-style'>DeepZoom &#038; Seadragon AJAX: add new button with on-hover-changing-style</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/' rel='bookmark' title='DeepZoom &amp; SEADragon (II)'>DeepZoom &#038; SEADragon (II)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/' rel='bookmark' title='DeepZoom &amp; SEADragon (I)'>DeepZoom &#038; SEADragon (I)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>These days we were talking about DeepZoom, SeaDragon and jCarousel. Refer to<br />
<a href="http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/">[1] DeepZoom &#038; SEADragon part one</a> and<br />
<a href="http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/">[2] DeepZoom &#038; SEADragon part two</a>.</p>
<h3>How to remove the SEADragon logo from the viewer?</h3>
<p>Well, that is REALLY simple indeed <img src='http://www.leccionespracticas.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<ul>
<li>First, open your <code>seadragon-branded.js</code> (in my examples it is located under <code>ajax/0.8/</code>.</li>
<li>Go to line 275. It should be something like<br />
<code></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: #003366; font-weight: bold;">function</span> init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>self.<span style="color: #660066;">addControl</span><span style="color: #009900;">&#40;</span>logoControl<span style="color: #339933;">,</span>Seadragon.<span style="color: #660066;">ControlAnchor</span>.<span style="color: #660066;">BOTTOM_LEFT</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>logoControl.<span style="color: #660066;">style</span>.<span style="color: #660066;">marginLeft</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;4px&quot;</span><span style="color: #339933;">;</span>logoControl.<span style="color: #660066;">style</span>.<span style="color: #660066;">marginBottom</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;4px&quot;</span><span style="color: #339933;">;</span>self.<span style="color: #660066;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;open&quot;</span><span style="color: #339933;">,</span>introAnimationSetup<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p></code>
<li>
<li>Just comment the adding of the <code>logoControl</code>. The final code should be like this:<br />
<code></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: #003366; 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: #006600; font-style: italic;">/*self.addControl(logoControl,Seadragon.ControlAnchor.BOTTOM_LEFT);logoControl.style.marginLeft=&quot;4px&quot;;logoControl.style.marginBottom=&quot;4px&quot;;self.addEventListener(&quot;open&quot;,introAnimationSetup);*/</span><span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p></code>
<li>
</ul>
<p>That&#8217;s all folks! <img src='http://www.leccionespracticas.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ajax-add-new-button-with-on-hover-changing-style/' rel='bookmark' title='DeepZoom &amp; Seadragon AJAX: add new button with on-hover-changing-style'>DeepZoom &#038; Seadragon AJAX: add new button with on-hover-changing-style</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/' rel='bookmark' title='DeepZoom &amp; SEADragon (II)'>DeepZoom &#038; SEADragon (II)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/' rel='bookmark' title='DeepZoom &amp; SEADragon (I)'>DeepZoom &#038; SEADragon (I)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iii/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>DeepZoom &amp; SEADragon (II)</title>
		<link>http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/</link>
		<comments>http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 07:23:01 +0000</pubDate>
		<dc:creator>Miguel</dc:creator>
				<category><![CDATA[Informática - web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[deep zoom]]></category>
		<category><![CDATA[deepzoom]]></category>
		<category><![CDATA[jcarousel]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[seadragon]]></category>

		<guid isPermaLink="false">http://www.leccionespracticas.com/?p=604</guid>
		<description><![CDATA[In my previous DeepZoom &#038; SeaDragon post I explained how to build a web gallery using SEADragon. Show thumbs in JCarousel I dont like the thumbs to be displayed all at once, so I decided to use a jCarousel instead. jCarousel is a jQuery plugin for controlling a list of items in horizontal or vertical [...]
Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/' rel='bookmark' title='DeepZoom &amp; SEADragon (I)'>DeepZoom &#038; SEADragon (I)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iv/' rel='bookmark' title='DeepZoom &amp; SEADragon (IV)'>DeepZoom &#038; SEADragon (IV)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iii/' rel='bookmark' title='DeepZoom &amp; SEADragon (III)'>DeepZoom &#038; SEADragon (III)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>In my previous <a href="http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/">DeepZoom &#038; SeaDragon post</a> I explained how to build a web gallery using SEADragon.</p>
<h3>Show thumbs in JCarousel</h3>
<p>I dont like the thumbs to be displayed all at once, so I decided to use a <a href="http://sorgalla.com/jcarousel/">jCarousel</a> instead. <i>jCarousel is a jQuery plugin for controlling a list of items in horizontal or vertical order. The items, which can be static HTML content or loaded with (or without) AJAX, can be scrolled back and forth (with or without animation).</i></p>
<p>jCarousel is quite simple to use. In order to have a carousel you include the JCarousel libraries (available for download in ) and build a code like the following.<br />
<code></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="html" style="font-family:monospace;">&lt;ul id=&quot;mycarousel&quot; class=&quot;jcarousel-skin-tango&quot;&gt;
    &lt;li&gt;&lt;img src=&quot;http://static.flickr.com/66/199481236_dc98b5abb3_s.jpg&quot; width=&quot;75&quot; height=&quot;75&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
    &lt;li&gt;&lt;img src=&quot;http://static.flickr.com/75/199481072_b4a0d09597_s.jpg&quot; width=&quot;75&quot; height=&quot;75&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
    &lt;li&gt;&lt;img src=&quot;http://static.flickr.com/57/199481087_33ae73a8de_s.jpg&quot; width=&quot;75&quot; height=&quot;75&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
    &lt;li&gt;&lt;img src=&quot;http://static.flickr.com/77/199481108_4359e6b971_s.jpg&quot; width=&quot;75&quot; height=&quot;75&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
    &lt;li&gt;&lt;img src=&quot;http://static.flickr.com/58/199481143_3c148d9dd3_s.jpg&quot; width=&quot;75&quot; height=&quot;75&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
    &lt;li&gt;&lt;img src=&quot;http://static.flickr.com/72/199481203_ad4cdcf109_s.jpg&quot; width=&quot;75&quot; height=&quot;75&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
  &lt;/ul&gt;</pre></td></tr></table></div>

<p></code></p>
<p>Its very simple: an <code>&lt;il&gt;</code> for each <code>&lt;img&gt;</code>, everything wrapped in an <code>&lt;ul&gt;</code> called, for instance, <code>mycarousel</code>.</p>
<p>You can see a super-simple example of JCarousel <a href="http://sorgalla.com/projects/jcarousel/examples/static_simple.html">HERE</a>.</p>
<h3>JCarousel &#038; SEADragon</h3>
<p>Before you continue reading you should understand the code shown in<br />
<a href="http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/">my first DeepZoom &#038; SeaDragon post</a>. You can see it working <a href="http://www.leccionespracticas.com/programas/DeepZoom/index2.html">HERE</a>.</p>
<p>The modifications to show the thumbs in a JCarousel are quite simple (I will only show the relevant part of the new code):</p>
<p><code></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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;ajax/0.8/seadragon-branded.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;data2.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
                    var viewerDiv = document.getElementById('viewer');  
                    var thumbsDiv = document.getElementById('thumbs');
                    var titleDiv = document.getElementById('title');
                    var descDiv = document.getElementById('desc');
		    var botonesDiv = document.getElementById('botones');
                    viewerDiv.innerHTML = &quot;&quot;;       // for the CMS
                    var viewer = new Seadragon.BrandedViewer(viewerDiv);   
                    var selectedItem = null;
&nbsp;
    		    var thumbsPath = 'http://155.210.85.31/dzi/miguel/mini/'; 
&nbsp;
                    function doOpen(item, anchor)
                    {
                        if(selectedItem)
                            selectedItem.button.src = thumbsPath + selectedItem.thumb + '_rest.png';
&nbsp;
                        if(item)
                        {
                            viewer.openDzi(item.dzi, item.xml);
                            titleDiv.innerHTML = item.title;
                            descDiv.innerHTML = item.desc;
&nbsp;
                            item.button.src = thumbsPath + item.thumb + '_selected.png';
                            selectedItem = item;
&nbsp;
                            if (anchor) {
                                window.location.hash = &quot;#&quot; + item.thumb;
                            }
                        }
                    }
&nbsp;
&nbsp;
		    /* here begins the IMPORTANT PART... */
		    var ul = document.createElement('ul');
                    ul.id    = &quot;mycarousel&quot;;
		    ul.className = &quot;jcarousel-skin-tango&quot;;
		    thumbsDiv.appendChild(ul);
&nbsp;
                    var count = data.length;
                    var dataMap = {};
                    var a;
&nbsp;
&nbsp;
		     for (a = 0; a &lt; count; a++)
                    {
                        var item = data[a];
                        var image = document.createElement('img');
&nbsp;
                        // index item by its thumb name
                        dataMap[item.thumb] = item;
&nbsp;
                        image.src = thumbsPath + item.thumb + '_rest.png';
                        image.className = &quot;thumb&quot;;
&nbsp;
                        image.title = item.title;
                        image.id = a;
			image.name = a;
&nbsp;
                        Seadragon.Utils.addEvent(image, &quot;click&quot;,
                                Seadragon.Utils.createCallback(null, doOpen, item, true));
&nbsp;
                        thumbsDiv.appendChild(image);
                        item.button = image;
&nbsp;
			var li = document.createElement('li');
			li.appendChild(image);
&nbsp;
			ul.appendChild(li);
                    }
&nbsp;
                    // if the page's hash is set, open image with that hash
                    // if there is one. otherwise, just open the first image.
                    // note that if there's a hash, it'll begin with #.
                    var hash = (window.location.hash || &quot; &quot;).substr(1);
                    doOpen(dataMap[hash] || data[0], false);    // don't anchor
&nbsp;
                &lt;/script&gt;
                &lt;script type=&quot;text/javascript&quot;&gt; 
                     jQuery(document).ready(function() {
                            jQuery('#mycarousel').jcarousel();
                     });
				&lt;/script&gt;
&lt;/div&gt;</pre></td></tr></table></div>

<p></code></p>
<ul>
<li>Lines 36 to 40 create the new <code>&lt;ul&gt;</code> and append it to the <code>thumbsDiv</code></li>
<li>Lines 68 to 71 create every <code>&lt;li&gt;</code> element and append it to the recently created <code>&lt;ul&gt;</code></li>
<li>Lines 81 to 85 create the jCarousel using jQuery</li>
<li>Note1: in the <a href="http://www.leccionespracticas.com/programas/DeepZoom/index2.html">previous version of the code we used <code>x</code> and <code>y</code> variables (defined in lines 134, 135 and used to set the thumbs position -lines 147, 148- so the thumbs where shown in rows of ten elements). These variables are no longer needed, as the thums are managed by jCarousel.
<p>Now you can see a full working example <a href="http://www.leccionespracticas.com/programas/DeepZoom/index8.html">HERE</a>.</p>
<p>In my next article I will explain how to remove the annoying SEADragon logo in the bottom left of the viewer <img src='http://www.leccionespracticas.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/' rel='bookmark' title='DeepZoom &amp; SEADragon (I)'>DeepZoom &#038; SEADragon (I)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iv/' rel='bookmark' title='DeepZoom &amp; SEADragon (IV)'>DeepZoom &#038; SEADragon (IV)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iii/' rel='bookmark' title='DeepZoom &amp; SEADragon (III)'>DeepZoom &#038; SEADragon (III)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>DeepZoom &amp; SEADragon (I)</title>
		<link>http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/</link>
		<comments>http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 10:23:23 +0000</pubDate>
		<dc:creator>Miguel</dc:creator>
				<category><![CDATA[Informática - web]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[deep zoom]]></category>
		<category><![CDATA[deepzoom]]></category>
		<category><![CDATA[dzi]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[seadragon]]></category>
		<category><![CDATA[tiles]]></category>

		<guid isPermaLink="false">http://www.leccionespracticas.com/?p=582</guid>
		<description><![CDATA[There are plenty of times when you want to see something closer, to get a good look at the texture of a sculpture, or find out if that&#8217;s a reflection or a scratch on that used car you&#8217;re looking at. Seadragon, implemented as the Deep Zoom feature of Silverlight, allows you to do that. But [...]
Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/' rel='bookmark' title='DeepZoom &amp; SEADragon (II)'>DeepZoom &#038; SEADragon (II)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iv/' rel='bookmark' title='DeepZoom &amp; SEADragon (IV)'>DeepZoom &#038; SEADragon (IV)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iii/' rel='bookmark' title='DeepZoom &amp; SEADragon (III)'>DeepZoom &#038; SEADragon (III)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>There are plenty of times when you want to see something closer, to get a good look at the texture of a sculpture, or find out if that&#8217;s a reflection or a scratch on that used car you&#8217;re looking at.<br />
<a href="http://livelabs.com/seadragon-ajax/">Seadragon</a>, implemented as the <a href="http://msdn.microsoft.com/en-us/library/cc645050(VS.95).aspx">Deep Zoom</a> feature of <a href="http://www.microsoft.com/silverlight/overview/whatis.aspx">Silverlight</a>, allows you to do that.  But what if you&#8217;re not using the Silverlight platform?  That&#8217;s what Seadragon Ajax is for.</p>
<p>Seadragon Ajax, written from the ground up in JavaScript,  gives you the ability to add a Deep Zoom viewer into your blog, web site, or even your eBay listing. </p>
<p>Let&#8217;s see an example of how this works.</p>
<p>First of all, you should be confortable with the <a href="http://schemas.microsoft.com/deepzoom/2008">DZI (deep zoom image) Schema definition</a> and you should download <a href="http://www.microsoft.com/downloads/details.aspx?familyid=457b17b7-52bf-4bda-87a3-fa8a4673f8bf&#038;displaylang=en">Microsoft&#8217;s DeepZoom composer</a> and, of course, read its manual.</p>
<h3>The DeepZoom generated files</h3>
<p>Lets suppose you have done all this and generated a new dzi image. Now you should have a directory (I call it <code>./pagina1</code>) which looks like this:<br />
<a href='http://img196.imageshack.us/i/directoriopaginadzi.jpg/'><img src='http://img196.imageshack.us/img196/7464/directoriopaginadzi.jpg' border='0' alt='Deep Zoom Composer results'/></a><br/></p>
<p>Let&#8217;s take a closer look at this files:</p>
<ul>
<li><b>dzc_output.xml</b>: this is just a file which shows the XSD used and the image-related data, such as width, height, tilesize, etc&#8230;<br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #000000; font-weight: bold;">&lt;Image</span> <span style="color: #000066;">TileSize</span>=<span style="color: #ff0000;">&quot;256&quot;</span> <span style="color: #000066;">Overlap</span>=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #000066;">Format</span>=<span style="color: #ff0000;">&quot;jpg&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/deepzoom/2008&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;Size</span> <span style="color: #000066;">Width</span>=<span style="color: #ff0000;">&quot;1820&quot;</span> <span style="color: #000066;">Height</span>=<span style="color: #ff0000;">&quot;2312&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/Image<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p></code>
</li>
<li><b>SparseSceneImageGraph</b>: this file contains information related to generation of the image tile.<br />
<code></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SceneGraph</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;AspectRatio<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0,78719723183391<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/AspectRatio<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SceneNode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;FileName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>C:\Documents and Settings\jrey\Mis documentos\Expression\Deep Zoom Composer Projects\ANTIFON2\Source Images\ms00418_0001.jpg<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/FileName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;x<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/x<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;y<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/y<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Width<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Width<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Height<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Height<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ZOrder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ZOrder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SceneNode<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SceneGraph<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p></code></li>
<li><b><a href="/programas/DeepZoom/pagina1/scene.xml">scene.xml</a></b>: this file indicates how the tiles are composed to obtain complete images. The composed image takes into account the zoom level.
</li>
<li><b>dzc_output_files</b>: it contains the tiles in a directory structure like this:<br />
<a href='http://img7.imageshack.us/i/estructuradzcoutputimag.jpg/'><img src='http://img7.imageshack.us/img7/1791/estructuradzcoutputimag.jpg' border='0' alt='Deep Zoom dzc_output_images folder'/></a><br/>
</li>
</ul>
<h3>Aditional and necessary files</h3>
<p>First of all, download and unzip <a href="/programas/DeepZoom/ajax+lib+img.rar">the seadragon viewer and some other files</a> to the parent directory.</p>
<p>You must create the thumbnails for the page too. The parent directory of thumnails must be called <code>mini</code>. For each image we will have two images: for instance, for <code>thumb</code> called <code>pagina1</code> we will generate the thumbnails <code><a href="./mini/pagina1_rest.png">pagina1_rest.png</a></code> and <code><a href="./mini/pagina1_selected.png">pagina1 _selected.png</a></code>.</p>
<p>Now, you must build a file (I call it <code>data2.js</code>) which contains a directory structure like the one showed above for each image.<br />
Here is an example of <code>data2.js</code> file which tells SEADragon the <code>title</code> of the image, the <code>thumb</code>, which points to the folder containing the structure (this is, <code>pagina1</code>), the <code>description</code> for that image and where to find the <code>dzi</code> file and the <code>xml</code> contents of that <code>dzi</code> file.</p>
<p><code></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="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span>
    <span style="color: #009900;">&#123;</span>
        title<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Antifonario moz&amp;aacute;rabe'</span><span style="color: #339933;">,</span>
        thumb<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pagina1'</span><span style="color: #339933;">,</span>
        desc<span style="color: #339933;">:</span> <span style="color: #3366CC;">'Antifonario moz&amp;aacute;rabe: p&amp;aacute;gina 1. Procede del Monasterio de San Juan de la Pe&amp;ntilde;a'</span><span style="color: #339933;">,</span>
        dzi<span style="color: #339933;">:</span> <span style="color: #3366CC;">'pagina1/dzc_output.xml'</span><span style="color: #339933;">,</span>
        xml<span style="color: #339933;">:</span> <span style="color: #3366CC;">'&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;Image TileSize=&quot;256&quot; Overlap=&quot;1&quot; Format=&quot;jpg&quot; xmlns=&quot;http://schemas.microsoft.com/deepzoom/2008&quot;&gt;&lt;Size Width=&quot;1820&quot; Height=&quot;2312&quot; /&gt;&lt;/Image&gt;'</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#93;</span></pre></td></tr></table></div>

<p></code></p>
<h3>How to use it in a web page</h3>
<p>Now that are familiar to the directory structure and the generated files, lets face the problem of generating an html page which shows the files.<br />
<code></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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
	&lt;head&gt;
&nbsp;
&lt;script type=&quot;text/javascript&quot;&gt;var _sf_startpt=(new Date()).getTime()&lt;/script&gt;  
&nbsp;
		&lt;title&gt;Gallery : Microsoft Live Labs&lt;/title&gt;
		&lt;link rel=&quot;stylesheet&quot; href=&quot;/files/themes/labs/styles.css&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&nbsp;
&nbsp;
&lt;link rel=&quot;EditURI&quot; type=&quot;application/rsd+xml&quot; title=&quot;RSD&quot; href=&quot;http://livelabs.com/api/rsd.ashx&quot; /&gt;
&lt;link rel=&quot;wlwmanifest&quot; type=&quot;application/wlwmanifest+xml&quot; title=&quot;WLWManifest&quot; href=&quot;http://livelabs.com/api/wlwmanifest.ashx&quot; /&gt;
&nbsp;
&lt;/head&gt;
&lt;body&gt;
&nbsp;
	&lt;div id=&quot;wrapper&quot;&gt;
&nbsp;
	&lt;div id=&quot;content_box&quot;&gt; 
		&lt;div id=&quot;content_area&quot; &gt;
&nbsp;
&lt;div id=&quot;middle_column&quot; class=&quot;content_double_column&quot;&gt;
&nbsp;
&lt;!-- CMS Start --&gt;
&lt;p&gt;&lt;style type=&quot;text/css&quot;&gt;
&nbsp;
                    #viewer
                    {
                        width: 640px;   
                        height: 480px;  
                        background-color: black;
                        color: white;   /* for error messages, etc. */ 
                        /* border -- on all sides */
                        border: 1px solid black
                    }
&nbsp;
                    #metadata
                    {
                        /* dimensions */
                        /*width: 564px;   /* plus (1px border + 7px padding) on each side */
			width: 626px;
                        height: 80px;
                        padding: 7px;
&nbsp;
                        /* color */
                        background-color: #888888;
                        color: white;
&nbsp;
                        /* border -- don't duplicate border with viewer */
                        border-bottom: 1px solid black;
                        border-left: 1px solid black;
                        border-right: 1px solid black;
                    }
&nbsp;
                    #metadata #title
                    {
                        font-size: large;
                    }
&nbsp;
                    #metadata #desc
                    {
                        font-size: small;
                    }
&nbsp;
                    #desc a:link, 
                    #desc a:visited, 
                    #desc a:hover, 
                    #desc a:active
                    {
                        color:#ffffff;
                        text-decoration:underline;
                    }
&nbsp;
                    #thumbs
                    {
                        width: 580px;
                        margin-top: 20px;
                    }
&nbsp;
                    .thumb
                    {
                        position: relative;
                        cursor: pointer;
                    }
&nbsp;
                &lt;/style&gt;&lt;/p&gt;
&lt;div id=&quot;viewer&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;div id=&quot;metadata&quot;&gt;
&lt;div&gt;
&lt;div id=&quot;title&quot;&gt;&amp;nbsp;&lt;/div&gt;
&nbsp;
&lt;div id=&quot;desc&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;thumbs&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;ajax/0.8/seadragon-branded.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;data2.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
&nbsp;
                    var viewerDiv = document.getElementById('viewer');  
                    var thumbsDiv = document.getElementById('thumbs');
                    var titleDiv = document.getElementById('title');
                    var descDiv = document.getElementById('desc');
&nbsp;
                    viewerDiv.innerHTML = &quot;&quot;;       // for the CMS
&nbsp;
                    var viewer = new Seadragon.BrandedViewer(viewerDiv);   
                    var selectedItem = null;
		    var thumbsPath = './mini/'; 
&nbsp;
                    function doOpen(item, anchor)
                    {
                        if(selectedItem)
                            selectedItem.button.src = thumbsPath + selectedItem.thumb + '_rest.png';
&nbsp;
                        if(item)
                        {
                            viewer.openDzi(item.dzi, item.xml);
                            titleDiv.innerHTML = item.title;
                            descDiv.innerHTML = item.desc;
&nbsp;
                            item.button.src = thumbsPath + item.thumb + '_selected.png';
                            selectedItem = item;
&nbsp;
                            if (anchor) {
                                window.location.hash = &quot;#&quot; + item.thumb;
                            }
                        }
                    }
&nbsp;
                    var count = data.length;
                    var dataMap = {};
                    var a;
                    var x = 0; 
                    var y = 0;
&nbsp;
                    for (a = 0; a &lt; count; a++)
                    {
                        var item = data[a];
                        var image = document.createElement('img');
&nbsp;
                        // index item by its thumb name
                        dataMap[item.thumb] = item;
&nbsp;
                        image.src = thumbsPath + item.thumb + '_rest.png';
                        image.className = &quot;thumb&quot;;
                        image.style.left = (16 * x) + 'px';
                        image.style.top = (16 * y) + 'px';
                        image.title = item.title;
&nbsp;
                        Seadragon.Utils.addEvent(image, &quot;click&quot;,
                                Seadragon.Utils.createCallback(null, doOpen, item, true));
&nbsp;
                        thumbsDiv.appendChild(image);
                        item.button = image;
&nbsp;
                        x++;
                        if(x &gt;= 9)
                        {
                            x = 0;
                            y++;
                            var br = document.createElement('br');
                            thumbsDiv.appendChild(br);
                        }
                    }
&nbsp;
                    // if the page's hash is set, open image with that hash
                    // if there is one. otherwise, just open the first image.
                    // note that if there's a hash, it'll begin with #.
                    var hash = (window.location.hash || &quot; &quot;).substr(1);
                    doOpen(dataMap[hash] || data[0], false);    // don't anchor
&nbsp;
                &lt;/script&gt;&lt;!-- CMS End --&gt;
&nbsp;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&nbsp;
&lt;div id=&quot;cap_bottom&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&nbsp;
&lt;/div&gt;&lt;!-- END wrapper --&gt;
&nbsp;
&nbsp;
	&lt;!-- SiteCatalyst code version: H.1. Copyright 1997-2005 Omniture, Inc. More info available at http://www.omniture.com --&gt;
  &lt;script language=&quot;JavaScript&quot;&gt;var s_account=&quot;msnportallivelabs&quot;;&lt;/script&gt;
  &lt;script language=&quot;JavaScript&quot; src=&quot;http://stj.msn.com/br/om/js/s_code.js&quot;&gt;&lt;/script&gt;
  &lt;script language=&quot;JavaScript&quot;&gt;
    &lt;!--
        s.linkInternalFilters=&quot;javascript:,.live.,.livelabs.&quot;;s.trackExternalLinks=true;
    s.server=&quot;livelabs.com&quot;;s.channel=&quot;livelabs.com&quot;;
        s.prop1=&quot;livelabs.com&quot;;s.prop2=&quot;en-us&quot;;
        /************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
        var s_code=s.t();if(s_code)document.write(s_code)//--&gt;
  &lt;/script&gt;
&nbsp;
  &lt;script language=&quot;JavaScript&quot;&gt; &lt;!-- if(navigator.appVersion.indexOf('MSIE')&gt;=0)document.write(unescape('%3C')+'\!-'+'-')//--&gt; &lt;/script&gt;
  &lt;noscript&gt;
    &lt;img src=&quot;http://msnportallivelabs.112.2O7.net/b/ss/msnportallivelabs/1/H.1--NS/0&quot; height=&quot;1&quot; width=&quot;1&quot; border=&quot;0&quot; alt=&quot;&quot; /&gt;
  &lt;/noscript&gt;
  &lt;!--/DO NOT REMOVE/--&gt;
  &lt;!-- End SiteCatalyst code version: H.1. --&gt;
	&lt;/body&gt;
&nbsp;
&lt;/html&gt;</pre></td></tr></table></div>

<p></code></p>
<p>If you are familiar with javascript and html the code shown is quite self-explainable.</p>
<p>You can <a href="http://www.leccionespracticas.com/programas/DeepZoom/index2.html">see a working example here</a>.</p>
<p>IMHO the thumnails visualization quite ugly, so I decided to add a <a href="http://sorgalla.com/projects/jcarousel/">JCarousel</a> to view these thumnails. This process is quite simple. I will show it how to do it in a subsequent post <img src='http://www.leccionespracticas.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<h3>Want to know more about Deep Zoom images?</h3>
<p>Visit the following links:<br />
<a href="http://gasi.ch/blog/inside-deep-zoom-2/">[1] Detailed mathematical explanation on how the tile algorithm works</a><br />
<a href="http://blog.kapilt.com/2008/11/30/viewing-large-images-openlayers-gsiv-modestmaps-deepzoom-and-python/">[2] Python implementation of Deep Zoom tile images</a><br />
<a href="http://blogs.msdn.com/lutzg/archive/2008/11/23/seadragon-ajax-and-deep-zoom.aspx">More interesting info</a></p>
<p>Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/' rel='bookmark' title='DeepZoom &amp; SEADragon (II)'>DeepZoom &#038; SEADragon (II)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iv/' rel='bookmark' title='DeepZoom &amp; SEADragon (IV)'>DeepZoom &#038; SEADragon (IV)</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-iii/' rel='bookmark' title='DeepZoom &amp; SEADragon (III)'>DeepZoom &#038; SEADragon (III)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-i/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Peticiones AJAX a SERVIDORES EXTERNOS</title>
		<link>http://www.leccionespracticas.com/javascript/haciendo-proxy-con-js/</link>
		<comments>http://www.leccionespracticas.com/javascript/haciendo-proxy-con-js/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 12:29:46 +0000</pubDate>
		<dc:creator>miguel</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[http request]]></category>
		<category><![CDATA[php proxy]]></category>
		<category><![CDATA[proxy]]></category>

		<guid isPermaLink="false">http://miguelmartin.x10hosting.com/blog/?p=224</guid>
		<description><![CDATA[El otro día os hablaba de cómo invocar servicios de nuestro propio servidor usando request&#8217;s de Ajax. Podéis ver un ejemplo de código que realiza peticiones Ajax [AQUI]. Como véis, NO FUNCIONA. Si utilizáis firebug veréis que la ejecución llega hasta la línea 27. 1 2 3 4 5 6 7 8 9 10 11 [...]
Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/ajax-i-peticiones-http-http-requests/' rel='bookmark' title='Ajax (I): peticiones HTTP &#8211; HTTP Requests'>Ajax (I): peticiones HTTP &#8211; HTTP Requests</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ajax-add-new-button-with-on-hover-changing-style/' rel='bookmark' title='DeepZoom &amp; Seadragon AJAX: add new button with on-hover-changing-style'>DeepZoom &#038; Seadragon AJAX: add new button with on-hover-changing-style</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/' rel='bookmark' title='DeepZoom &amp; SEADragon (II)'>DeepZoom &#038; SEADragon (II)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>El otro día os hablaba de cómo invocar servicios de nuestro propio servidor usando request&#8217;s de Ajax</a>.</p>
<p>Podéis ver un ejemplo de código que realiza peticiones Ajax <a href="http://www.leccionespracticas.com/trabajo/buscador_zaguan.php">[AQUI]</a>. Como véis, <font color="red">NO FUNCIONA</font>. Si utilizáis <a href="https://addons.mozilla.org/es-ES/firefox/addon/1843">firebug</a> veréis que la ejecución llega hasta la línea 27.</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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> makeRequest<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span>param<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
               url <span style="color: #339933;">=</span> url <span style="color: #339933;">+</span> param<span style="color: #339933;">;</span>
               http_request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
               <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">XMLHttpRequest</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// Mozilla, Safari,...</span>
                  http_request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</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>http_request.<span style="color: #660066;">overrideMimeType</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                      http_request.<span style="color: #660066;">overrideMimeType</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'text/html'</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: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">ActiveXObject</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">// IE</span>
                  <span style="color: #000066; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span> http_request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Msxml2.XMLHTTP&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;">catch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #000066; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
                           http_request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Microsoft.XMLHTTP&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;">catch</span> <span style="color: #009900;">&#40;</span>e2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
                   <span style="color: #009900;">&#125;</span>
               <span style="color: #009900;">&#125;</span>
               <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>http_request<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                  <span style="color: #006600; font-style: italic;">// uncomment next line if you want to show any error messages</span>
                  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Cannot create XMLHTTP instance'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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: #006600; font-style: italic;">//alert(&quot;makeRequest(): url='&quot;+url+&quot;'&quot;);</span>
               http_request.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> fromServer<span style="color: #339933;">;</span>
               <span style="color: #339933;">&lt;</span>b<span style="color: #339933;">&gt;</span>http_request.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'GET'</span><span style="color: #339933;">,</span> url<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #006600; font-style: italic;">// En este punto URL contiene una URL EXTERNA</span>
               <span style="color: #006600; font-style: italic;">//(fuera de nuestro servidor)&lt;/b&gt;</span>
               http_request.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span>param<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #000066; font-weight: bold;">return</span> http_request<span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Además, si abrimos la consola de errores de Firefox, veremos algo parecido a</p>
<pre><code>
Error de seguridad: el contenido en

http://www.leccionespracticas.com/trabajo/buscador_zaguan.php

no puede cargar datos de http://olmo.unizar.es/search?ln=es&#038;sc=1&#038;p=water.

Error: uncaught exception:
[Exception... "Access to restricted URI denied"  
code: "1012" nsresult: "0x805303f4 (NS_ERROR_DOM_BAD_URI)"
location: "http://www.leccionespracticas.com/trabajo/buscador_zaguan.php Line: 110"]
</code></pre>
<p>Buscando encontré <a href="http://developer.yahoo.com/javascript/howto-proxy.html">el manual para hacer proxy desde javascript</a>.</p>
<p>Ésto me dio la pista definitiva para solucionar el problema. Os cuento cómo lo he resuelto:</p>
<p>1. Creo el archivo <code>php_proxy2.php</code> con <a href="http://www.leccionespracticas.com/trabajo/php_proxy2.php.txt">[éste código fuente]</a> y MODIFICAMOS <code>$vfile</code>añadiendo la url BASE del sitio web <u>al que queremos invocar</u> mediante Ajax, esto es:<br />
<code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
   <span style="color: #339933;">&lt;</span>font color<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;red&quot;</span><span style="color: #339933;">&gt;</span>   <span style="color: #000088;">$vfile</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://olmo.unizar.es&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Esta línea tiene la URL base del sitio &lt;/font&gt;</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dst'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         <span style="color: #000088;">$vfile</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$vfile</span><span style="color: #339933;">.</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'dst'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #990000;">readfile</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$vfile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
?<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span></pre></div></div>

<p></code></p>
<p><b>Nota:</b> Además, por <b>motivos de seguridad</b> es <font color="red">IMPRESCINDIBLE</font> que utilicéis este parámetro base, ya que sino vuestra máquina se podría convertir en un proxy -desde el que se podrían hacer <em>cosas malas, you know what I mean</em>-</p>
<p>2. Hago el encode de la URL que deseo invocar y se la paso como parámetro al proxy ANTES de invocar a <code><b>http_request.open</b></code> (mira la línea 26). Ésto es, modificamos la funcion <code>makeRequest</code>, que quedará asi:<br />
<code></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;">function</span> makeRequest<span style="color: #009900;">&#40;</span>url<span style="color: #339933;">,</span>param<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
               url <span style="color: #339933;">=</span> url <span style="color: #339933;">+</span> param<span style="color: #339933;">;</span>
               http_request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
               <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">XMLHttpRequest</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// Mozilla, Safari,...</span>
                  http_request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</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>http_request.<span style="color: #660066;">overrideMimeType</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                      http_request.<span style="color: #660066;">overrideMimeType</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'text/html'</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: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>window.<span style="color: #660066;">ActiveXObject</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #006600; font-style: italic;">// IE</span>
                  <span style="color: #000066; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span> http_request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Msxml2.XMLHTTP&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;">catch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                        <span style="color: #000066; font-weight: bold;">try</span><span style="color: #009900;">&#123;</span>
                           http_request <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> ActiveXObject<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Microsoft.XMLHTTP&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;">catch</span> <span style="color: #009900;">&#40;</span>e2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
                   <span style="color: #009900;">&#125;</span>
               <span style="color: #009900;">&#125;</span>
               <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>http_request<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                  <span style="color: #006600; font-style: italic;">// uncomment next line if you want to show any error messages</span>
                  <span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Cannot create XMLHTTP instance'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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>
               http_request.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> fromServer<span style="color: #339933;">;</span>
               <span style="color: #003366; font-weight: bold;">var</span> url_mod <span style="color: #339933;">=</span><span style="color: #3366CC;">'http://www.leccionespracticas.com/trabajo/php_proxy2.php?dst='</span> <span style="color: #339933;">+</span> encodeURIComponent<span style="color: #009900;">&#40;</span>param<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               http_request.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'GET'</span><span style="color: #339933;">,</span> url_mod<span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               http_request.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span>param<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
               <span style="color: #000066; font-weight: bold;">return</span> http_request<span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p></code></p>
<p>El resultado podéis verlo <a href="http://www.leccionespracticas.com/trabajo/buscador_zaguan_bueno.php">[EN ESTE LINK]</a></p>
<p>Ficheros utilizados en este tutorial:<br />
[1] Proxy PHP: <a href="http://www.leccionespracticas.com/trabajo/php_proxy2.php.txt">php_proxy2.php</a><br />
[2] Fichero ORIGINAL desde el que hago los Ajax Requests: <a href="http://www.leccionespracticas.com/trabajo/buscador_zaguan_bueno.php.txt">buscador_zaguan_bueno.php</a></p>
<p>Related posts:<ol>
<li><a href='http://www.leccionespracticas.com/informatica-web/ajax-i-peticiones-http-http-requests/' rel='bookmark' title='Ajax (I): peticiones HTTP &#8211; HTTP Requests'>Ajax (I): peticiones HTTP &#8211; HTTP Requests</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ajax-add-new-button-with-on-hover-changing-style/' rel='bookmark' title='DeepZoom &amp; Seadragon AJAX: add new button with on-hover-changing-style'>DeepZoom &#038; Seadragon AJAX: add new button with on-hover-changing-style</a></li>
<li><a href='http://www.leccionespracticas.com/informatica-web/deepzoom-seadragon-ii/' rel='bookmark' title='DeepZoom &amp; SEADragon (II)'>DeepZoom &#038; SEADragon (II)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.leccionespracticas.com/javascript/haciendo-proxy-con-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

