<?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>Cultura Digital#Blog &#187; Desarrollo web</title>
	<atom:link href="http://blog.culturadigital.org/temas/tecnologia/desarrollo-web/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.culturadigital.org</link>
	<description>Tener algo que decir; y decirlo.</description>
	<lastBuildDate>Mon, 26 Apr 2010 15:43:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Ticker (NewsTicker) con MooTools</title>
		<link>http://blog.culturadigital.org/tecnologia/desarrollo-web/ticker-newsticker-con-mootools</link>
		<comments>http://blog.culturadigital.org/tecnologia/desarrollo-web/ticker-newsticker-con-mootools#comments</comments>
		<pubDate>Sun, 25 Apr 2010 18:13:15 +0000</pubDate>
		<dc:creator>J.A.Cobo</dc:creator>
				<category><![CDATA[Desarrollo web]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[MooTools]]></category>
		<category><![CDATA[newsticker]]></category>
		<category><![CDATA[ticker]]></category>

		<guid isPermaLink="false">http://blog.culturadigital.org/?p=883</guid>
		<description><![CDATA[Como implementar un ticker de noticias, o cualquier listado sin importar las etiquetas de listas, con MooTools (habitualmente con efecto scroll).]]></description>
			<content:encoded><![CDATA[<h4>Contexto</h4>
<p>Hace poco tiempo que decidí cambiar de framework Javascript, en concreto desde que vi los problemas que <a hreflang="en" href="http://jquery.com/" title="Sitio web de jQuery">jQuery</a> tenía para trabajar con <a hreflang="en" href="http://www.w3.org/DOM/#what" title="Sitio web del W3C sobre el DOM"><abbr title="Document Object Model (Modelo de Objetos del Documento )" xml:lang="en">DOM</abbr></a> distinto de <abbr title="HyperText Markup Language (Lenguaje de Marcado de Hipertexto)" xml:lang="en">HTML</abbr>. Mi elección <a href="http://blog.culturadigital.org/proyectos-y-trabajos/proyectos-grandes-o-externos/1sctools" title="Proyecto 1SC/BETools">entonces</a> fue volver a <a hreflang="en" href="http://www.prototypejs.org/" title="Sitio web de Prototype">Prototype</a> para más tarde pasarme a <a hreflang="en" href="http://mootools.net/" title="Sitio web de MooTools">MooTools</a>.</p>
<h4>Objetivo</h4>
<p>Ahora estoy migrando el Javascript que uso en algunos sitios a esta librería, MooTools, y con esta entrada trato de ilustrar lo intuitivo y fácil que resulta trabajar con MooTools para extender Javascript y adaptarlo de una forma estándar a tus propósitos. Es, a diferencia de jQuery, para lo que está hecha esta librería.</p>
<h5>Newsticker</h5>
<p>Aunque es espectacular el ritmo de crecimiento de los plugins para MooTools en su sección Forge y en concreto los <em xml:lang="en">slideshow</em> de varios tipos, lo cierto es que no encontraba un <strong>scroll de noticias sencillo</strong> -técnicamente más conocidos como <em xml:lang="en">ticker</em> o <em xml:lang="en">newsticker</em>-.</p>
<p>Haberlos los hay, pero ninguno satisfacía mis necesidades pues: o generaban marcado que no me parecía correcto; o se basaban en procesos demasiado estrictos, demasiado complicados; o se basaban más bien en <abbr title="Cascading StyleSheets (Hojas de estilo en cascada)" xml:lang="en">CSS</abbr>. &#8230;O sea, <strong>todo demasiado estricto y yo solo quería implementar la funcionalidad para cualquier listado</strong> independientemente del estilo CSS asignado y de su marcado.<br />
Así que, como en otras ocasiones -en las BeTools por ejemplo- e inspirado en <a href="http://woork.blogspot.com/2009/05/how-to-implement-news-ticker-with.html" title="How to implement a news ticker with jQuery and ten lines of code" hreflang="en">la idea de Antonio Lupetti</a> para jQuery (es un ciclo de posiciones básicamente), decidí ponerme manos a la obra y reinventar la rueda porque a veces sigue siendo la mejor solución para conseguir exactamente lo que quieres, como en este caso.</p>
<h4>Código NewsTicker con MooTools</h4>
<p>Esta es la clase que he implementado, nada del otro mundo pero que me funciona perfecta y hace exactamente lo que quiero:</p>
<h5>Funcionalidad</h5>
<ul>
<li>Me permite <strong>aplicarlo a cualquier elemento que contenga hijos</strong>, ya sea un listado o no, aunque obviamente lo recomendable y más fiable son los listados.</li>
<li>Me permite <strong>mantener el estilo original</strong> de los elementos <strong>abstrayéndose</strong> de si se usan o no para el ticker. El ticker simplemente aplica el estilo mínimo para la funcionalidad, en este caso la visualización de un solo item del listado y de acuerdo a la altura original del elemento. Es decir, olvídate de anchos o altos estrictos preestablecidos, es la funcionalidad y punto.</li>
<li>El resto ya es lo normal: tiempo entre repeticiones, establecer un efecto, etc.</li>
</ul>
<p class="alert">Actualizado</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
</pre></td><td class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #006600; font-style: italic;">/**
 * MooTools NewsTicker by Covi.
 * 
 * Inspirado en la idea de Antonio Lupetti 
 * (http://woork.blogspot.com/2009/05/how-to-implement-news-ticker-with.html)
 *
 * @author Covi
 * @copyright 2010 J.A.Cobo (Covi)
 * @version 0.1beta
 * @todo Interfaz y extender para ticker pequeño, slideshow...
 *
 * @license MIT License http://www.opensource.org/licenses/mit-license.php
Copyright (c) 2010 J. A. Cobo Ruz (Covi), inspired by Antonio Lupetti cycle idea.
&nbsp;
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the &quot;Software&quot;), to deal in the
Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the
Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
&nbsp;
The above copyright notice and this permission notice
shall be included in all copies or substantial portions of
the Software.
&nbsp;
THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/</span>
<span style="color: #003366; font-weight: bold;">var</span> NewsTicker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Class</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
	Implements<span style="color: #339933;">:</span> Options<span style="color: #339933;">,</span>
&nbsp;
	options<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
		autostart<span style="color: #339933;">:</span> 		<span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> 		<span style="color: #006600; font-style: italic;">// Comenzar automático o no.</span>
		animation<span style="color: #339933;">:</span> 		<span style="color: #3366CC;">'fade'</span><span style="color: #339933;">,</span> 	<span style="color: #006600; font-style: italic;">// Tipo de animación, por el momento: fade, slide (mode:horizontal|vertical).</span>
		mode<span style="color: #339933;">:</span>			<span style="color: #3366CC;">'vertical'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// Para animación slide.</span>
		transition<span style="color: #339933;">:</span>		<span style="color: #3366CC;">'sine:out'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// TODO slide con transición expo da error pues no crea el div vacío.</span>
		speed<span style="color: #339933;">:</span> 			<span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span> 		<span style="color: #006600; font-style: italic;">// Velocidad de la transición en efectos.</span>
		periodical<span style="color: #339933;">:</span> 	<span style="color: #CC0000;">5000</span><span style="color: #339933;">,</span> 		<span style="color: #006600; font-style: italic;">// Periocidad de la iteración sobre los ítems.</span>
		padding<span style="color: #339933;">:</span>		<span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> 			<span style="color: #006600; font-style: italic;">// Aplicar espaciado a cada ítem si se desea (en un futuro será estilo completo).</span>
		fixedHeight<span style="color: #339933;">:</span>	<span style="color: #003366; font-weight: bold;">true</span>		<span style="color: #006600; font-style: italic;">// Alto fijo o flexible para adaptarse al alto de cada ítem.</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * Constructor
	 */</span>
	initialize<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>el<span style="color: #339933;">,</span> options<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">timer</span> 		<span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span> 	<span style="color: #339933;">=</span> el<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">setOptions</span><span style="color: #009900;">&#40;</span>options<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> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span> <span style="color: #009900;">&#41;</span> 
			<span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #003366; font-weight: bold;">new</span> Error<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'El contenedor de la lista no se encontró.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// # Setup container: Establecer el alto al primer hijo del container:</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span>.<span style="color: #660066;">setStyles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #3366CC;">'height'</span><span style="color: #339933;">:</span>	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span>.<span style="color: #660066;">getFirst</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">getComputedSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">totalHeight</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">padding</span>.<span style="color: #660066;">toInt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> 
			<span style="color: #3366CC;">'overflow'</span><span style="color: #339933;">:</span>	<span style="color: #3366CC;">'hidden'</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;">// Eventos y run...</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">autostart</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">run</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;">&#125;</span><span style="color: #339933;">,</span> 
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * Efecto.
	 * @access private
	 */</span>
	_animate<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> <span style="color: #000066; font-weight: bold;">item</span> 		<span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span>.<span style="color: #660066;">getFirst</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;">// Primer elemento del listado</span>
		<span style="color: #003366; font-weight: bold;">var</span> first 		<span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">clone</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;">// Clonar el ITEM ORIGINAL para situarlo al final</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Eliminar y efecto:</span>
		<span style="color: #000066; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">animation</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #006600; font-style: italic;">// # FADE:</span>
			<span style="color: #003366; font-weight: bold;">default</span><span style="color: #339933;">:</span>
			<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'fade'</span><span style="color: #339933;">:</span>
				<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tween'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
					duration<span style="color: #339933;">:</span> 	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">speed</span><span style="color: #339933;">,</span> 
					transition<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">transition</span><span style="color: #339933;">,</span> 
					onComplete<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;">this</span>._cycleItem<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> first<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">tween</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'opacity'</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">// # SLIDE:</span>
			<span style="color: #000066; font-weight: bold;">case</span> <span style="color: #3366CC;">'slide'</span><span style="color: #339933;">:</span>
				<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">set</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'slide'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
					duration<span style="color: #339933;">:</span> 	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">speed</span><span style="color: #339933;">,</span> 
					transition<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">transition</span><span style="color: #339933;">,</span> 
					mode<span style="color: #339933;">:</span> 		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">mode</span><span style="color: #339933;">,</span> 
					onComplete<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;">this</span>._cycleItem<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> first<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slide</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'out'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066; font-weight: bold;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * Ciclo: Eliminar el ítem y pasarlo al final.
	 * @access private
	 */</span>
	_cycleItem<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> first<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: #339933;">!</span>$chk<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>$chk<span style="color: #009900;">&#40;</span>first<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> 
			<span style="color: #000066; font-weight: bold;">return</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> itemHeight 	<span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">getComputedSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">totalHeight</span><span style="color: #339933;">;</span> 	<span style="color: #006600; font-style: italic;">// Alto del ítem para ajustar el container</span>
		<span style="color: #006600; font-style: italic;">// Eliminar y copiarlo al final:</span>
		<span style="color: #000066; font-weight: bold;">item</span>.<span style="color: #660066;">dispose</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span>.<span style="color: #660066;">grab</span><span style="color: #009900;">&#40;</span>first<span style="color: #339933;">,</span> <span style="color: #3366CC;">'bottom'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// FIXME Eliminar el div vacío que deja slide (para MooTools 1.2.6)</span>
		<span style="color: #006600; font-style: italic;">// @see https://mootools.lighthouseapp.com/projects/24057/tickets/194-fxslide-sometimes-clips-the-contents-of-divs</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'slide'</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">animation</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> wrongDivSlide <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span>.<span style="color: #660066;">getFirst</span><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> <span style="color: #3366CC;">'div'</span> <span style="color: #339933;">==</span> wrongDivSlide.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tag'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				wrongDivSlide.<span style="color: #660066;">dispose</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #003366; font-weight: bold;">var</span> nextItem 	<span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span>.<span style="color: #660066;">getFirst</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;">// Para el ajustar el alto del container, volvemos a coger el ítem superior.</span>
				itemHeight 		<span style="color: #339933;">=</span> nextItem.<span style="color: #660066;">getComputedSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">totalHeight</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'horizontal'</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">mode</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #003366; font-weight: bold;">var</span> myFx <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Fx.<span style="color: #660066;">Slide</span><span style="color: #009900;">&#40;</span>nextItem<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
						duration<span style="color: #339933;">:</span> 	<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">speed</span><span style="color: #339933;">,</span>
						transition<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">transition</span><span style="color: #339933;">,</span> 
						mode<span style="color: #339933;">:</span>		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">mode</span>
					<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					myFx.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">slideIn</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;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Si no se establece como alto fijo, ajustamos el alto del container:</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">fixedHeight</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">container</span>.<span style="color: #660066;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'height'</span><span style="color: #339933;">,</span> itemHeight<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: #339933;">,</span> 
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * Inicia el bucle para iterar sobre los ítems.
	 */</span>
	start<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;">this</span>.<span style="color: #660066;">timer</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span>._animate.<span style="color: #660066;">periodical</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">options</span>.<span style="color: #660066;">periodical</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * Detiene el bucle.
	 */</span>
	<span style="color: #000066;">stop</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>
		$clear<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">timer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> 
&nbsp;
	<span style="color: #006600; font-style: italic;">/**
	 * Lanza todo el proceso: establece, si procede, el bucle y los eventos.
	 */</span>
	run<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;">this</span>.<span style="color: #660066;">container</span>.<span style="color: #660066;">addEvents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #3366CC;">&quot;mouseover&quot;</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;">this</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 	<span style="color: #009900;">&#125;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #3366CC;">&quot;mouseout&quot;</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;">this</span>.<span style="color: #660066;">start</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: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">start</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;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h5>Uso</h5>
<p>Por ejemplo para elementos con la clase newsticker:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">$$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.newsticker'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> myTicker <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> NewsTicker<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">item</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
		periodical<span style="color: #339933;">:</span>		<span style="color: #CC0000;">5000</span><span style="color: #339933;">,</span> 
		animation<span style="color: #339933;">:</span>		<span style="color: #3366CC;">'slide'</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h6>Opciones</h6>
<p>Las opciones, valga la redundancia, son opcionales ya que se establecen las siguientes por defecto:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">options<span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>
		autostart<span style="color: #339933;">:</span> 		<span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> 		<span style="color: #006600; font-style: italic;">// Comenzar automático o no.</span>
		animation<span style="color: #339933;">:</span> 		<span style="color: #3366CC;">'fade'</span><span style="color: #339933;">,</span> 	<span style="color: #006600; font-style: italic;">// Tipo de animación, por el momento: fade, slide (mode:horizontal|vertical).</span>
		mode<span style="color: #339933;">:</span>			<span style="color: #3366CC;">'vertical'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// Para animación slide.</span>
		transition<span style="color: #339933;">:</span>		<span style="color: #3366CC;">'sine:out'</span><span style="color: #339933;">,</span> <span style="color: #006600; font-style: italic;">// TODO slide con transición expo da error pues no crea el div vacío.</span>
		speed<span style="color: #339933;">:</span> 			<span style="color: #CC0000;">1000</span><span style="color: #339933;">,</span> 		<span style="color: #006600; font-style: italic;">// Velocidad de la transición en efectos.</span>
		periodical<span style="color: #339933;">:</span> 	<span style="color: #CC0000;">5000</span><span style="color: #339933;">,</span> 		<span style="color: #006600; font-style: italic;">// Periocidad de la iteración sobre los ítems.</span>
		padding<span style="color: #339933;">:</span>		<span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> 			<span style="color: #006600; font-style: italic;">// Aplicar espaciado a cada ítem si se desea (en un futuro será estilo completo).</span>
		fixedHeight<span style="color: #339933;">:</span>	<span style="color: #003366; font-weight: bold;">true</span>		<span style="color: #006600; font-style: italic;">// Alto fijo o flexible para adaptarse al alto de cada ítem.</span>
	<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<ul>
<li>(Boolean) <strong>Autostart</strong> (true): <em>true|false</em>. Comenzar o no automáticamente, obvio.</li>
<li>(String) <strong>Animation</strong> (&#8216;fade&#8217;): <em>fade|slide</em> por el momento. Tipo de animación (efecto) a usar en las transiciones de ítems.</li>
<li>(String) <strong>Mode</strong> (&#8216;vertical&#8217;): <em>vertical|horizontal</em>. Modo del efecto slide si se usa..</li>
<li>(String) <strong>Transition</strong> (&#8216;bounce:out&#8217;): <em><a href="http://mootools.net/docs/core/Fx/Fx.Transitions" title="MooTools Docs Fx.Transitions">Fx.Transitions</a> (sine|bounce|bounce:in|&#8230;)</em>. Tipo de transición para el efecto.</li>
<li>(Integer) <strong>Speed</strong> (1000): <em>Número</em>. Velocidad de la transición (opción anterior) del efecto.</li>
<li>(Integer) <strong>Periodical</strong> (5000): <em>Número</em>. Lapso de tiempo entre el intercambio de ítems.</li>
<li>(Integer) <strong>Padding</strong> (0): <em>Número</em>. Espaciado a aplicar al item.<br />
Me gustaría hacer de esto una opción para aplicar un estilo completo si se decide, daría más control sobre la visualización y corregiría posibles fallos que pudiera haber.</li>
<li>(Boolean) <strong>FixedHeight</strong> (true): <em>Número</em>. Alto fijo o flexible para adaptarse al alto de cada ítem.</li>
</ul>
<h5>Notas</h5>
<p>Quiero extenderlo bastante más, mejorarlo, añadir más efectos&#8230; pero para ilustrar creo que sobra.<br />
Este código se distribuye bajo la licencia del <abbr title="Massachusetts Institute of Technology (Instituto de Tecnología de Massachusetts)" xml:lang="en">MIT</abbr> (MIT License: <a href="http://www.opensource.org/licenses/mit-license.php" title="MIT License" hreflang="en">http://www.opensource.org/licenses/mit-license.php</a>), por lo tanto hay que mantener el copyright de la cabecera.</p>
<p><del datetime="2010-04-25T21:44:43+00:00" title="Eliminado el 25/04/2010 21:44 h">PD: Aún no tengo implementado MooTools en el blog y no hay demo pero pronto pondré alguna.</del></p>
<h4>Demo</h4>
<p>Demo y tests en MooShell:<br />
<a href="http://mootools.net/shell/XaUJA/3/" title="Demo NewsTicker en MooShell">http://mootools.net/shell/XaUJA/3/</a>.</p>
<h5>MooShell iframe</h5>
<p>Por si no resultará obvio: <strong>pulsa en la pestaña RESULT para ver el resultado de la demo</strong>.<br />
<iframe style="width: 100%; height: 300px" src="http://mootools.net/shell/XaUJA/3/embedded/"></iframe></p>
<h4>TODO</h4>
<ol>
<li>Cada ítem debe tener su propia altura si los ítems no tienen la misma.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.culturadigital.org/tecnologia/desarrollo-web/ticker-newsticker-con-mootools/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wordpress Widgets con shortcode</title>
		<link>http://blog.culturadigital.org/tecnologia/desarrollo-web/wordpress-widgets-con-shortcode</link>
		<comments>http://blog.culturadigital.org/tecnologia/desarrollo-web/wordpress-widgets-con-shortcode#comments</comments>
		<pubDate>Thu, 15 Apr 2010 15:17:24 +0000</pubDate>
		<dc:creator>J.A.Cobo</dc:creator>
				<category><![CDATA[Desarrollo web]]></category>
		<category><![CDATA[Plugins WP]]></category>
		<category><![CDATA[shortcode]]></category>
		<category><![CDATA[the_widget]]></category>
		<category><![CDATA[widgets]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://blog.culturadigital.org/?p=860</guid>
		<description><![CDATA[Wordpress: Cómo usar Widgets en el contenido de las entradas a través de <em>Shortcode</em>.]]></description>
			<content:encoded><![CDATA[<div class="headerImg"><object data="http://blog.culturadigital.org/media/2010/04/php-code-widget.jpg" type="image/jpeg" height="200px" width="100%"><param name="background-position" value="0 10%" /><param name="background-color" value="#FFF" /><param name="border" value="1px solid #FFF" /><param name="border-radius" value=".3em" /></object>
<p class="opacity7">Imagen de ejemplo de código PHP</p>
</div>
<h4>Contexto</h4>
<p>Aprovechando la función <em class="tt">the_widget()</em> para llamar a tus widgets desde plantillas de «themes» en Wordpress; imagino que es normal que la gente también vaya queriendo usarlo en los contenidos de las entradas.<br />
Aunque se pueden usar plugins para ejecutar código <acronym title="PHP: Hypertext Preprocessor" xml:lang="en">PHP</acronym> en el contenido, a mí hace tiempo que no me gusta en absoluto&#8230; por cómodo que pueda ser.</p>
<h4>Objetivo</h4>
<p>Esta es una función simple que he estado probando para <strong>llamar, por ahora, a los widgets que por defecto incorpora Wordpress</strong> a través de <em><a href="http://codex.wordpress.org/Shortcode API" title="Wordpress Codex: Shortcode">Shortcode</a></em>. Digo <em>por ahora</em> porque también se puede llamar a otros widgets instalados por plugins, por ti mismo&#8230; aunque no se comprueba si están activos ni nada más, solo se comprueba si existe la clase que gestiona el widget -que creo que sobra- y si es una instancia válida (ver siguiente).</p>
<p>Esto significa que los widgets que no utilicen la <a href="http://codex.wordpress.org/Widgets_API" title="Wordpress Codex: Widget API">nueva API</a>, es decir, que no sean instancias de <em class="tt">WP_Widget</em>, no se reconocen y no se pueden utilizar. No obstante, migrar un antiguo widget a la nueva <abbr title="Application programming interface" xml:lang="en">API</abbr>, basada en objetos, es muy fácil ¿eh?</p>
<h4>Código</h4>
<p>En fin, esto es lo que estoy probando ahora y no va mal.</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
</pre></td><td class="code"><pre class="php" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'myWidgetSC'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009933; font-style: italic;">/**
 * Shortcode para the_widget().
 * 
 * @uses WP_Widget
 * 
 * @param array $atts: Shortcode atts.
 * @return string $output: Salida del widget (the_widget)
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> myWidgetSC<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</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;">$wp_widget_factory</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// # Parámetros base:</span>
	<span style="color: #000088;">$output</span> 	<span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$msgError</span>	<span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;p class=&quot;error&quot;&gt;%s&lt;/p&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$instance</span>	<span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// No se pasan argumentos extra del widget, es peligroso:</span>
	<span style="color: #000088;">$defaultArgs</span><span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'after_widget'</span> 	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'before_title'</span> 	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'after_title'</span> 	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// # Init check:</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_widget_factory</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> 
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$msgError</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'No tenemos acceso a, o no podemos generar, Widgets.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// # Options: para Debug</span>
	<span style="color: #666666; font-style: italic;">/*$options 	= shortcode_atts(array(
		'widget_name' 	=&gt; false, 
	), $atts);
	extract($options);*/</span>
	<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span>shortcode_atts<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'widget_name'</span> 	<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$widget_name</span> <span style="color: #339933;">=</span> esc_html<span style="color: #009900;">&#40;</span><span style="color: #000088;">$widget_name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// FIXME Eliminar la clave widget_name en concreto.</span>
	<span style="color: #990000;">array_shift</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Eliminar parámetro nombre del Widget para parsear los argumentos del mismo.</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// # Check:</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$widget_name</span>&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> 
		<span style="color: #b1b100;">return</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$msgError</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'El Widget: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$widget_name</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' no existe.'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$widget</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_widget_factory</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">widgets</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$widget_name</span>&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$widget</span> instanceof WP_Widget<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$msgError</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'El widget no es una instancia válida de WP_Widget.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Settings del widget original cacheado:</span>
		<span style="color: #000088;">$widgetSettings</span> <span style="color: #339933;">=</span> <span style="color: #990000;">current</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$widget</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_settings</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// Formatear instancia final para el widget:</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$widgetSettings</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #666666; font-style: italic;">// Limpiar los valores cacheados del widget original:</span>
			<span style="color: #000088;">$defaultSettings</span><span style="color: #339933;">=</span> <span style="color: #990000;">array_fill_keys</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array_keys</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$widgetSettings</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// Parsear los valores pasados por shortcode de acuerdo a los settings del widget:</span>
			<span style="color: #000088;">$instance</span> 	<span style="color: #339933;">=</span> wp_parse_args<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #339933;">,</span> <span style="color: #000088;">$defaultSettings</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// # Run...</span>
	<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Menos pesado aunque más inseguro; the_widget() vuelve a instanciar el Widget:</span>
	<span style="color: #666666; font-style: italic;">//$widget-&gt;widget($defaultArgs, $instance); // Sin parámetros extra</span>
	<span style="color: #666666; font-style: italic;">// Más seguro pero redundante (con argumentos da problemas con tags html y es inseguro): </span>
	the_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$widget_name</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$instance</span><span style="color: #339933;">,</span> <span style="color: #000088;">$defaultArgs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// # Return:</span>
	<span style="color: #b1b100;">return</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$output</span> <span style="color: #339933;">:</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$msgError</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'El widget no generó contenido.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'widget'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'myWidgetSC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h4>Uso</h4>
<pre>[widget widget_name="WP_Widget_RSS" url="http://blog.culturadigital.org/feed/" items="5"]</pre>
<h4>Notas</h4>
<dl>
<dt class="strong">Opciones comunes de los widgets:</dt>
<dd>He intentado que se pudieran añadir argumentos típicos de los widgets como <em>before_title</em> y demás pero&#8230;, a parte de ser un coñazo por los resultados impredecibles que puede dar el uso de etiquetas html, también es peligroso usarlos a no ser que se haga una limpieza que a mí se me antoja demasiado intensiva, teniendo en cuenta que estamos en el contenido y si se quieren incluir etiquetas html, al menos antes y después del widget, es tan fácil como incluirlas en la entrada y punto.</dd>
<dt class="strong">Más simple:</dt>
<dd>Obviamente, se puede hacer mucho más reducido y simple, entre otras cosas, si no se quieren comprobar los argumentos del Widget al que se llama por ejemplo (a partir de la línea 50 del código en el bloque condicional).</dd>
<dt class="strong">Más simple todavía:</dt>
<dd>Yo he preferido documentarme directamente en la clase <a href="http://core.trac.wordpress.org/browser/trunk/wp-includes/widgets.php" title="TRAC Wordpress WP_Widget">WP_Widget</a>, pero hay otras opciones. Por ejemplo, en <a href="http://digwp.com/2010/04/call-widget-with-shortcode/" title="Digging into Wordpress: Call a Widget with a Shortcode"><em>Digging into Wordpress</em></a> tenéis para widgets sin parámetros.</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://blog.culturadigital.org/tecnologia/desarrollo-web/wordpress-widgets-con-shortcode/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Animations</title>
		<link>http://blog.culturadigital.org/tecnologia/desarrollo-web/diseno-web-desarrollo-web-2/css-animations</link>
		<comments>http://blog.culturadigital.org/tecnologia/desarrollo-web/diseno-web-desarrollo-web-2/css-animations#comments</comments>
		<pubDate>Sun, 21 Mar 2010 15:53:32 +0000</pubDate>
		<dc:creator>J.A.Cobo</dc:creator>
				<category><![CDATA[Diseño web]]></category>
		<category><![CDATA[animaciones]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[diseño web]]></category>
		<category><![CDATA[dock]]></category>
		<category><![CDATA[estándares]]></category>
		<category><![CDATA[W3C]]></category>

		<guid isPermaLink="false">http://blog.culturadigital.org/?p=848</guid>
		<description><![CDATA[Mi malestar en general sobre la dirección que está tomando el W3C y en concreto sobre las animaciones CSS para CSS3.]]></description>
			<content:encoded><![CDATA[<p>Buscando artículos sobre el problema de Firefox para aplicar bordes redondeados directamente en imágenes -no las recorta (<em>crop</em>) aun en 3.6-, llego por casualidad y leo en Anieto <a href="http://www.anieto2k.com/2008/04/02/dock-estilo-macos-con-css-animations" title="Dock estilo MacOS con CSS Animations">una de sus entradas</a> sobre las Animaciones CSS aplicadas a un dock estilo Mac OS, Avant Window Navigator en para Gnome, etc.</p>
<p>Aunque hace tiempo de su implantación y de la entrada, no he podido evitar expresar mi descontento con la dirección que está tomando el W3C con cuestiones como esta y HTML5 entre muchas otras. Ya he dicho muchas veces que soy muy talibán de XML, en este caso en concreto de XHTML.</p>
<h4>CSS Animations</h4>
<p>En mi opinión, esto debería ser parte de las animaciones estándar: SVG, al menos en XHTML. No debería haber ningún problema al incrustarlo en un documento con ambos Doctypes.</p>
<p>Si no, como dicen en los comentarios de la entrada, esto va a empezar a ser lo que fue en su día con la Guerra de los navegadores y un batiburrillo de soportes en todas las tecnologías para hacer lo mismo.<br />
No entiendo por qué el W3C no sigue manteniéndolo todo tan simple como al principio:</p>
<ul>
<li>Estructura: (X)HTML;</li>
<li>estilo visual: CSS;</li>
<li>animaciones: como parte de SVG, PNG&#8230;;</li>
<li>objetos: object&#8230;</li>
</ul>
<p>Juro que no lo entiendo, imagino que Microsoft y Adobe cada vez ejercen más influencia en el W3C. Una pena<br />
:(</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.culturadigital.org/tecnologia/desarrollo-web/diseno-web-desarrollo-web-2/css-animations/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mejora visualmente tus kbd con CSS</title>
		<link>http://blog.culturadigital.org/tecnologia/desarrollo-web/mejora-visualmente-tus-kbd-con-css</link>
		<comments>http://blog.culturadigital.org/tecnologia/desarrollo-web/mejora-visualmente-tus-kbd-con-css#comments</comments>
		<pubDate>Thu, 25 Feb 2010 19:03:49 +0000</pubDate>
		<dc:creator>J.A.Cobo</dc:creator>
				<category><![CDATA[Desarrollo web]]></category>
		<category><![CDATA[Diseño web]]></category>
		<category><![CDATA[Trabajos]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[estilo]]></category>
		<category><![CDATA[kbd]]></category>

		<guid isPermaLink="false">http://blog.culturadigital.org/?p=821</guid>
		<description><![CDATA[Hace tiempo que no publico nada en el blog y hoy, tras volver a mejorar el estilo visual para contenidos que usan la etiqueta kbd (keyboard) en algunos de mis trabajos, he decidido publicar el estilo CSS que utilizo y que, personalmente, me gusta bastante como queda.
Parte de la regla principal está inspirada en el [...]]]></description>
			<content:encoded><![CDATA[<p>Hace tiempo que no publico nada en el blog y hoy, tras volver a mejorar el estilo visual para contenidos que usan la etiqueta <span class="tt">kbd</span> (<dfn title="Teclado, en inglés" xml:lang="en">keyboard</dfn>) en algunos de mis trabajos, he decidido publicar el estilo CSS que utilizo y que, personalmente, me gusta bastante como queda.<br />
Parte de la regla principal está inspirada en el estilo por defecto que usa Wikipedia, pero ciertamente la adapté a mi gusto y añadí más efectos como el estado <em>sobre</em>, bordes redondeados, fuentes y colores&#8230; si sigo casi que es la regla entera :D</p>
<h4>Ejemplo</h4>
<p>En definitiva, el estilo para la etiqueta kbd y que se puede apreciar ampliamente en la sección <a href="http://blog.culturadigital.org/accesibilidad">Accesibilidad</a> queda así:</p>
<p><kbd>Alt</kbd></p>
<h4>Reglas CSS</h4>
<p>Las reglas CSS son las siguientes:</p>
<p>En mi <strong>basic.css</strong>:<br />
Una regla genérica y común anterior:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="css" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">pre<span style="color: #00AA00;">,</span> code<span style="color: #00AA00;">,</span> tt<span style="color: #00AA00;">,</span> kbd <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span>		<span style="color: #933;">0.87em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span>		Monaco<span style="color: #00AA00;">,</span> <span style="color: #ff0000;">'Andale Mono'</span><span style="color: #00AA00;">,</span> 
				<span style="color: #ff0000;">'Bitstream Vera Sans Mono'</span><span style="color: #00AA00;">,</span> <span style="color: #993333;">monospace</span> !important<span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span>			<span style="color: #cc00cc;">#008000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>* <strong>Nota</strong>: Aunque <em>Monaco</em> me gusta mucho, antes usaba la nueva fuente monoespaciada de Windows Vista para edición de código <em>Consolas</em>, pero su tamaño varía mucho con el resto de fuentes alternativas. Creo que también hay que tener cuidado, aunque no recuerdo cierto, con <em>Andale Mono</em>.<br />
&#8230;aunque siempre se puede recurrir a <span class="tt">@font-face {}</span> para usar una fuente propia o incluso a <em><a href="http://www.google.es/search?q=cufon" title="Buscar en Google sobre la técnica cufon">cufon</a></em>.</p>
<p>Personalización para el estilo final:</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
</pre></td><td class="code"><pre class="css" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">kbd <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> 		<span style="color: #cc66cc;">0</span> <span style="color: #933;">0.5em</span> <span style="color: #933;">0.5em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> 		<span style="color: #cc66cc;">0</span> <span style="color: #933;">0.5em</span> <span style="color: #933;">0.1em</span> <span style="color: #933;">0.25em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> 			<span style="color: #933;">4em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> 		<span style="color: #933;">4em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> 		<span style="color: #933;">4em</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span>		<span style="color: #cc00cc;">#EEE</span> <span style="color: #993333;">none</span> <span style="color: #993333;">repeat</span> <span style="color: #993333;">scroll</span> <span style="color: #933;"><span style="color: #cc66cc;">0</span>%</span> <span style="color: #933;"><span style="color: #cc66cc;">0</span>%</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span>			<span style="color: #933;">0.23em</span> <span style="color: #993333;">outset</span> <span style="color: #cc00cc;">#DDD</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-bottom-color</span><span style="color: #00AA00;">:</span>	<span style="color: #cc00cc;">#BBB</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-right-color</span><span style="color: #00AA00;">:</span>	<span style="color: #cc00cc;">#BBB</span><span style="color: #00AA00;">;</span>
	border-radius<span style="color: #00AA00;">:</span> 		<span style="color: #933;">0.3em</span><span style="color: #00AA00;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span>			<span style="color: #000000; font-weight: bold;">black</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> 		<span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">white-space</span><span style="color: #00AA00;">:</span>		<span style="color: #993333;">nowrap</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
kbd<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> 		<span style="color: #cc66cc;">0</span> <span style="color: #933;">0.75em</span> <span style="color: #933;">0.75em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> 		<span style="color: #cc66cc;">0</span> <span style="color: #933;">0.53em</span> <span style="color: #933;">0.13em</span> <span style="color: #933;">0.28em</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span>			<span style="color: #933;">0.1em</span> <span style="color: #993333;">outset</span> <span style="color: #cc00cc;">#DDD</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-bottom-color</span><span style="color: #00AA00;">:</span>	<span style="color: #cc00cc;">#EEE</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">border-right-color</span><span style="color: #00AA00;">:</span>	<span style="color: #cc00cc;">#EEE</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span>			<span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Básicamente cambiamos los bordes inferior y derecho a otro color para el efecto de sombreado, además del tamaño para el efecto <em>pulsada</em>. Luego ajustamos los espaciados y márgenes para que, al reducir o aumentar el tamaño de los bordes, el del botón no varíe -al menos demasiado (nota siguiente)-.</p>
<p>Pueden existir problemas al usar medidas relativas&#8230; pero yo al menos ya me he acostumbrado a ellas y prácticamente no diseño nada en base a píxeles.<br />
&#8230;es algo arriesgado, sobre todo con navegadores poco estándares, pero diseñando de un modo más flexible y aceptando las variaciones de estos últimos -que las tienen con o sin píxeles- al final el resultado es casi más gratificante. Los píxeles quedan casi en exclusiva para elementos que no redimensionen o que solo lo hagan dentro de unos límites conocidos. Por ejemplo un elemento que sepas solo se ampliará o reducirá por un lado y dejes un espacio para una imagen de tamaño fijo. No obstante, incluso en casos así se sigue pudiendo prescindir de ellos perfectamente.</p>
<p>Además ajustamos el texto, como en los teclados, un poco a la parte superior izquierda, un efecto sutil en teclas pequeñas y visible en las grandes.</p>
<h5>Jugando un poco, más ejemplos</h5>
<p>Aquí viene otra de las bondades de los tamaños relativos: aunque no sean medidas exactas de teclas, las teclas grandes -con más texto- se autoexpanden. Y permiten jugar un poco con su contenido aunque de forma menos semántica. En concreto, añadiendo texto y ajustando la autoexpansión, se le da sentido a las teclas cuando no se usa CSS. Por ejemplo:<br />
Para <kbd>Ctrl</kbd> y <kbd>Alt</kbd>, el mismo tamaño del texto es suficiente, pero para mayúsculas simples (shift) podemos o añadir la palabra inglesa, u ocultarla mediante algo de CSS de presentación -del que no me gusta pero bueno- y conseguir el tamaño deseado.</p>
<p><kbd>&uArr; Shift</kbd><br />
Versión ocultando <em>shift</em> sin extras:<br />
<kbd>&uArr; <span style="visibility:hidden;">Shift</span></kbd><br />
Una tecla más real, mayúsculas corta:<br />
<kbd><span style="font-size:1.4em;">&uArr;</span> <span style="visibility:hidden; letter-spacing:-2em;">Shift</span></kbd><br />
Mayúsculas larga:<br />
<kbd><span style="font-size:1.4em;">&uArr;</span> <span style="visibility:hidden; letter-spacing:0.8em;">Shift</span></kbd></p>
<p>Espacio:<br />
<kbd><span style="visibility:hidden; letter-spacing:3em;">Shift</span></kbd></p>
<p>Retroceso:<br />
<kbd><span style="font-size:1.4em;">&larr;</span><span style="visibility:hidden;">return</span></kbd><br />
:D</p>
<p>Bueno, ahí queda por si le gusta o interesa a alguien.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.culturadigital.org/tecnologia/desarrollo-web/mejora-visualmente-tus-kbd-con-css/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVG: Un ejemplo más de su potencial</title>
		<link>http://blog.culturadigital.org/tecnologia/desarrollo-web/svg-un-ejemplo-mas-de-su-potencial</link>
		<comments>http://blog.culturadigital.org/tecnologia/desarrollo-web/svg-un-ejemplo-mas-de-su-potencial#comments</comments>
		<pubDate>Tue, 17 Nov 2009 16:35:23 +0000</pubDate>
		<dc:creator>J.A.Cobo</dc:creator>
				<category><![CDATA[Desarrollo web]]></category>
		<category><![CDATA[Diseño web]]></category>
		<category><![CDATA[animación]]></category>
		<category><![CDATA[estándares-web]]></category>
		<category><![CDATA[SVG]]></category>

		<guid isPermaLink="false">http://blog.culturadigital.org/?p=758</guid>
		<description><![CDATA[Como siempre, una breve introducción:
Como a no poca gente creo, me encantan los créditos finales de The Bourne Identity (El caso Bourne) y la saga en general -creo que es obvio que Extreme Ways tiene mucho que ver :D -.
Hace poco vi algunos vídeos en Youtube para recrear los efectos de los créditos desde diferentes [...]]]></description>
			<content:encoded><![CDATA[<p>Como siempre, una breve introducción:</p>
<p>Como a no poca gente creo, me encantan los créditos finales de <strong>The Bourne Identity</strong> (<em>El caso Bourne</em>) y la saga en general -creo que es obvio que <em title="Extreme Ways del álbum 18 de Moby">Extreme Ways</em> tiene mucho que ver :D -.<br />
Hace poco vi algunos vídeos en Youtube para <strong>recrear los efectos de los créditos</strong> desde diferentes aplicaciones pero sobre todo con <em>After Effects</em>, que por cierto es genial, y en ese mismo instante pensé: vamos a demostrar que no necesitamos Flash para hacer lo mismo de forma estándar, es decir: <strong>con SVG</strong>.</p>
<h4>Ejemplo de créditos finales Bourne con SVG</h4>
<p>Anoche realicé mi primera aproximación en apenas una hora y los resultados prometían mucho. Debo aclarar que solo es eso: una aproximación, además de que no estoy muy puesto aún en la animación declarativa -nativa- de SVG ya que solo está soportada por Opera, Safari creo, y poco más. Normalmente yo utilizo scripting pero con el tiempo y el aumento de soporte todo pasará a ser declarativa, en su mayor parte al menos.</p>
<p>Lo que quiero decir es que estos han sido mis primeros pasos en animación declarativa SVG, no está optimizado ni acabado, solo pretende mostrar el potencial de SVG.</p>
<h4>Resultado</h4>
<p class="alert"><strong>Muy importante</strong>: Como decía, la animación declarativa solo está soportada -que yo sepa hasta ahora- en Opera y Safari, no sé si webkit en general como por ejemplo Chrome. Por lo tanto necesitas un navegador compatible para ver la animación de este SVG, aunque no de su contenido para ver como funciona.</p>
<p>Nota: :D Es muy recomendable escuchar de fondo, sobre todo el comienzo, el tema «<strong>Extreme Ways</strong>» de los créditos; es del álbum, estupendo por cierto, «18», de «Moby», y aunque no lo he mirado creo recordar que se puede hacer también con animación SVG.<br />
<object data="http://blog.culturadigital.org/media/2009/11/bourne2.svg" type="image/svg+xml"><img src="http://blog.culturadigital.org/media/2009/11/bourne2.svg" alt="The Bourne Identity end credits" title="The Bourne Identity end credits" class="aligncenter size-full wp-image-759" /></object></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.culturadigital.org/tecnologia/desarrollo-web/svg-un-ejemplo-mas-de-su-potencial/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SVG: A vueltas con los Estándares</title>
		<link>http://blog.culturadigital.org/tecnologia/desarrollo-web/svg-a-vueltas-con-los-estandares</link>
		<comments>http://blog.culturadigital.org/tecnologia/desarrollo-web/svg-a-vueltas-con-los-estandares#comments</comments>
		<pubDate>Fri, 23 Oct 2009 20:10:36 +0000</pubDate>
		<dc:creator>J.A.Cobo</dc:creator>
				<category><![CDATA[Desarrollo web]]></category>
		<category><![CDATA[estándares-web]]></category>
		<category><![CDATA[SVG]]></category>

		<guid isPermaLink="false">http://blog.culturadigital.org/?p=717</guid>
		<description><![CDATA[La potencia de SVG -estándar de gráficos escalables vectoriales-, por ejemplo, para generar mapas con datos dinámicos:

Battleground Europe Tools &#8211; Pantallazo del MapViewer en la versión 39beta.

Me he encontrado de repente sorprendido porque aún no había escrito nada sobre SVG&#8230; con lo inmerso que estoy en ello ahora mismo en relación a las Battleground Europe [...]]]></description>
			<content:encoded><![CDATA[<p>La potencia de SVG -estándar de gráficos escalables vectoriales-, por ejemplo, para generar mapas con datos dinámicos:</p>
<div class="headerImg"><object data="http://www.1spanishcompany.co.uk/ftp-fotos/Covi/1SCTools/screenshots/BeTools.MapViewer.v0.39.jpg" type="image/jpeg" height="200px" width="100%"><param name="background-color" value="#222" /><param name="background-position" value="47% 15%" /><param name="background-border" value="1px solid #222"/><param name="border-radius" value="0.25em"/></object>
<p class="opacity7">Battleground Europe Tools &#8211; <a href="http://1spanishcompany.co.uk/ftp-fotos/Covi/1SCTools/screenshots/Pantallazo-Map%20Viewer.v38.jpg" title="Ver imagen">Pantallazo</a> del MapViewer en la versión 39beta.</p>
</div>
<p>Me he encontrado de repente sorprendido porque aún no había escrito nada sobre SVG&#8230; con lo inmerso que estoy en ello ahora mismo en relación a las <a href="http://betools.culturadigital.org" title="Sitio de las BeTools">Battleground Europe Tools</a>; una aplicación de monitorización para jugadores de <a href="http://battlegroundeurope.com">Battleground Europe</a> y que está centrada en la creación de un mapa lo más parecido al del juego, para poder seguir el desarrollo de la campaña online y sin necesidad de entrar en él. &#8230;de hecho, tengo una sección en el blog sobre el proyecto: <a href="http://blog.culturadigital.org/search/1sctools" title="buscar contenido relacionado">BE/1SCTools</a>.</p>
<p>Para no enrollarme mucho más, solo voy a dejar unas capturas del potencial de SVG como estándar para gráficos vectoriales y escalables en la web; es decir, en lugar de formatos o tecnologías propietarias como por ejemplo gif, flash&#8230; y/o no nativos como este último. Además sin necesidad de plugins, como el de Adobe por ejemplo, y sin <a href="http://blog.culturadigital.org/tecnologia/desarrollo-web/svg-un-ejemplo-mas-de-su-potencial">animaciones declarativas</a> ya que aún están muy poco soportadas, sustituyendo las mismas con Javascript, en este caso Ecmascript.</p>
<h4>Capturas Battleground Europe Tools</h4>
<p>v.39beta:<br />
<img src="http://www.1spanishcompany.co.uk/ftp-fotos/Covi/1SCTools/screenshots/BeTools.MapViewer.v0.39.jpg" alt="Map Viewer - v.39b" /></p>
<p><img src="http://1spanishcompany.co.uk/ftp-fotos/Covi/1SCTools/screenshots/Pantallazo-Map%20Viewer.v38.jpg" alt="Map Viewer - v.38" /></p>
<p><img src="http://1spanishcompany.co.uk/ftp-fotos/Covi/1SCTools/screenshots/Pantallazo-Map%20Viewer.2.v38.jpg" alt="Map Viewer (2) - v.38" /></p>
<p><img src="http://1spanishcompany.co.uk/ftp-fotos/Covi/1SCTools/screenshots/homeMapZoom.jpg" alt="Home - v.38" /></p>
<h4>Scripting: Javascript, Ecmascript, DOM&#8230;</h4>
<p>En el sentido del <em>scripting</em>, he aprendido mucho gracias, paradójicamente, a las pocas, por no decir ninguna, librerías Javascript que trabajan con el DOM de XML&#8230; o al menos de SVG en concreto. Y me refiero muy en parte a jQuery que desde luego hace lo que indica en su eslogan pero lo cierto es que se queda corta en el sentido global de extender y mejorar Javascript -como ya hace comentaba Anieto2K-. Es decir, por ejemplo mootools se abstrae más del tipo de documento o del DOM en este caso para montar un framework genérico que extienda y mejore de verdad Javascript&#8230; lo que ellos denominan «como debería ser Javascript».</p>
<p>He de decir que en este caso me ha sorprendido mucho mucho Prototype, el primer framework Javascript que usé en los albores de AJAX en la web 2.0, e imagino que es debido a su sólida génesis. De ahí que ni haya crecido como otras librerías&#8230; ni se haya desvirtuado que es lo bueno.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.culturadigital.org/tecnologia/desarrollo-web/svg-a-vueltas-con-los-estandares/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XHTML: Object en lugar de img</title>
		<link>http://blog.culturadigital.org/tecnologia/desarrollo-web/xhtml-object-en-lugar-de-img</link>
		<comments>http://blog.culturadigital.org/tecnologia/desarrollo-web/xhtml-object-en-lugar-de-img#comments</comments>
		<pubDate>Thu, 08 Oct 2009 16:43:24 +0000</pubDate>
		<dc:creator>J.A.Cobo</dc:creator>
				<category><![CDATA[Desarrollo web]]></category>
		<category><![CDATA[Diseño web]]></category>
		<category><![CDATA[estándares-web]]></category>
		<category><![CDATA[img]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[XHTML]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://blog.culturadigital.org/?p=648</guid>
		<description><![CDATA[En una entrada anterior comentaba las bondades de jQuery para hacer compatible el uso, por ejemplo, de un objeto en XML (XHTML) con navegadores que no lo soportaran, para aprovechar su potencial y crear imágenes bonitas de cabecera sin marcado no válido.
Quedó algo confuso desde el punto de vista de usar objetos; ahora pretendo concretar [...]]]></description>
			<content:encoded><![CDATA[<p>En una entrada anterior comentaba las bondades de jQuery para hacer compatible el uso, por ejemplo, de un objeto en XML (XHTML) con navegadores que no lo soportaran, para aprovechar su potencial y crear imágenes bonitas de cabecera sin marcado no válido.<br />
Quedó algo confuso desde el punto de vista de usar objetos; ahora pretendo concretar e ilustrar la idea del <strong>potencial de <tt>&lt;object&gt;</tt> (estándar del W3C) frente <tt>&lt;img&gt;</tt></strong>.</p>
<h4>Lo fundamental: diseñar en base a estándares</h4>
<p>La cuestión fundamental es: &lt;object&gt; nos da muchísimas más posibilidades y es más flexible que &lt;img&gt;; además es estándar, compatible con los navegadores actuales y con soporte para mucho mucho tiempo en el futuro.</p>
<p>La funcionalidad es la misma prácticamente que con la etiqueta propietaria de Netscape (img) usado de forma básica, pero ésta es extensible de mil y una maneras ya que se pueden usar parámetros que se abstraen del marcado estructural, y además es mucho más flexible y potente para contenido alternativo en navegadores que no lo soporten.</p>
<p>Es más estándar y coherente, por lo tanto más semántica, por ejemplo se puede establecer el mime type del objeto, etc. O sea, proporciona más información al navegador que, en teoría, debería redundar en un mayor rendimiento y menos coste de proceso.<br />
<strong>Es decir, todo son beneficios</strong>.</p>
<h5>¿Por qué resistirse?</h5>
<p>Existe un ámbito de ciertas opiniones clásicas que se escudan en la usabilidad y que saltan a la palestra siempre que se habla de Estándares web, de marcado basura, obsoleto, Flash, soporte Internet Explorer y profesionalidad; en especial cuando al parecer se ejerce intrusismo laboral y se presupone falta de experiencia.<br />
En referencia a esta última cuestión: No entiendo porqué les parece un sacrilegio olvidar de una vez a Internet Explorer 6 e inferiores, y por añadidura prácticamente el HTML clásico y obsoleto. En mi opinión diría que ya está bien y basta de dar soporte a un software con más de diez años y 5 sin actualizarse por no decir 7. Eso, es una aberración obvia en el desarrollo -y soporte- de software y no hubiera pasado nunca si su propietario no fuera Microsoft.</p>
<h6>Profesionalidad o pereza</h6>
<p>No, no es dar al cliente algo que funcione seguro, se trata de ser profesional; y ser profesional significa trabajar bien y superar las dificultades -entiendo yo, claro-, no hacer chapuzas de las que tenemos muchos ejemplos, ejemplos profesionales: web del Congreso, de Telefónica (ver ejemplo de la copia para promoción IPhone: Apple con Javascript válido y Telefónica con Flash xD) y algunas de Microsoft&#8230;</p>
<p>Quiero decir, SÍ es posible diseñar en base a los estándares y que tu diseño funcione, por ejemplo, en Internet Explorer -no me refiero al 6 en exclusiva- sin tener que escribir marcado basura, propietario u obsoleto. Otra cosa es pasar del tema, cobrar un pastón pero seguir siendo un chapucero, aun teniendo quinientos mil títulos académicos.</p>
<p>&#8230;y tampoco me creo que porque se use un sistema de gestión mastodóntico -administración pública- sea imposible proporcionar salidas de documentos válidas. Y si es el caso, si han migrado y actualizado la administración, deberían haber migrado también ese sistema&#8230; por que no será por falta de dinero para hacerlo.</p>
<h4>Ejemplos</h4>
<p>Como mencionaba, en el ejemplo de una imagen de cabecera bonita la <em>tendencia natural</em> es usar una división, aplicar estilos incrustados e insertar una imagen de fondo. La solución directa también podría ser diseñar dos versiones o más de una imagen, como ocurre en Wordpress cuando subes medios o casi en cualquier CMS.<br />
Bien&#8230; :D rentable no es que sea mucho la verdad, eso sin contar con que por ejemplo quieras posicionar esa imagen de mil formas distintas: ¿una versión para cada caso o estilo que quieras aplicar?<br />
¿Porqué tener 20 versiones de la misma imagen para solo aplicar estilos?</p>
<p>La solución, en mi opinión obvia, es usarla como fondo y aplicar CSS. El problema a superar como decía es usar marcado válido, estructural y semántico. Ese es el problema que hay superar y ser profesional.</p>
<h5>Ejemplo no profesional o falto de recursos</h5>
<h6>Lo más terrorífico: tengo mil versiones para una imagen</h6>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;mi versión de imagen, de entre unas 4/5 para aplicar un estilo caprichoso&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">alt</span>=<span style="color: #ff0000;">&quot;Mi contenido alternativo se reduce a esta patatilla.&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span><span style="color: #000000; font-weight: bold;">&lt;br</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		Cristina Scabbia de Lacuna Coil.
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Si bueno&#8230; puedes incrustar estilos, javascript&#8230; o incluso podría no ser ni javascript intrusivo y CSS externo pero es muy muy fácil caer en la clasitis por ejemplo; sin contar con que img se cae en XHTML 2.0, y se caerá de todo en un futuro muy cercano, y sus limitaciones obvias.</p>
<h6>Estilos incrustados</h6>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;headerImg&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;height:200px; background:#333 url(http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg) </span>
<span style="color: #009900;">	no-repeat 0 30%;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cristina Scabbia de Lacuna Coil.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Algo es algo, al menos eliminamos la etiqueta imagen, las posibles versiones de una imagen y pasamos a usar una sola. Igualmente se nos va al garete sin CSS.</p>
<h5>Como tengo recursos, puedo ser estándar</h5>
<p>Esto es y debería ser la base. Que un maquetador se dedique a hacer las cosas correctamente, como mandan los cánones -en este caso los estándares web-; tener una versión portable y mantenible venga quien venga después; jueguen como quieran jugar después con los objetos y les den la salida que prefieran. Como hemos dicho mil veces: abstracción de la estructura, en este caso frente al diseño visual:</p>
<h6>Object</h6>

<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="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;headerImg&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;object</span> <span style="color: #000066;">data</span>=<span style="color: #ff0000;">&quot;http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;image/jpeg&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;200px&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;background-position&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;0% 30%&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cristina Scabbia de Lacuna Coil.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Cojonudo:<br />
Por lo pronto, funciona, aunque no del todo bien, sin CSS, o sea de forma básica. Podemos jugar con los parámetros del objeto desde cualquier lenguaje de servidor que parsee el HTML, con Javascript&#8230; el caso es que se abstrae del estilo visual.<br />
Es coherente y semántico ya que proporciona información a los renderizadores: navegadores, etc.</p>
<p>Por ejemplo les dice que es una imagen/jpeg y se supone que en un futuro si no ya, da la posibilidad a los desarrolladores de navegadores web optimizar su funcionamiento y hacerlos más rápidos, sino ya desarrollar plugins específicos para imágenes, en concreto si tienen transparencias o no (png, gif vs jpeg, bmp&#8230;)&#8230; bff, y muchas cosas más imagino.<br />
Es decir, todo lo que sea dar información concreta sobre los elementos del documento es beneficio y renderización optimizada del navegador, algo que creo que se pierde, y se perdía, con HTML que normalmente es muy poco semántico, hasta ahora al menos.</p>
<h4>Casos probados</h4>
<h5>Todo funcional, con Javascript y CSS al vuelo</h5>
<p>Usando Javascript para gestionar el objeto:</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="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;headerImg&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;object</span> <span style="color: #000066;">data</span>=<span style="color: #ff0000;">&quot;http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;image/jpeg&quot;</span> <span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;200px&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;background-position&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;0% 30%&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cristina Scabbia de Lacuna Coil.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<div class="headerImg"><object data="http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg" type="image/jpeg" height="200px" width="100%"><param name="background-position" value="0% 30%" /></object>
<p>Cristina Scabbia de Lacuna Coil.</p>
</div>
<p>Vamos a jugar un poco con la imagen, no necesito más versiones de la misma, no necesito CSS incrustado, solo los parámetros del objeto que para eso están:<br />
<em>En este caso se gestiona con Javascript (jQuery) generando, eso sí, CSS al vuelo, pero como digo&#8230; es un proceso externo al marcado que es de lo que se trata.</em></p>
<p><tt>param name="background-position" value="50% 30%"</tt>:</p>
<div class="headerImg"><object data="http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg" type="image/jpeg" height="200px" width="100%"><param name="background-position" value="50% 30%" /></object>
<p>Cristina Scabbia de Lacuna Coil.</p>
</div>
<p><tt>param name="background-position" value="70% 70%"</tt>:</p>
<div class="headerImg"><object data="http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg" type="image/jpeg" height="200px" width="100%"><param name="background-position" value="70% 70%" /></object>
<p>Cristina Scabbia de Lacuna Coil.</p>
</div>
<p><tt>param name="background-color" value="red"</tt>:</p>
<div class="headerImg"><object data="http://nop" type="image/jpeg" height="200px" width="100%"><param name="background-position" value="70% 70%" /><param name="background-color" value="red" /></object>
<p>Cristina Scabbia de Lacuna Coil.</p>
</div>
<p><tt>param name="background-border" value="5px solid blue"</tt>:</p>
<div class="headerImg"><object data="http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg" type="image/jpeg" height="200px" width="100%"><param name="background-position" value="70% 70%" /><param name="background-border" value="5px solid blue" /></object>
<p>Cristina Scabbia de Lacuna Coil.</p>
</div>
<p><tt>param name="background-position" value="50% 0"</tt><br />
<tt>param name="background-border" value="1px solid blue"</tt><br />
<tt>param name="border-radius" value="3em 3em 0 0"</tt>:</p>
<div class="headerImg"><object data="http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg" type="image/jpeg" height="200px" width="100%"><param name="background-position" value="50% 0" /><param name="background-border" value="1px solid blue" /><param name="border-radius" value="3em 3em 0 0" /></object>
<p>Cristina Scabbia de Lacuna Coil.</p>
</div>
<p>¿Más pequeña?<br />
<tt>&lt;object [...]height="100px" width="50%"[...]</tt><br />
<tt>param name="background-position" value="50% 0"</tt><br />
<tt>param name="background-border" value="1px solid blue"</tt><br />
<tt>param name="border-radius" value="3em 3em 0 0"</tt>:</p>
<div class="headerImg"><object data="http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg" type="image/jpeg" height="100px" width="50%"><param name="background-position" value="50% 0" /><param name="background-border" value="1px solid blue" /><param name="border-radius" value="3em 3em 0 0" /></object>
<p>Cristina Scabbia de Lacuna Coil.</p>
</div>
<h6>Conclusión</h6>
<p>Con imagen (<tt>&lt;img&gt;</tt>) es inevitable o caer en clasitis o establecer atributos no estándares (<em>hacks</em>). Además se hace trabajar al navegador con cuestiones raras que no tiene porqué entender; es decir: debe intentar buscar atributos, por ejemplo rel -<em class="x-small">que se usa mucho y mal para hacks ya que su función no es ni por asomo esa salvo contadas excepciones</em>- que no concuerdan con nada de lo que conoce. Cuando si usamos un objeto, sabe perfectamente de qué se trata, lo renderiza y punto porque él no se encarga de gestionar sus parámetros; al menos y que yo sepa en este caso (mime type: imagen/jpeg), no sé exactamente como se comportan con otros objetos pero en cualquier caso les ayudamos a comportarse mejor porque concretamos un medio.</p>
<p>Alguien puede pensar que simplemente es una pasarela para atributos CSS, pero no obstante es igual de válido que con imagen (van a comportarse de la misma manera aplicando clases y reglas CSS) y te ofrece además estas posibilidades: gestionarlo con cualquier lenguaje sin marcado no válido, inventado o extra. Además, tu marcado será válido también para XML, lo que lo convierte en portable, estándar y por lo tanto mantenible, y compatible con el pasado y futuro.</p>
<p><strong>En resumen</strong>: Es por lo que precisamente, actualmente el W3C mantiene <tt>&lt;object&gt;</tt> en el estándar para elementos multimedia frente a la simpleza y pobreza de <tt>&lt;img&gt;</tt> de Netscape. Y obviamente porque es un elemento multimedia, claro.</p>
<h6>¿No es demasiado complicado?</h6>
<p>No nos equivoquemos, object puede ser tan simple como img:</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="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;25%&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">alt</span>=<span style="color: #ff0000;">&quot;Cristina Scabbia, Lacuna Coil&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;object</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">data</span>=<span style="color: #ff0000;">&quot;http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;25%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	Cristina Scabbia, Lacuna Coil
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><img src="http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg" width="25%" alt="Cristina Scabbia, Lacuna Coil" /><br />
<object data="http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg" width="25%">Cristina Scabbia, Lacuna Coil</object><br />
Pero es aún mejor, <em>potencial del contenido alternativo</em> y parámetros propios:</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="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;object</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;image/jpeg&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">data</span>=<span style="color: #ff0000;">&quot;no existo&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;25%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;italic&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Tu navegador no puede mostrar esta imagen de <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://es.wikipedia.org/wiki/Cristina Scabbia&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Cristina Scabbia en Wikipedia&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Cristina Scabbia, Lacuna Coil<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span> 
	cantando con su característico gesto apasionado, bajo la tenue iluminación azul del escenario.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><object type="image/jpeg" data="no existo" width="25%">
<p class="italic">Tu navegador no puede mostrar esta imagen de <a href="http://es.wikipedia.org/wiki/Cristina Scabbia" title="Cristina Scabbia en Wikipedia">Cristina Scabbia, Lacuna Coil</a>cantando con su característico gesto apasionado, bajo la tenue iluminación azul del escenario.</p>
<p></object><br />
Tampoco quiero confundir a nadie, el cierre de la etiqueta de imagen solo significa que esa etiqueta no tiene contenido, pero se puede especificar con contenido:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;no existo&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;25%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;italic&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Tu navegador no puede mostrar esta imagen de <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://es.wikipedia.org/wiki/Cristina Scabbia&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;Cristina Scabbia en Wikipedia&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Cristina Scabbia, Lacuna Coil<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
		cantando con su característico gesto apasionado, bajo la tenue iluminación azul del escenario.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/img<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>No obstante sigue siendo muy pobre en comparación con object, no es estándar y por lo tanto si se renderiza bien solo es fruto de una funcionalidad específica del navegador en uso, por lo tanto es jugar con fuego. De hecho, una etiqueta de cierre de img está prohibida.<br />
Más referencias: <a href="http://html.conclase.net/w3c/html401-es/struct/objects.html#h-13.1">W3C &#8211; HTML4</a></p>
<h5>Salvando las dificultades</h5>
<h6>Sin Javascript y con reglas CSS</h6>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;object</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">data</span>=<span style="color: #ff0000;">&quot;http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;image/jpeg&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;headerImg&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cristina Scabbia de Lacuna Coil.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Yo prefiero con XML cerrar una etiqueta vacía: <del datetime="2009-10-08T13:41:00+00:00"><tt>class="testImgHead"&gt;&lt;/object&gt;</tt></del> <tt>class="testImgHead"/&gt;</tt></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">[...].static.flickr.com/41/115559256_918ab03490_o_d.jpg&quot;/&gt;</pre></div></div>

<p><object data="http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg" type="image/jpeg" class="headerImg" height="200px" width="100%"></object>
<p>Cristina Scabbia de Lacuna Coil.</p>
<p>Para solucionar la expansión máxima de la imagen, bastaría con añadir una clase CSS que la redujera en el caso de estar desactivado Javascript. Ej:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #6666ff;">.adjustHeaderImageNoJs</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span> !important<span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #808080; font-style: italic;">/* Puede bastar con !important (cuidado IE6) pero dependería del CSS 
y siempre se puede aplicar más especificidad con herencia */</span>
html body <span style="color: #6666ff;">.post</span> <span style="color: #6666ff;">.entry</span> <span style="color: #6666ff;">.etc</span>... div<span style="color: #6666ff;">.headerImage</span><span style="color: #6666ff;">.adjustHeaderImageNoJs</span> object <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><strong>¿Cómo?</strong> «<em>Captain Obvious to the rescue</em>» que dirían los <em>yankis</em> ^.^ , muy fácil -relativamente, claro-, eliminando dicha clase mediante Javascript 8) &#8230; o/y viceversa.<br />
Por ejemplo y a bote pronto -ojo-:</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
</pre></td><td class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #006600; font-style: italic;">// Entendiendo que tenemos esta y el resto de funciones básicas</span>
<span style="color: #006600; font-style: italic;">// ...porque es un coñazo, ponerme a escribir ahora aquí el bucle para encontrar la clase.</span>
<span style="color: #003366; font-weight: bold;">var</span> newClasses	<span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// Esto será string, no array.</span>
<span style="color: #003366; font-weight: bold;">var</span> objectClasses	<span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">var</span> myObjects		<span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByClassName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'headerImg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// DOM 2 en todo caso</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">;</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> myObjects.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> myObject		<span style="color: #339933;">=</span> myObjects<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> objectAttrClass	<span style="color: #339933;">=</span> myObject.<span style="color: #660066;">getAttributeNS</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> objectClasses	<span style="color: #339933;">=</span> objectAttrClass.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Eliminar todas las clases:</span>
	myObject.<span style="color: #660066;">removeAttributeNS</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">// Volver a añadirlas excepto la que no queremos:</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">;</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;=</span> objectClasses.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'adjustHeaderImageNoJs'</span> <span style="color: #339933;">!=</span> objectClasses<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">// La clase que ajusta el objeto sin Js</span>
			newClasses <span style="color: #339933;">+=</span> objectClasses<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">' '</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #006600; font-style: italic;">// Volver a añadir el atributo de clase</span>
	myObject.<span style="color: #660066;">setAttributeNS</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span> newClasses<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #006600; font-style: italic;">// Resto de instrucciones de proceso del objeto.</span></pre></td></tr></table></div>

<p>..mmm, como siempre, con jQuery sería tan sencillo como esto:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.headerImg'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'adjustHeaderImageNoJs'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h6>Sin Javascript ni CSS</h6>
<div><object data="http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg" type="image/jpeg" class="headerImg" width="200px" height="200px"></object>
<p>Cristina Scabbia de Lacuna Coil.</p>
</div>
<p>Tendríamos un problema ya algo serio ya que la imagen se expandiría sin remedio, esta vez sí, sin alternativa a usar una etiqueta de imagen&#8230; que no obstante, tendría el mismo problema:</p>
<div><img src="http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg" class="headerImg" width="200px" height="200px"></object>
<p>Cristina Scabbia de Lacuna Coil.</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.culturadigital.org/tecnologia/desarrollo-web/xhtml-object-en-lugar-de-img/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JQuery&amp;object, imágenes de cabecera semánticas y limpias para XHTML</title>
		<link>http://blog.culturadigital.org/tecnologia/desarrollo-web/jquery-imagenes-de-cabecera-semanticas-y-limpias-para-xhtml</link>
		<comments>http://blog.culturadigital.org/tecnologia/desarrollo-web/jquery-imagenes-de-cabecera-semanticas-y-limpias-para-xhtml#comments</comments>
		<pubDate>Mon, 05 Oct 2009 23:10:21 +0000</pubDate>
		<dc:creator>J.A.Cobo</dc:creator>
				<category><![CDATA[Desarrollo web]]></category>
		<category><![CDATA[Diseño web]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[cabecera]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Imagen]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[object]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://blog.culturadigital.org/?p=562</guid>
		<description><![CDATA[Esta entrada tiene el objetivo de mostrar, una vez más, lo fácil que jQuery hace nuestro trabajo en desarrollo web, su flexibilidad y, lo más importante, como seguir manteniendo tu código limpio, semántico, estándar y flexible.
En este caso en concreto a través del uso de esa demasiado poco usada etiqueta &#60;object&#62; que, dicho sea de [...]]]></description>
			<content:encoded><![CDATA[<p>Esta entrada tiene el objetivo de mostrar, una vez más, lo fácil que jQuery hace nuestro trabajo en desarrollo web, su flexibilidad y, lo más importante, como seguir manteniendo tu código limpio, semántico, estándar y flexible.<br />
En este caso en concreto a través del uso de esa demasiado poco usada etiqueta <tt>&lt;object&gt;</tt> que, dicho sea de paso, sustituirá en un futuro (XHTML 2.0) y como debió ser desde el principio, a la etiqueta propietaria de Netscape <tt>&lt;img&gt;</tt>.<br />
Se puede ver el resultado de lo que se pretende <a href="http://blog.culturadigital.org/musica/cristina-scabbia-lacuna-coil" title="ver ejemplo en entrada de Cristina Scabbia">aquí</a> y <a href="http://laguardiadejaen.com/web/la-guardia/patrimonio-historico-y-cultural/monumentos-de-interes/antiguo-convento-de-santo-domingo/" title="Ver ejemplo en laguardiadejaen.com">aquí</a>.</p>
<p>Como siempre, ahí va un poco de contexto:</p>
<h4>Contexto</h4>
<p>En el sitio web donde trabajo -y en este blog-, hasta hace pocos días, usaba el siguiente código para maquetar una <strong>imagen bonita de cabecera</strong> para algunas entradas o secciones.</p>
<h5>Marcado no estructural</h5>
<p>Por ejemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;headerImg&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #000066;">style</span>=<span style="color: #ff0000;">&quot;height:200px; background:#333 url(http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg) no-repeat 0 30%;&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cristina Scabbia de Lacuna Coil.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>La cuestión era usar una imagen ya existente a tamaño original, ponerla como fondo para esa cabecera y añadir texto descriptivo a modo de visor en lugar de texto debajo de la imagen:<br />
<div id="attachment_590" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.culturadigital.org/media/2009/10/ImagenBonitaCabecera.png" rel="group_gallery"><img src="http://blog.culturadigital.org/media/2009/10/ImagenBonitaCabecera-300x177.png" alt="Ejemplo de imagen bonita de cabecera" title="ImagenBonitaCabecera" width="300" height="177" class="size-medium wp-image-590" /></a><p class="wp-caption-text">Ejemplo de imagen bonita de cabecera</p></div><br />
Nunca me gustó porque usaba estilo incrustado -aunque es posible hacerlo con CSS pero demasiado experimental- lo cual una vez más es marcado extra innecesario y no semántico: ya se sabe, <del datetime="2009-10-05T23:50:09+00:00" title="en este caso no importa">aumenta el peso de la página</del>, mezcla estilo y maquetación, etc. Empezó por ser algo provisional hasta que acabé por usarlo demasiado. Hace poco por fin me decidí a meterle mano aprovechando la flexibilidad y el desuso de la etiqueta <tt>object</tt>, y la potencia de jQuery.</p>
<h4>Solución</h4>
<p><strong>Usar una etiqueta <tt>object</tt> para la imagen</strong>, lo cual además de ser estándar actualmente, se adelanta a XHTML 2.0 y ya estás maquetando con soporte para un futuro muy lejano; todo esto sin olvidar que si estructuras en XHTML, es XML y las migraciones o la portabilidad se mantienen.</p>
<h5>¿Por qué object?</h5>
<p>Bien, usar un objeto va a dar muchísimo juego y las opciones pueden ser muchas. En este caso, no necesito inventar atributos ni etiquetas, que se podría hacer pero mantendremos un marcado estándar. Es decir:<br />
Puedes seguir usando una etiqueta de imagen pero para aplicar dimensiones y posiciones deberías usar o <em>peripecias</em> o marcado no válido como atributos raros que luego tendrías que eliminar con JS. En este caso deberías inventar algo para posicionar el fondo. ¿El atributo rel?, no, rel por mucho que nos pueda servir y sea estándar no es para eso&#8230; pero ¿por qué seguir pensando?:<br />
OBJECT: Se creó para esto justamente, admite más atributos que son completamente coherentes. Admite contenido alternativo. Admite parámetros de configuración que se abstraen precisamente del marcado que es lo que realmente queremos.</p>
<h5>¿Por qué Javascript?</h5>
<p>Aunque la tercera cuestión es la más importante, con Javascript, y jQuery en concreto, fabricas una funcionalidad más sólida que, como ya he dicho antes, con CSS avanzado y parcialmente soportado, aunque igualmente la base de todo sea XPath (<em>aludimos a los selectores avanzados de CSS</em>).</p>
<h5>¿Por qué XML?</h5>
<p>Lo bueno de XML y que tu maquetación básica sea estándar, es, por ejemplo, el uso de Javascript:<br />
Mañana, si quiero eliminar el Javascript puedo hacerlo perfectamente y la funcionalidad de la imagen -el marcado XHTML estándar y semántico- va a seguir prácticamente igual. En este ejemplo se desproporciona la imagen pero es corregible mediante CSS si se desea.<br />
Otra opción, al ser XML, es que puedes aplicarle por ejemplo XSLT si lo prefieres.</p>
<p>En definitiva, hay muchísimas opciones desarrollando en XML, desde que conocí el lenguaje no he hecho otra cosa más que ver sus ventajas :D</p>
<h5>Marcado estándar, coherente y semántico</h5>

<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="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;headerImg&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;object</span> <span style="color: #000066;">data</span>=<span style="color: #ff0000;">&quot;http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;200px&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;background-position&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;0% 30%&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cristina Scabbia de Lacuna Coil.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Con Mime type:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">[...]<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;object</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;image/jpeg&quot;</span> <span style="color: #66cc66;">&#91;</span>...<span style="color: #66cc66;">&#93;</span></span></pre></td></tr></table></div>

<p>Todo es válido, estándar, semántico y sencillo.<br />
Para object puedes establecer incluso el mimetype, puedes establecer como contenido alternativo tu imagen y gestionarla de nuevo con lo que prefieras. Bastaría con meter dentro de la etiqueta del objeto el contenido alternativo, en este caso nuestra imagen que queremos mostrar, e igualmente aplicarle cambios, o dinámicos, o mediante estilos, o volviendo a los inicios, con estilos incrustados:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;headerImg&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;object</span> <span style="color: #000066;">data</span>=<span style="color: #ff0000;">&quot;http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">height</span>=<span style="color: #ff0000;">&quot;200px&quot;</span> <span style="color: #000066;">width</span>=<span style="color: #ff0000;">&quot;100%&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;background-position&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;0% 30%&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;img</span> </span>
<span style="color: #009900;">			<span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://farm1.static.flickr.com/41/115559256_918ab03490_o_d.jpg&quot;</span> </span>
<span style="color: #009900;">			<span style="color: #000066;">alt</span>=<span style="color: #ff0000;">&quot;Texto alternativo&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;estilos CSS&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/object<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Cristina Scabbia de Lacuna Coil.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Y&#8230; vuelta a empezar por ejemplo con modificaciones JavaScript si queremos.</p>
<p>Es decir, este es el proceso por descarte:<br />
XHTML válido + Javascript <tt>-si falla Javascript-></tt><br />
XHTML válido y usable <tt>-si falla XHTML (object)-></tt><br />
marcado usable tradicional que, aun pudiendo no ser válido, igualmente era la primera opción.</p>
<h5>Proceso con jquery</h5>
<p>Pues como siempre que usamos esta fantástica librería, muy sencillo: Un poco de XPath y ya está.</p>
<h6>Código Javascript</h6>
<p>Bueno&#8230; un poco, pero obviamente se puede y debe mejorar con lo cual te extiendes un poco más y te puede salir algo así:</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
</pre></td><td class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #003366; font-weight: bold;">function</span> imageHeaderPosts<span style="color: #009900;">&#40;</span>elm<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> jQuery<span style="color: #009900;">&#40;</span>elm<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #006600; font-style: italic;">// INIT:</span>
		<span style="color: #003366; font-weight: bold;">var</span> errorMsg	<span style="color: #339933;">=</span> <span style="color: #3366CC;">'No se puede crear un visor de imagen para '</span> <span style="color: #339933;">+</span> elm <span style="color: #339933;">+</span> <span style="color: #3366CC;">'.'</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> parentElm	<span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span>elm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> objectElm	<span style="color: #339933;">=</span> parentElm.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'object'</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> <span style="color: #003366; font-weight: bold;">true</span> <span style="color: #339933;">!==</span> objectElm.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">0</span> <span style="color: #009900;">&#41;</span>
			<span style="color: #000066; font-weight: bold;">throw</span> <span style="color: #003366; font-weight: bold;">new</span> Error<span style="color: #009900;">&#40;</span>errorMsg <span style="color: #339933;">+</span> <span style="color: #3366CC;">' No contiene un objeto a procesar.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> bckgImg<span style="color: #339933;">,</span> imgHeight<span style="color: #339933;">,</span> bckgColor<span style="color: #339933;">,</span> bckgPos<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Atributos por defecto:</span>
		<span style="color: #003366; font-weight: bold;">var</span> defImgHeight<span style="color: #339933;">=</span> <span style="color: #3366CC;">'200px'</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> defBckgImg<span style="color: #339933;">=</span> <span style="color: #3366CC;">''</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> defBckgColor<span style="color: #339933;">=</span> <span style="color: #3366CC;">'#333'</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> defBckgPos	<span style="color: #339933;">=</span> <span style="color: #3366CC;">'0% 20%'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// VISOR:</span>
		imgHeight 	<span style="color: #339933;">=</span> objectElm.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'height'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		bckgImg 		<span style="color: #339933;">=</span> objectElm.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'data'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		bckgColor 	<span style="color: #339933;">=</span> objectElm.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'param[name=background-color]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		bckgPos 		<span style="color: #339933;">=</span> objectElm.<span style="color: #660066;">children</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'param[name=background-position]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Check:</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'undefined'</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>imgHeight<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> 
			imgHeight	<span style="color: #339933;">=</span> defImgHeight<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'undefined'</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>bckgImg<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> 
			bckgImg		<span style="color: #339933;">=</span> defBckgImg<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'undefined'</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>bckgColor<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> 
			bckgColor	<span style="color: #339933;">=</span> defBckgColor<span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'undefined'</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>bckgPos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> 
			bckgPos		<span style="color: #339933;">=</span> defBckgPos<span style="color: #339933;">;</span>
		<span style="color: #006600; font-style: italic;">// Run...</span>
		parentElm.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #3366CC;">'height'</span><span style="color: #339933;">:</span>				imgHeight<span style="color: #339933;">,</span> 
			<span style="color: #3366CC;">'background-color'</span><span style="color: #339933;">:</span>		bckgColor<span style="color: #339933;">,</span> 
			<span style="color: #3366CC;">'background-image'</span><span style="color: #339933;">:</span>	<span style="color: #3366CC;">'url('</span> <span style="color: #339933;">+</span> bckgImg <span style="color: #339933;">+</span> <span style="color: #3366CC;">')'</span><span style="color: #339933;">,</span> 
			<span style="color: #3366CC;">'background-position'</span><span style="color: #339933;">:</span>	bckgPos<span style="color: #339933;">,</span> 
			<span style="color: #3366CC;">'background-repeat'</span><span style="color: #339933;">:</span>	<span style="color: #3366CC;">'no-repeat'</span><span style="color: #339933;">,</span> 
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		objectElm.<span style="color: #660066;">remove</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;">&#125;</span>
<span style="color: #006600; font-style: italic;">// Lanzar:</span>
imageHeaderPosts<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div.headerImg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Como hemos dicho antes, lo único que hacemos es aprovechar los parámetros de configuración del objeto. Nosotros les aplicamos JavaScript, pero están ahí para cualquier otro lenguaje o proceso. La cuestión es mantener el marcado coherente, limpio y sin fabricar <em>cosas raras</em> :)</p>
<p>Sobre el comportamiento en sí es necesario aclarar: Usamos una división contenedor tanto para buscarla como para aplicarle cambios: <tt>&lt;div class="headerImg"&gt;</tt> pero también podríamos actuar directamente sobre el elemento <tt>object</tt> con unas cuantas modificaciones más.</p>
<h4>Resultado</h4>
<div class="wp-caption alignleft"><a href="http://blog.culturadigital.org/media/2009/10/ImagenBonitaCabecera.png" title="Cabecera bonita usando XHTML (object) y modificaciones Javascript" rel="group_gallery"><img src="http://blog.culturadigital.org/media/2009/10/ImagenBonitaCabecera-300x177.png" alt="Ejemplo de imagen bonita de cabecera" title="ImagenBonitaCabecera" width="300" height="177" class="size-medium wp-image-590" /></a>
<p class="wp-caption-text">Cabecera bonita usando XHTML (object) y Javascript</p>
</div>
<div class="wp-caption alignleft"><a href="http://blog.culturadigital.org/media/2009/10/EjemploObjectsinJavascript.png" title="Cabecera bonita usando XHTML (object) SIN Javascript" rel="group_gallery"><img src="http://blog.culturadigital.org/media/2009/10/EjemploObjectsinJavascript-300x166.png" alt="Cabecera bonita usando object sin Javascript" title="EjemploObjectsinJavascript" width="300" height="166" class="size-medium wp-image-632" /></a>
<p class="wp-caption-text">Cabecera bonita usando XHTML (object) SIN Javascript</p>
</div>
<p><br class="clear" /></p>
<div class="wp-caption alignleft"><a href="http://blog.culturadigital.org/media/2009/10/CabeceraBonitaJavascript.png" title="Cabecera bonita con object y Javascript" rel="group_gallery"><img src="http://blog.culturadigital.org/media/2009/10/CabeceraBonitaJavascript-300x115.png" alt="Cabecera bonita con object y Javascript" title="CabeceraBonitaJavascript" width="300" height="115" class="size-medium" /></a>
<p class="wp-caption-text">Cabecera bonita con object y Javascript</p>
</div>
<div class="wp-caption alignleft"><a href="http://blog.culturadigital.org/media/2009/10/CabeceraBonitaSinJavascript.png" title="Cabecera bonita con object SIN Javascript" rel="group_gallery"><img src="http://blog.culturadigital.org/media/2009/10/CabeceraBonitaSinJavascript-300x116.png" alt="Cabecera bonita con object y Javascript" title="CabeceraBonitaJavascript" width="300" height="115" class="size-medium" /></a>
<p class="wp-caption-text">Cabecera bonita con object SIN Javascript</p>
</div>
<h4 class="clear">Otras consideraciones</h4>
<p>Algunas otras aplicaciones y/o alternativas y en las que he pensado mientras escribía esto han sido: usar tu propio Namespace -más válido-; si usas Wordpress, tu filtro para etiquetas propias; o simplemente CSS experimental:</p>
<dl>
<dt>Wordpress</dt>
<dd>Si usas Wordpress, quizá una solución más heterodoxa sea aplicar filtros propios para generar etiquetas.<br />
Este es un ejemplo sencillo del uso de filtros para aplicar al contenido:</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="php" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #000000; font-weight: bold;">function</span> myFilterTest<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$content</span>	<span style="color: #339933;">=</span> <span style="color: #990000;">str_ireplace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;test&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;strong&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$content</span>	<span style="color: #339933;">=</span> <span style="color: #990000;">str_ireplace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;/test&gt;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/strong&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Más técnico y costoso:</span>
	<span style="color: #666666; font-style: italic;">//$content	= preg_replace('#\&lt;test\&gt;(.*?)\&lt;/test\&gt;#si', '&lt;strong&gt;\1&lt;/strong&gt;', $content);</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'myFilterTest'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Para aplicarlo a este ejemplo ya depende de tu imaginación.</dd>
<dt>Namespace propio</dt>
<dd>Etiquetas propias con un «Namespace» propio también puede parecer demasiado extremo :mrgreen:<br />
No obstante, lo mismo lo pruebo &#8230;porque de lo que se trata es de experimentar ;)</dd>
<dt>CSS</dt>
<dd>Por último y como dije al principio, también es posible mediante CSS pero si pensamos, por ejemplo, en la posibilidad de que Javascript esté deshabilitado&#8230; es mucho más probable que el navegador no soporte los selectores avanzados de CSS entre otras características.</dd>
</dl>
]]></content:encoded>
			<wfw:commentRss>http://blog.culturadigital.org/tecnologia/desarrollo-web/jquery-imagenes-de-cabecera-semanticas-y-limpias-para-xhtml/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery: Solución al max-&amp;min CSS en IE</title>
		<link>http://blog.culturadigital.org/tecnologia/desarrollo-web/jquery-solucion-al-max-min-css-en-ie</link>
		<comments>http://blog.culturadigital.org/tecnologia/desarrollo-web/jquery-solucion-al-max-min-css-en-ie#comments</comments>
		<pubDate>Sun, 06 Sep 2009 18:13:47 +0000</pubDate>
		<dc:creator>J.A.Cobo</dc:creator>
				<category><![CDATA[Desarrollo web]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[dimensions]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[ie]]></category>
		<category><![CDATA[internet-explorer]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[max-width]]></category>
		<category><![CDATA[min-width]]></category>

		<guid isPermaLink="false">http://blog.culturadigital.org/?p=379</guid>
		<description><![CDATA[Si es que jQuery es una maravilla :D
Información:Esta entrada es antigua, se ha reabierto -y actualizado un poco- pero data de al menos casi dos años, de ahí referencias obsoletas a temas como «dimensions», el cual se incluye hace tiempo ya como base de «jQuery».
Un poco de Off Topic:
Si hay algún lector habitual de Cultura [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Si es que jQuery es una maravilla</strong> :D</p>
<p class="info"><strong>Información</strong>:<br />Esta entrada es antigua, se ha reabierto -<em>y actualizado un poco</em>- pero data de al menos casi dos años, de ahí referencias obsoletas a temas como «<em>dimensions</em>», el cual se incluye hace tiempo ya como base de «jQuery».</p>
<p>Un poco de Off Topic:</p>
<blockquote><p>Si hay algún lector habitual de Cultura Digital ya conocerá mi habitual tendencia a irme por las ramas o establecer contextos sobre el tema central de la entrada&#8230; Qué le voy a hacer, después de todo, esto es un blog -un blog nacido con pretensiones artísticas- no un compendio de artículos técnico-temáticos; así que siempre me voy a permitir la libertad de divagar -y puede que incluso utilizando recursos literarios- un poco o un mucho, según me de ;)</p></blockquote>
<p>Pero en fin, por ahora, vamos con ello:</p>
<h4>Contexto</h4>
<p>Aunque llevaba tiempo resignado aún habiendo soluciones, tampoco era un problema demasiado severo siempre que diseñaras en «fixed». Recordé que Cameron Moll, en el famoso «CSS Mastering» de Andy Budd -la traducción de Anaya&reg; no es gran cosa- indicaba una expresión propietaria de <acronym title="(Microsoft) Internet Explorer">IE</acronym> con JavaScript para «solucionar» el problema.</p>
<h5>Soluciones habituales</h5>
<p>En el portátil dónde suelo probar el diseño en IE (Windows XP SP2 + IE6 de casa) no me ha funcionado, está a 1024, y ninguna de las otras soluciones que he encontrado, como la del «crack» Dean Edwards, tampoco han servido de mucho. Entre ellas algunos resets de prestigio como el de Yahoo, del mismo Dean Edwards&#8230;<br />
<ins datetime="2009-09-06T18:20:19+00:00">
<p class="info"><strong>Información</strong><br />Actualizado: Hoy por hoy -09/09-, el mismo Edwards ha desarrollado soluciones de compatibilidad con estándares, y en este caso en concreto con CSS, dónde evidentemente ya podemos usar min-width, max-width y muchos otros, no sé cuantos, pseudo-selectores en casi o todas las versiones IE, al menos 6, 7 y 8.<br />
Enlace: <a href="http://dean.edwards.name/weblog/2008/01/ie7-2/" title="Enlace a la entrada en el blog de Dean">Dean Edwards IE7 Actualizaciones</a></p>
<p></ins></p>
<h5>Test</h5>
<p>El caso es que el resultado de <tt>laguardiadejaen.com</tt> para IE, con unos pocos arreglos sobre imágenes y un CSS con unas 6/7 reglas para solucionar problemas específicos, no difiere mucho del diseño basado en estándares o por ejemplo del resultado en FF (Firefox). Pero&#8230; tenía un inconveniente bastante desagradable que me alarmó al ver los accesos por resoluciones de pantalla:</p>
<h5>Resoluciones de usuario</h5>
<p>El último cambio de <em>look</em> se basaba en esto, una ampliación de la anchura gracias a la creciente facilidad para adquirir pantallas planas o monitores -¿monitores?&#8230; me atrevería a decir que prácticamente se han extinguido en el ámbito doméstico-, pues eso: resolví que 1260 podría ser en poco tiempo la media&#8230; de hecho, casi lo es ya, pero por ahora continuamos en 1024.<br />
Así que cambié a un diseño fluido de 1000 píxeles mínimos, algo justo pero válido para resoluciones de 1024, y 1260 de máxima anchura para resoluciones más grandes y que no diera un ancho excesivo.</p>
<p>Bien&#8230; pues encontré que había bastantes accesos a 800&#8230;, ¡Dios! -aún no había tanto acceso con pda&#8217;s, móviles, etc-. A 800 y con I. Explorer, sin poder usar <tt>min-width</tt>, ufff&#8230; aunque no hice nada en ese momento -había cosas más serias-, al final era inevitable usar una solución en un trabajo para un organismo público:</p>
<h4>La solución: de nuevo jQuery</h4>
<p><strong>Dimensions</strong>:<br />
En una entrada anterior hablaba de como me sorprendió este plugin para jQuery&#8230; Así que después de probar mil y un <em>hacks</em> que, como decía, no me convencieron y sobre todo, no funcionaban (por ejemplo para usar un reset debes usarlo desde el principio&#8230; y el que estés usando seguir usándolo), decidí probar con JavaScript, jQuery y su plugin Dimensions:</p>
<h5>Código JS</h5>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">// &lt;![CDATA[</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>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> jQuery.<span style="color: #660066;">browser</span>.<span style="color: #660066;">msie</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		jQuery<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">resize</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> windowWidth 	<span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> wrapper 		<span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#wrapper'</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> <span style="color: #3366CC;">'number'</span> <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>windowWidth<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #3366CC;">'object'</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>wrapper<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;">if</span> 		<span style="color: #009900;">&#40;</span> windowWidth <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">1000</span> <span style="color: #009900;">&#41;</span>	wrapper.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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> windowWidth <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">1260</span> <span style="color: #009900;">&#41;</span>	wrapper.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1260</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000066; font-weight: bold;">else</span>							wrapper.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'98%'</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>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// ]]&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Y para hacer un test dejo esto:</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
</pre></td><td class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">// &lt;![CDATA[</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>
	<span style="color: #006600; font-style: italic;">// IE, simular max y min-width con dimensions:</span>
	jQuery<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">resize</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> windowWidth	<span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> wrapper		<span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#wrapper'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> wrapperWidth	<span style="color: #339933;">=</span> wrapper.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> msgWindow	<span style="color: #339933;">=</span> <span style="color: #3366CC;">'Resolución: '</span> <span style="color: #339933;">+</span> windowWidth<span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> msgWrapper	<span style="color: #339933;">=</span> <span style="color: #3366CC;">'Wrapper ajustado a: '</span> <span style="color: #339933;">+</span> wrapperWidth<span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> windowWidth <span style="color: #339933;">&lt;</span> <span style="color: #CC0000;">1000</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			wrapper.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>msgWindow <span style="color: #339933;">+</span> <span style="color: #3366CC;">' min-width activo!.'</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span> msgWrapper<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> windowWidth <span style="color: #339933;">&gt;</span> <span style="color: #CC0000;">1260</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			wrapper.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1260</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>msgWindow <span style="color: #339933;">+</span> <span style="color: #3366CC;">' max-width activo!.'</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span> msgWrapper<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
			wrapper.<span style="color: #660066;">width</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'98%'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>msgWindow <span style="color: #339933;">+</span> <span style="color: #3366CC;">' dentro de los límites.'</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">'<span style="color: #000099; font-weight: bold;">\n</span>'</span> <span style="color: #339933;">+</span> msgWrapper<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>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">// ]]&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Obviamente, en un navegador estándar, restrinjo el ancho con la división <tt>wrapper</tt> que envuelve la maquetación, un 98% me parece bien para aplicar un pequeño margen en resoluciones inferiores a 1260 y en concreto a 1024 trabajando a 1000 píxeles más o menos.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.culturadigital.org/tecnologia/desarrollo-web/jquery-solucion-al-max-min-css-en-ie/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Breve tutorial Facebook Connect rápido de verdad</title>
		<link>http://blog.culturadigital.org/tecnologia/desarrollo-web/breve-tutorial-facebook-connect-rapido-de-verdad</link>
		<comments>http://blog.culturadigital.org/tecnologia/desarrollo-web/breve-tutorial-facebook-connect-rapido-de-verdad#comments</comments>
		<pubDate>Mon, 17 Aug 2009 07:57:25 +0000</pubDate>
		<dc:creator>J.A.Cobo</dc:creator>
				<category><![CDATA[Desarrollo web]]></category>
		<category><![CDATA[Diseño web]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Connect]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[mashups]]></category>

		<guid isPermaLink="false">http://blog.culturadigital.org/?p=507</guid>
		<description><![CDATA[Antes de nada comentaré que es una de las pocas modas en la web, y en concreto en la blogosfera, que me parece bastante útil y que me gusta bastante -si usas «Facebook» claro, &#8230;y si no: acabarás usándolo xP-. Sé que ya antes existía «OpenId» y tal y que caminamos, de forma irremediable, a [...]]]></description>
			<content:encoded><![CDATA[<p>Antes de nada comentaré que es una de las pocas modas en la web, y en concreto en la <em>blogosfera</em>, que me parece bastante útil y que me gusta bastante -si usas «Facebook» claro, &#8230;y si no: acabarás usándolo xP-. Sé que ya antes existía «OpenId» y tal y que caminamos, de forma irremediable, a la globalización totalmente ya total :D en la que, ya de verdad, tendremos una identidad única y global en la red -la unión de servicios como FB Connect, Google FC, OpenId&#8230; creo que no debe tardar-; espero que siempre y cuando así lo deseemos.</p>
<p>Además, piensa que, en el caso de los comentarios de un blog por ejemplo, se ahorran implementaciones extra y recursos como chequeos de usuarios -aunque siga habiendo spam en Facebook- ya que, en general, se usa una gestión externa con los beneficios que ello conlleva, aunque también, obviamente, sus desventajas.</p>
<p class="alert"><ins datetime="2010-01-16T09:51:20+00:00" title="Añadido 16/01/2010" class="nodecoration">(16/01/2010) <strong>Muy importante</strong>: No estoy seguro porque no he hecho todas las pruebas necesarias, pero al menos a mí, en dos servidores y aplicaciones distintas:<br />El script (js) de la librería de Facebook <strong class="red">me da error sirviendo como: <tt>application/xhtml+xml</tt></strong>, es decir XML de verdad.<br />En el blog funciona porque se sirve como html plano, al menos el documento real, las cabeceras; el marcado, DocType y tal es otro tema aunque debería ser el mismo.<br />Es decir: <strong class="blue">Funciona sirviendo como <tt>text/html</tt></strong></ins></p>
<h4>Tutorial rápido</h4>
<p>Bien, en cualquier caso, paso ya a escribir esta especie de minitutorial rápido para aquellos que, pese a darle tanto bombo, resulta que el vídeo de 8 minutos -como ya ha comentado alguien por ahí- no son tan 8 minutos y sí más bien unos cuantos más, sin contar porrazos al teclado estilo «niño alemán de Youtube», etc.</p>
<p>Como siempre recordar que solo pretendo echar una mano a aquellos que, quizá como yo, se hayan atrancado intentando implementar el servicio por su cuenta o a través de plugins. Personalmente soy bastante poco amigo de los plugins -en Wordpress me refiero-&#8230; esto ya es otra historia. aunque reconozco su valía para usuarios web finales que, a decir verdad, hoy no son lo que era antes: Es decir, no hay porqué ser un diseñador o desarrollador web para tener un blog, la verdad.<br />
Así que vamos allá:</p>
<h4>Empecemos</h4>
<p>Al menos, esta es la forma como yo lo he hecho, liberando al sitio web de librerías propias -aunque estoy deseando probarlo al completo en PHP- y creando un sistema más o menos rápido y sencillo mediante la api y librerías de Facebook. Vamos, lo normal.</p>
<h5>1. Creando la conexión Facebook App &#8211; tu blog</h5>
<p>Esto básicamente lo podéis mirar aquí:<br />
<a href="http://wiki.developers.facebook.com/index.php/Facebook_Connect_Tutorial1">Facebook Connect &#8211; Tutorial 1</a>.</p>
<p>Como en el resto de tutoriales que se hayan podido consultar, lo primero es crear tu aplicación en Facebook.<br />
&#8230;hay muchos tutoriales sobre cómo hacer pero lo básico, al margen de estar registrado en Facebook y en la sección de desarrolladores ^^!, sería comentar que hay muuuuuuchos manuales que nos hablan sobre la antigua interfaz de configuración, que ha cambiado, que si canvas url, callback post y delete&#8230; Nos os liéis!!:</p>
<ul>
<li><strong>Nombre de la aplicación</strong></li>
<li><strong>Url Callback</strong> -donde irá vuestro famoso xd_receiver.html-</li>
<li>y, esto no estoy seguro, activar el uso del marcado especial de Facebook -necesitará un namespace extra en el<br />
	documento- <strong>FBML</strong> en lugar de un marco: <strong>iframe</strong>.</li>
</ul>
<p>¡PUNTO!</p>
<h6>En imágenes</h6>

<a href='http://blog.culturadigital.org/tecnologia/desarrollo-web/breve-tutorial-facebook-connect-rapido-de-verdad/attachment/fbconnectcreateapp' title='FBConnectCreateApp'><img width="150" height="150" src="http://blog.culturadigital.org/media/2009/08/FBConnectCreateApp-150x150.png" class="attachment-thumbnail" alt="Facebook Connect: Crear aplicación" title="FBConnectCreateApp" /></a>
<a href='http://blog.culturadigital.org/tecnologia/desarrollo-web/breve-tutorial-facebook-connect-rapido-de-verdad/attachment/fbconnecteditnewapp' title='FBConnectEditNewApp'><img width="150" height="150" src="http://blog.culturadigital.org/media/2009/08/FBConnectEditNewApp-150x150.png" class="attachment-thumbnail" alt="Facebook Connect: Editar aplicación" title="FBConnectEditNewApp" /></a>
<a href='http://blog.culturadigital.org/tecnologia/desarrollo-web/breve-tutorial-facebook-connect-rapido-de-verdad/attachment/fbconnecteditnewapp2blur' title='FBConnectEditNewApp2Blur'><img width="150" height="150" src="http://blog.culturadigital.org/media/2009/08/FBConnectEditNewApp2Blur-150x150.png" class="attachment-thumbnail" alt="Facebook Connect: Editar aplicación, url connect xd_receiver" title="FBConnectEditNewApp2Blur" /></a>

<h5>2. Lo importante de verdad.</h5>
<p>Así es como yo lo he implementado -con JavaScript (parte de jQuery)- en el blog y, hasta ahora, funciona bien.</p>
<p class="alert"><strong>Importante</strong>: Todo el código a continuación, es más o menos a modo rápido de prueba. Por ejemplo, Facebook Connect se debería inicializar con el Bootstrap de la librería (ver wiki), para asegurarse de la carga completa de la misma, el DOM, etc.</p>
<dl>
<dt><strong>Incluye el <tt>Namespace</tt></strong> del marcado de Facebook (FBML):</dt>
<dd><tt>xmlns:fb="http://www.facebook.com/2008/fbml"</tt></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;html</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">xmlns:fb</span>=<span style="color: #ff0000;">&quot;http://www.facebook.com/2008/fbml&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">xml:lang</span>=<span style="color: #ff0000;">&quot;es&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span> <span style="color: #808080; font-style: italic;">&lt;!-- Yo, es que no uso el language_attributes() pero vamos... puedes hacerlo aquí --&gt;</span></pre></div></div>

<p>	Aunque es muy muy pesado, si lo prefieres, imagino que también puedes usar namespaces incrustados en lugar del<br />
	atributo del html; por ejemplo, si vas a generar poco código FBML y todo tú.<br />
	Ej.:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fb:login-button</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.facebook.com/2008/fbml&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;medium&quot;</span> <span style="color: #000066;">length</span>=<span style="color: #ff0000;">&quot;long&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>	Resultado: <fb:login-button xmlns="http://www.facebook.com/2008/fbml" size="medium" length="long" /></dd>
<dt>Incluye el script de Facebook</dt>
<dd>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/es_ES&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">charset</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;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

</dd>
<dt><strong>Archivo <tt>comments.php</tt></strong>:</dt>
<dd>

<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="php" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user_ID</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	...
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	...
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #666666; font-style: italic;">// Facebook Connect ?&gt;</span>
	&lt;p id=&quot;facebookConnect&quot;&gt;
		&lt;span id=&quot;facebookLogin&quot;&gt;&lt;/span&gt;
		&lt;!-- ó &lt;span id=&quot;facebookLogin&quot; /&gt; --&gt;
		&lt;!-- ó incluso &lt;span id=&quot;facebookLogin&quot;/&gt; si sirves xml de verdad --&gt;
	&lt;/p&gt;
	...
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #666666; font-style: italic;">// END Facebook Connect ?&gt;</span>
&nbsp;
	&lt;p id=&quot;userBox&quot;&gt;
		&lt;input 
			type=&quot;text&quot; name=&quot;author&quot; id=&quot;author&quot; 
			value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$comment_author</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; size=&quot;22&quot; tabindex=&quot;1&quot; /&gt; 
		&lt;label for=&quot;author&quot;&gt;
			&lt;span class=&quot;x-small<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$req</span> <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' required'</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
				<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$req</span> <span style="color: #009900;">&#41;</span> ? _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;/span&gt;
		&lt;/label&gt;
	&lt;/p&gt;
&nbsp;
	&lt;p id=&quot;userMail&quot;&gt;
		&lt;input type=&quot;text&quot; name=&quot;email&quot; id=&quot;email&quot; 
			value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$comment_author_email</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; size=&quot;22&quot; tabindex=&quot;2&quot; /&gt; 
		&lt;label for=&quot;email&quot;&gt;
			&lt;span class=&quot;x-small<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$req</span> <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' required'</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
				Email (no se publicar&amp;aacute;) <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$req</span> <span style="color: #009900;">&#41;</span> ? _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'*'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;/span&gt;
		&lt;/label&gt;
	&lt;/p&gt;
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

</dd>
</dl>
<p><strong>Javascript</strong>: Preferiblemente incluir <strong>antes de la etiqueta body</strong> de tu documento. Por ejemplo puedes añadirlo al <tt>wp_footer()</tt>, tú mismo.</p>
<p>Unas <strong>cuántas cuestiones interesantes</strong>:<br />
En estos ejemplos hay ciertas cosas que lo mismo pueden liar a alguien pero son bastante triviales.</p>
<ul>
<li>Por ejemplo aplico mediante jQuery una clase CSS que añade el cursor correspondiente (pointer) &#8211; M$I.E. usa <tt>cursor: hand;</tt> -<br />
Si se prefiere usar CSS al vuelo con jQuery debería bastar con algo como:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'elemento'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'cursor'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'pointer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Pero yo prefiero crear marcado válido incluso si es con JavaScript al vuelo (<em>el método anterior añade estilo incrustado mientras que si usas una clase sigue siendo válido y no intrusivo</em>), además de que es una clase que ya uso normalmente.</li>
<li>También es necesario tener en cuenta los identificadores de los elementos párrafo que engloban las secciones, en este caso nombre y correo: <tt>userBox</tt> y <tt>userMail</tt>; además del <em>wrapper</em> HTML en el botón de login para aplicarle cambios sin tener que tocar el marcado de facebook FBML: <tt>facebookLogin</tt>.</li>
</ul>

<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
</pre></td><td class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">// &lt;![CDATA[</span>
	jQuery<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> apiKey		<span style="color: #339933;">=</span> <span style="color: #3366CC;">'CLAVE_DE_TU_APLICACIÓN_ACCESO_A_LA_API'</span><span style="color: #339933;">;</span>
		<span style="color: #003366; font-weight: bold;">var</span> channelPath	<span style="color: #339933;">=</span> <span style="color: #3366CC;">'URL A TU RECEIVER: xd_receiver.htm'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009966; font-style: italic;">/* DESCONECTADO */</span>
		<span style="color: #003366; font-weight: bold;">function</span> fbNotConnected<span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebookLogin'</span><span style="color: #009900;">&#41;</span>
			.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'pointer'</span><span style="color: #009900;">&#41;</span>
			.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;fb:login-button size=&quot;medium&quot; length=&quot;long&quot; /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			FB.<span style="color: #660066;">XFBML</span>.<span style="color: #660066;">Host</span>.<span style="color: #660066;">parseDomTree</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009966; font-style: italic;">/* CONECTADO */</span>
		<span style="color: #003366; font-weight: bold;">function</span> fbConnected<span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> api			<span style="color: #339933;">=</span> FB.<span style="color: #660066;">Facebook</span>.<span style="color: #660066;">apiClient</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> userUid		<span style="color: #339933;">=</span> api.<span style="color: #660066;">get_session</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">uid</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #003366; font-weight: bold;">var</span> htmlLogin 	<span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;span&gt;&lt;fb:profile-pic uid=&quot;loggedinuser&quot; facebook-logo=&quot;true&quot; linked=&quot;false&quot; '</span>
			<span style="color: #339933;">+</span> <span style="color: #3366CC;">'class=&quot;alignleft&quot; /&gt; Bienvenido &lt;fb:name uid=&quot;loggedinuser&quot; useyou=&quot;false&quot; /&gt;'</span>
			<span style="color: #339933;">+</span> <span style="color: #3366CC;">', estás conectado con tu cuenta de Facebook.'</span>
			<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;fb:user uid=&quot;loggedinuser&quot; /&gt;&lt;fb:website uid=&quot;loggediuserin&quot; /&gt;&lt;/span&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">// Según mi punto de vista, no se debería usar php incrustado -the_permalink()-</span>
			<span style="color: #003366; font-weight: bold;">var</span> htmlLogout 	<span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;a class=&quot;pointer&quot; title=&quot;Desconectar de tu cuenta Facebook y esta web.&quot; '</span>
			<span style="color: #339933;">+</span> <span style="color: #3366CC;">'onclick=&quot;FB.Connect.logoutAndRedirect(<span style="color: #000099; font-weight: bold;">\'</span>&lt;?php the_permalink(); ?&gt;<span style="color: #000099; font-weight: bold;">\'</span>); return false;&quot;&gt;'</span>
			<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;img alt=&quot;Logout&quot; src=&quot;http://static.ak.fbcdn.net/rsrc.php/zDUG0/hash/3g5yiwv5.gif&quot;&gt;&lt;/a&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
			api.<span style="color: #660066;">users_getInfo</span><span style="color: #009900;">&#40;</span>userUid<span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'website'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'profile_url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				fbGenerateFormField<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'author'</span><span style="color: #339933;">,</span> res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				fbGenerateFormField<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'email'</span><span style="color: #339933;">,</span> userUid <span style="color: #339933;">+</span> <span style="color: #3366CC;">'@facebook.com'</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> <span style="color: #3366CC;">'string'</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">website</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#commentform input#url'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'value'</span><span style="color: #339933;">,</span> res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">website</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #006600; font-style: italic;">// Forzar: fbUpdateFormField('url', res[0].website);</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</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: #3366CC;">'string'</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">profile_url</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>  
						jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#commentform input#url'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'value'</span><span style="color: #339933;">,</span> res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">profile_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #006600; font-style: italic;">// Forzar: fbUpdateFormField('url', res[0].profile_url);</span>
				<span style="color: #009900;">&#125;</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;">'#facebookLogin'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>htmlLogout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#userBox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>htmlLogin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#userMail'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			FB.<span style="color: #660066;">XFBML</span>.<span style="color: #660066;">Host</span>.<span style="color: #660066;">parseDomTree</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: #003366; font-weight: bold;">function</span> fbGenerateFormField<span style="color: #009900;">&#40;</span>elId<span style="color: #339933;">,</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> formField <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;input id=&quot;'</span> <span style="color: #339933;">+</span> elId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; name=&quot;'</span> <span style="color: #339933;">+</span> elId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; value=&quot;'</span> <span style="color: #339933;">+</span> value <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; type=&quot;hidden&quot; /&gt;'</span><span style="color: #339933;">;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form#commentform'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>formField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Init setup:</span>
		FB.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span>apiKey<span style="color: #339933;">,</span> channelPath<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> <span style="color: #3366CC;">&quot;ifUserConnected&quot;</span> <span style="color: #339933;">:</span> fbConnected<span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;ifUserNotConnected&quot;</span> <span style="color: #339933;">:</span> fbNotConnected <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: #006600; font-style: italic;">// End jQuery</span>
<span style="color: #006600; font-style: italic;">// ]]&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h4>Explicando el código</h4>
<h5>Inicialización</h5>

<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:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> charset<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;utf-8&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">// &lt;![CDATA[</span>
	<span style="color: #006600; font-style: italic;">// jQuery sin conflicto con la función de dólar de otras librerías</span>
	jQuery<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;">// Init vars: PUB_URL es una variable propia en otro sitio</span>
		<span style="color: #003366; font-weight: bold;">var</span> apiKey		<span style="color: #339933;">=</span> <span style="color: #3366CC;">'CLAVE_DE_TU_APLICACIÓN_PARA_ACCEDER_A_LA_API'</span><span style="color: #339933;">;</span>	<span style="color: #006600; font-style: italic;">// API KEY Facebook</span>
		<span style="color: #003366; font-weight: bold;">var</span> channelPath	<span style="color: #339933;">=</span> PUB_URL <span style="color: #339933;">+</span> <span style="color: #3366CC;">'/xd_receiver.htm'</span><span style="color: #339933;">;</span>						<span style="color: #006600; font-style: italic;">// Url a tu xd_receiver.html</span></pre></td></tr></table></div>

<p><strong>xd_receiver</strong>: A mí al menos me funciona tanto con rutas relativas como con absolutas pero tienes que tener cuidado, si usas redirecciones de cualquier tipo, mod_rewritte, wordpress&#8230;<br />
En mi opinión la mejor forma de comprobarlo es hacer una llamada AJAX al archivo a ver si obtienes una respuesta correcta<br />
<tt>200 OK</tt> al menos. Ej:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">jQuery.<span style="color: #660066;">get</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'tu_receiver_url'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span>response<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: #006600; font-style: italic;">// O prueba con post</span></pre></div></div>

<h5>Estado: Desconectado</h5>
<p><strong>Desconectado</strong>: Se puede generar FBML, XHTML&#8230; Yo recomiendo usar FBML siempre que sea posible para evitar problemas, por ejemplo de carga del DOM por otras librerías si se usan -ej. jQuery- y la de Facebook. Obviamente, esto se puede -y debe- mejorar, crear un plugin jQuery&#8230; pero eso ahora no corresponde.</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:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">		<span style="color: #009966; font-style: italic;">/* DESCONECTADO */</span>
		<span style="color: #006600; font-style: italic;">// Mostrar login:</span>
		<span style="color: #003366; font-weight: bold;">function</span> fbNotConnected<span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebookLogin'</span><span style="color: #009900;">&#41;</span>
			.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'pointer'</span><span style="color: #009900;">&#41;</span> <span style="color: #006600; font-style: italic;">// Clase CSS que añade el cursor correspondiente al botón padre span.</span>
			.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'&lt;fb:login-button size=&quot;medium&quot; length=&quot;long&quot; /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">// Parsear el DOM FB</span>
			FB.<span style="color: #660066;">XFBML</span>.<span style="color: #660066;">Host</span>.<span style="color: #660066;">parseDomTree</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h5>Estado: Desconectado, versión DOM</h5>
<p>Ejemplo rápido DOM. Ojo, se puede usar la librería de gestión del DOM de Facebook, pero yo aún no la he mirado. Sé que al menos usa la «función del dólar».</p>
<p><strong>Desconectado</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">		<span style="color: #009966; font-style: italic;">/* DESCONECTADO */</span>
		<span style="color: #006600; font-style: italic;">// Mostrar login:</span>
		<span style="color: #003366; font-weight: bold;">function</span> fbNotConnected<span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> userBoxLogin <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'facebookLogin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			userBoxLogin.<span style="color: #660066;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'style'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'cursor:pointer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// cursor:hand para IE.</span>
			<span style="color: #006600; font-style: italic;">// Es un coñazo -y más con namespace extras- pero no voy a usar el puto innerHTML de M$</span>
			<span style="color: #003366; font-weight: bold;">var</span> fbLogin <span style="color: #339933;">=</span> document.<span style="color: #660066;">createElementNS</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'http://www.facebook.com/2008/fbml'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'fb:login-button'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">// Atributos, imagino, que no registrados xhtml:</span>
			fbLogin.<span style="color: #660066;">setAttributte</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'size'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'medium'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			fbLogin.<span style="color: #660066;">setAttributte</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'length'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'long'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			userBoxLogin.<span style="color: #660066;">appendChild</span><span style="color: #009900;">&#40;</span>fbLogin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">// Parsear el DOM FB</span>
			FB.<span style="color: #660066;">XFBML</span>.<span style="color: #660066;">Host</span>.<span style="color: #660066;">parseDomTree</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><tt>result</tt> es opcional, debería devolver un <tt>null</tt>.</p>
<p>Básicamente generamos marcado Facebook (FBML) al vuelo, con jQuery si el usuario no está conectado y lo parseamos con la librería de Facebook.<br />
Muy importante: Como ya dije, necesitas un Namespace extra para el mismo, tu documento debe soportarlo y, como siempre y en cualquier caso, ¡estar bien formado! ;) <del datetime="2010-01-16T09:54:13+00:00" title="Ver aviso inicial">Yo, como buen talibán XML y anti M$ que soy, recomiendo XHTML1.1 de verdad, es decir, servir application/xhtml+xml que soporta XML</del>, pero ojo con Wordpress que la puede liar. Tú mismo; debería bastarte con un XHTML 1.0 Strict o Transicional.</p>
<p>Del resto se encarga la librería de Facebook al parsear el FBML, en este caso: generando el botón de login y su comportamiento. Se le puede añadir incluso una gestión de login/out -atributo <tt>autologoutlink="(bool)"</tt>-, aunque he preferido hacer el cambio yo mismo.</p>
<h5>Estado: Conectado</h5>
<dl>
<dt><strong>1.</strong> Generar la userbox del usuario y las opciones pertinentes.</dt>
<dd>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">		<span style="color: #009966; font-style: italic;">/* CONECTADO */</span>
		<span style="color: #006600; font-style: italic;">// Update userbox:</span>
		<span style="color: #003366; font-weight: bold;">function</span> fbConnected<span style="color: #009900;">&#40;</span>result<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> api			<span style="color: #339933;">=</span> FB.<span style="color: #660066;">Facebook</span>.<span style="color: #660066;">apiClient</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> userUid		<span style="color: #339933;">=</span> api.<span style="color: #660066;">get_session</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">uid</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">// Html + FBML:</span>
			<span style="color: #003366; font-weight: bold;">var</span> htmlLogin 	<span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;span&gt;'</span>
			<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;fb:profile-pic uid=&quot;loggedinuser&quot; facebook-logo=&quot;true&quot; linked=&quot;false&quot; class=&quot;alignleft&quot; /&gt;'</span>
			<span style="color: #339933;">+</span> <span style="color: #3366CC;">'Bienvenido &lt;fb:name uid=&quot;loggedinuser&quot; useyou=&quot;false&quot; /&gt;'</span>
			<span style="color: #339933;">+</span> <span style="color: #3366CC;">', estás conectado con tu cuenta de Facebook.'</span>
			<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;fb:user uid=&quot;loggedinuser&quot; /&gt;&lt;fb:website uid=&quot;loggediuserin&quot; /&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;/span&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #003366; font-weight: bold;">var</span> htmlLogout 	<span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;a class=&quot;pointer&quot; title=&quot;Desconectar de tu cuenta Facebook y esta web.&quot; '</span>
			<span style="color: #339933;">+</span> <span style="color: #3366CC;">'onclick=&quot;FB.Connect.logoutAndRedirect(<span style="color: #000099; font-weight: bold;">\'</span>&lt;?php the_permalink(); ?&gt;<span style="color: #000099; font-weight: bold;">\'</span>); return false;&quot;&gt;'</span>
			<span style="color: #339933;">+</span> <span style="color: #3366CC;">'&lt;img alt=&quot;Logout&quot; src=&quot;http://static.ak.fbcdn.net/rsrc.php/zDUG0/hash/3g5yiwv5.gif&quot;&gt;&lt;/a&gt;'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

</dd>
<dt><strong>2.</strong> Lo más importante: Conseguir un formulario útil y coherente.</dt>
<dt><strong>2.a</strong> En este sentido existe el problema, que por añadidura es una gran ventaja para los usuarios Facebook, de los permisos para el correo.</dt>
<dd>En concreto, Facebook no distribuye emails de usuarios lo cual me parece absolutamente necesario y genial.<br />
Solo ofrece un servicio comunicación proxy de emails a través de hashes o cadenas codificadas de los mismos que ellos de/codifican. Todo ello en el caso de obtener el permiso del usuario para que nuestra aplicación acceda al servicio de emails; permiso el cual solo es una cuestión ética, ya que podemos obtener la dirección proxy del email, aunque no nos va a servir de nada, al menos hasta que alguien decida intentar conocer la forma en que se codifican.</dd>
<dd>En resumen: Nunca nos van a dar el mail, solo el acceso al servicio.</dd>
<dt><strong>2.b</strong> Otras implementaciones que he visto no realizan lo siguiente; y los plugins, como digo, no me gustan y son muy pesados. Se limitan a enviar un nombre.</dt>
<dd>Nosotros obtendremos el nombre del usuario, un correo sustancialmente inútil pero válido en nuestro caso: id del usuario + cuenta facebook y otros campos a gusto del consumidor: Sitio web del perfil de Facebook, url del perfil, imagen&#8230;</p>
<p>Más detalles en este sentido con una simple búsqueda web por Facebook Connect: users.getInfo, users.getStandarInfo&#8230;, FQL User Tables, etc.</dd>
<dt><strong>3.b</strong> Por fin, rellenaremos el formulario vía JavaScrit y jQuery a ser posible, aunque podemos usar el DOM puro y duro.</dt>
<dd>Aquí ya depende de cada uno como hacerlo:<br />
	Se pueden rellenar los campos de forma visible al usuario para que pueda modificarlo si quiere, -lo más correcto y honesto-.<br />
	Se pueden rellenar de forma silenciosa para evitar cambios no deseados -en la mayoría de los casos el usuario no sabrá cambiarlos aunque es perfectamente posible-.<br />
	Se pueden rellenar justo al enviar el formulario -la forma más vil :mrgreen: aunque se me ocurren otras como es lógico-.</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
</pre></td><td class="code"><pre class="javascript" style="font-family:Consolas, Monaco, 'Lucida Sans Typewriter', 'Lucida Console', 'Andale Mono', monospace;">			<span style="color: #006600; font-style: italic;">// Obtener el nombre:</span>
			api.<span style="color: #660066;">users_getInfo</span><span style="color: #009900;">&#40;</span>userUid<span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'name'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'website'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'profile_url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
				fbGenerateFormField<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'author'</span><span style="color: #339933;">,</span> res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #000066;">name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				fbGenerateFormField<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'email'</span><span style="color: #339933;">,</span> userUid <span style="color: #339933;">+</span> <span style="color: #3366CC;">'@facebook.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #006600; font-style: italic;">// Opcionales: Se pueden forzar o dejar para rellenar por el usuario</span>
				<span style="color: #006600; font-style: italic;">// Sitio Web: Url del sitio web establecido en el perfil o el propio perfil.</span>
				<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">'string'</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">website</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#commentform input#url'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'value'</span><span style="color: #339933;">,</span> res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">website</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #006600; font-style: italic;">// Forzar: fbUpdateFormField('url', res[0].website);</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</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: #3366CC;">'string'</span> <span style="color: #339933;">===</span> <span style="color: #000066; font-weight: bold;">typeof</span><span style="color: #009900;">&#40;</span>res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">profile_url</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#commentform input#url'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'value'</span><span style="color: #339933;">,</span> res<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span>.<span style="color: #660066;">profile_url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #006600; font-style: italic;">// Forzar: fbUpdateFormField('url', res[0].profile_url);</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
			<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #006600; font-style: italic;">// Cambiar la userbox:</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#facebookLogin'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>htmlLogout<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#userBox'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>htmlLogin<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#userMail'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #006600; font-style: italic;">// Parsear el DOM FB</span>
			FB.<span style="color: #660066;">XFBML</span>.<span style="color: #660066;">Host</span>.<span style="color: #660066;">parseDomTree</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: #006600; font-style: italic;">// Helper: Crear nuevos campos en el formulario:</span>
		<span style="color: #003366; font-weight: bold;">function</span> fbGenerateFormField<span style="color: #009900;">&#40;</span>elId<span style="color: #339933;">,</span> value<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003366; font-weight: bold;">var</span> formField <span style="color: #339933;">=</span> <span style="color: #3366CC;">'&lt;input id=&quot;'</span> <span style="color: #339933;">+</span> elId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; name=&quot;'</span> <span style="color: #339933;">+</span> elId <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; value=&quot;'</span> <span style="color: #339933;">+</span> value <span style="color: #339933;">+</span> <span style="color: #3366CC;">'&quot; type=&quot;hidden&quot; /&gt;'</span><span style="color: #339933;">;</span>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'form#commentform'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">append</span><span style="color: #009900;">&#40;</span>formField<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #006600; font-style: italic;">// Init setup:</span>
		FB.<span style="color: #660066;">init</span><span style="color: #009900;">&#40;</span>apiKey<span style="color: #339933;">,</span> channelPath<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #3366CC;">&quot;ifUserConnected&quot;</span> <span style="color: #339933;">:</span> 	fbConnected<span style="color: #339933;">,</span> 
			<span style="color: #3366CC;">&quot;ifUserNotConnected&quot;</span> <span style="color: #339933;">:</span> 	fbNotConnected
		<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: #006600; font-style: italic;">// End jQuery</span>
<span style="color: #006600; font-style: italic;">// ]]&gt;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

</dd>
</dl>
<p>:( &#8230;bueno, al final no ha salido tan <em>breve</em> ni <em>rápido</em> :mrgreen: . Ya haré una versión corta y una demo.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.culturadigital.org/tecnologia/desarrollo-web/breve-tutorial-facebook-connect-rapido-de-verdad/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
