<?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>Mas que Wordpress - Tutoriales, recursos web, JQuery y PHP, Wordpress , twitter y muchos recursos más &#187; tutorial jquery</title>
	<atom:link href="http://www.masquewordpress.com/tag/tutorial-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.masquewordpress.com</link>
	<description>Tutoriales y recursos web sobre JQuery , PHP, Wordpress , twitter. Aprende diseño web y programación</description>
	<lastBuildDate>Mon, 06 Feb 2012 15:02:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Enviar formularios con AJAX y jQuery parte II</title>
		<link>http://www.masquewordpress.com/enviar-formularios-con-ajax-y-jquery/</link>
		<comments>http://www.masquewordpress.com/enviar-formularios-con-ajax-y-jquery/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 20:33:17 +0000</pubDate>
		<dc:creator>Damian</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutoriales]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[formularios]]></category>
		<category><![CDATA[tutorial jquery]]></category>

		<guid isPermaLink="false">http://www.masquewordpress.com/?p=1169</guid>
		<description><![CDATA[Hace mucho tiempo escribí en el blog como enviar un formulario con AJAX y jQuery mediante el plugin jquery.form.js. A día de hoy y con mucha más experiencia en jQuery prefiero escribir mis propios códigos en lugar de utilizar tantos plugins. Por lo que hoy les voy a explicar como enviar un formulario con AJAX [...]]]></description>
			<content:encoded><![CDATA[<p>Hace mucho tiempo escribí en el blog <a href="http://www.masquewordpress.com/como-enviar-un-formulario-via-ajax-con-jquery/">como enviar un formulario con AJAX y jQuery</a> mediante el plugin jquery.form.js. A día de hoy y con mucha más experiencia en jQuery prefiero escribir mis propios códigos en lugar de utilizar tantos plugins.<br />
Por lo que hoy les voy a explicar como enviar un formulario con AJAX gracias a jQuery y sin usar ningún plugin.<br />
<span id="more-1169"></span></p>
<p>Para seguir el mismo ejemplo que en el otro post vamos a utilizar el mismo formulario:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;form id=&quot;myForm&quot; action=&quot;contacto.php&quot; method=&quot;post&quot; style=&quot;height:200px;&quot;&gt; 
    &lt;label&gt;Nombre:&lt;/label&gt; &lt;input type=&quot;text&quot; name=&quot;name&quot; /&gt; 
    &lt;label&gt;Mensaje:&lt;/label&gt; &lt;textarea name=&quot;mensaje&quot;&gt;&lt;/textarea&gt; 
    &lt;input type=&quot;submit&quot; value=&quot;Enviar&quot; /&gt; &lt;div id=&quot;ajax_loader&quot;&gt;&lt;img id=&quot;loader_gif&quot; src=&quot;loader.gif&quot; style=&quot; display:none;&quot;/&gt;&lt;/div&gt;
&lt;/form&gt;</pre></div></div>

<p>Pero ahora para enviar el formulario tan solo haremos uso de algunas funciones de jQuery como son : </p>
<ul>
<li><a href="http://api.jquery.com/serialize/">.serialize()</a> : encargada de codificar todos los valores del formulario en una cadena para ser pasada.</li>
<li><a href="http://api.jquery.com/submit/">.submit()</a>: encargada de añadir al evento submit del formulario la función que usaremos para enviar el mismo.</li>
<li><a href="http://api.jquery.com/jQuery.ajax/">jQuery.ajax()</a>: encargada de realizar AJAX request.</li>
</ul>
<p>Nuestro nuevo script quedaría de la siguiente manera:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">        $<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ready<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
&nbsp;
          $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#myForm'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>submit<span style="color: #009900;">&#40;</span><span style="color: #000000; 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: #666666; font-style: italic;">//en el evento submit del fomulario</span>
	          event<span style="color: #339933;">.</span>preventDefault<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//detenemos el comportamiento por default</span>
&nbsp;
			  <span style="color: #000000; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>attr<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//la url del action del formulario</span>
			  <span style="color: #000000; font-weight: bold;">var</span> datos <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #990000;">serialize</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;">// los datos del formulario</span>
			  $<span style="color: #339933;">.</span>ajax<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
				  type<span style="color: #339933;">:</span> <span style="color: #0000ff;">'POST'</span><span style="color: #339933;">,</span>
				  url<span style="color: #339933;">:</span> url<span style="color: #339933;">,</span>
				  data<span style="color: #339933;">:</span> datos<span style="color: #339933;">,</span>
				  beforeSend<span style="color: #339933;">:</span> mostrarLoader<span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//funciones que definimos más abajo</span>
				  success<span style="color: #339933;">:</span> mostrarRespuesta  <span style="color: #666666; font-style: italic;">//funciones que definimos más abajo</span>
			   <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
          <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
&nbsp;
&nbsp;
&nbsp;
&nbsp;
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> mostrarLoader<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
              $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#loader_gif'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>fadeIn<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//muestro el loader de ajax</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">function</span> mostrarRespuesta <span style="color: #009900;">&#40;</span>responseText<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	          alert<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Mensaje enviado: &quot;</span><span style="color: #339933;">+</span>responseText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//responseText es lo que devuelve la página contacto.php. Si en contacto.php hacemos echo &quot;Hola&quot; , la variable responseText = &quot;Hola&quot; . Aca hago un alert con el valor de response text</span>
	          $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#loader_gif&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>fadeOut<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Hago desaparecer el loader de ajax</span>
	          $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#ajax_loader&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>append<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;br&gt;Mensaje: &quot;</span><span style="color: #339933;">+</span>responseText<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Aca utilizo la función append de JQuery para añadir el responseText  dentro del div &quot;ajax_loader&quot;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div>

<p><div class="avia-box info    "><span class="avia-innerbox" >Pueden ver un ejemplo online en <a href="http://masquewordpress.com/ejemplos/enviar-formulario-con-ajax-jquery/">&#8220;Como enviar un formulario AJAX con jQuery&#8221;</a></span></div><br />
<div class="avia-box download   rounded "><span class="avia-innerbox" >Pueden descargar el código antiguo en <a href="http://www.masquewordpress.com/como-enviar-un-formulario-via-ajax-con-jquery/">este post</a> </span></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.masquewordpress.com/enviar-formularios-con-ajax-y-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scroll con Jquery sin plugins</title>
		<link>http://www.masquewordpress.com/scroll-con-jquery-sin-plugins/</link>
		<comments>http://www.masquewordpress.com/scroll-con-jquery-sin-plugins/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 14:06:42 +0000</pubDate>
		<dc:creator>Damian</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutoriales]]></category>
		<category><![CDATA[scroll]]></category>
		<category><![CDATA[tutorial jquery]]></category>

		<guid isPermaLink="false">http://www.masquewordpress.com/?p=1103</guid>
		<description><![CDATA[Uno de los post más consultados en mi blog es el de  , que no es ni más ni menos que un plugin para animar la pantalla en lugar de usar los aburridos y anticuados anchors de HTML. Como en dicho en montón de oportunidades no siempre me gusta usar plugin para realizar tareas sencillas. [...]]]></description>
			<content:encoded><![CDATA[<p>Uno de los post más consultados en mi blog es el de <a href="http://www.masquewordpress.com/jquery-scrollto-olvidate-de-usar-anchors-aburridos/">jQuery.ScrollTo</a> , que no es ni más ni menos que un plugin para animar la pantalla en lugar de usar los aburridos y anticuados anchors de HTML. Como en dicho en montón de oportunidades no siempre me gusta usar plugin para realizar tareas sencillas.</p>
<p>En el caso de un scroll , si lo que quieren es animar la pantalla para volver a la parte superior de sus sitios webs no hay nada más sencillo para hacer que lo siguiente:</p>
<p><span id="more-1103"></span></p>
<p>Por ejemplo si en el header a nuestro logo le agregamos la clase <strong>.top-page</strong></p>
<p>En el footer podemos colocar un link, una imagen o lo que ustedes quieran como por ejemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;a class=&quot;top&quot; href=&quot;top-page&quot;&gt;Click para subir &lt;/a&gt;</pre></td></tr></table></div>

<p>Por último agregamos el código jQuery encargado de animar nuestro anchor.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'document'</span><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: #009900;">&#40;</span><span style="color: #3366CC;">'.top'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #003366; font-weight: bold;">var</span> elementClicked <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;href&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> destination <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #339933;">+</span>elementClicked<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">offset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">top</span><span style="color: #339933;">;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;html:not(:animated),body:not(:animated)&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span> scrollTop<span style="color: #339933;">:</span> destination<span style="color: #339933;">-</span><span style="color: #CC0000;">20</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<a target="_blank" href="http://www.masquewordpress.com/ejemplos/scroll-con-jquery-facil/" class="avia-button  dark xl" ><span class="avia-note">Ver Ejemplo Online</span></a>
]]></content:encoded>
			<wfw:commentRss>http://www.masquewordpress.com/scroll-con-jquery-sin-plugins/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validar email con Javascript sin un plugin</title>
		<link>http://www.masquewordpress.com/validar-email-con-jquery-sin-un-plugin/</link>
		<comments>http://www.masquewordpress.com/validar-email-con-jquery-sin-un-plugin/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 14:23:28 +0000</pubDate>
		<dc:creator>Damian</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutoriales]]></category>
		<category><![CDATA[tutorial jquery]]></category>

		<guid isPermaLink="false">http://www.masquewordpress.com/?p=960</guid>
		<description><![CDATA[Todos saben que no me gusta instalar cuando tan solo requiero pequeñas funciones. Por ejemplo para validar un email no creo necesario instalar un plugin que realize validación de formularios sino más bien crear una pequeña función que valide dicho email y listo. Con esta pequeña función pueden validad direcciones de email con jQuery Javascript. [...]]]></description>
			<content:encoded><![CDATA[<p>Todos saben que no me gusta instalar <a href="http://www.masquewordpress.com/240-plugins-para-jquery-lo-mejor-de-lo-mejor/">plugins de jQuery</a> cuando tan solo requiero pequeñas funciones. Por ejemplo para validar un email no creo necesario instalar un plugin que realize validación de formularios sino más bien crear una pequeña función que valide dicho email y listo.<br />
<span id="more-960"></span><br />
Con esta pequeña función pueden validad direcciones de email con <del datetime="2012-01-18T17:05:31+00:00">jQuery</del> Javascript.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> validateEmail<span style="color: #009900;">&#40;</span>$email<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> emailReg <span style="color: #339933;">=</span> <span style="color: #009966; font-style: italic;">/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/</span><span style="color: #339933;">;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>emailReg.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span> $email <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</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>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Saludos!!</p>
<p><strong>Update:</strong>Como bien comenta Franz en los comentarios no hay jQuery en este artículo. Eso me pasa por escribir apurado sobre un borrador que tenía preparado que en un principio iba a usar jQuery y luego no fue así. Gracias lectores por estar atentos!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.masquewordpress.com/validar-email-con-jquery-sin-un-plugin/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Diferencia entre $(document).ready y $(window).load en jQuery</title>
		<link>http://www.masquewordpress.com/diferencia-entre-document-ready-y-window-load-en-jquery/</link>
		<comments>http://www.masquewordpress.com/diferencia-entre-document-ready-y-window-load-en-jquery/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 19:07:27 +0000</pubDate>
		<dc:creator>Damian</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutoriales]]></category>
		<category><![CDATA[tutorial jquery]]></category>

		<guid isPermaLink="false">http://www.masquewordpress.com/?p=957</guid>
		<description><![CDATA[Hoy les voy a explicar la principal diferencia entre $(document).ready y $(window).load , funciones esenciales a la hora de usar en tus programas. 1 2 3 $&#40;document&#41;.ready&#40;function&#40;&#41;&#123; //todo el código &#125;&#41;; El código que ven más arriba se suele usar la mayoría del tiempo y en casi todos lados lo mencionan como la mejor manera de [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy les voy a explicar la principal diferencia entre <strong>$(document).ready</strong> y <strong>$(window).load </strong>, funciones esenciales a la hora de usar <a href="http://www.masquewordpress.com/category/jquery/">jQuery</a> en tus programas.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #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;">//todo el código</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>El código que ven más arriba se suele usar la mayoría del tiempo y en casi todos lados lo mencionan como la mejor manera de ejecutar nuestro código después del que el <a href="http://es.wikipedia.org/wiki/Document_Object_Model" rel="nofollow">DOM</a> esta listo.<br />
<span id="more-957"></span></p>
<h3>Entonces para que se necesita <strong>$(window).load() </strong>?</h3>
<p>Yo hasta ahora lo he utilizado para trabajar con imágenes. Cuando se necesita manipular imágenes para por ejemplo alinearlas o se necesita obtener el width y height de las mismas necesitaremos sí o sí utilizar <strong>$(window).load()</strong>.<br />
Con <strong>$(document).ready() </strong> no podrás hacer eso si el usuario no tiene cargadas las imágenes en la cache o en otras palabras tu código siempre fallaría con nuevos usuarios.</p>
<p>A diferencia de este último <strong>$(window).load()</strong> ejecutará el código una vez hayan cargado todas las imágenes. A simple vista no se observa diferencia ninguna en cuanto a tiempo, pero si alguna vez tuvieron que manipular imágenes cuando carga una página sabrán a que me refiero.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">load</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;">// Código ejecutado después de que se carguen la imágenes.</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Saludos!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.masquewordpress.com/diferencia-entre-document-ready-y-window-load-en-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convertir cadenas de texto en números en Javascript</title>
		<link>http://www.masquewordpress.com/convertir-cadenas-de-texto-en-numeros-en-javascript/</link>
		<comments>http://www.masquewordpress.com/convertir-cadenas-de-texto-en-numeros-en-javascript/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 13:24:12 +0000</pubDate>
		<dc:creator>Damian</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutoriales]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tutorial jquery]]></category>

		<guid isPermaLink="false">http://www.masquewordpress.com/?p=910</guid>
		<description><![CDATA[Sencillas funciones que no por ello son menos importantes para poder convertir strings en int o floats. Aunque estas funciones son de Javascript las pueden emplear con jQuery o cualquier otro framework para convertir sus cadenas de texto en números y así poder restar, sumar o realizar cualquier otra operación que necesiten. Convertir string a [...]]]></description>
			<content:encoded><![CDATA[<p>Sencillas funciones que no por ello son menos importantes para poder convertir <strong>strings</strong> en <strong>int</strong> o <strong>floats</strong>. Aunque estas funciones son de <strong>Javascript</strong> las pueden emplear con jQuery o cualquier otro framework para convertir sus cadenas de texto en números y así poder restar, sumar o realizar cualquier otra operación que necesiten.<br />
<span id="more-910"></span></p>
<p>Convertir string a entero</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> texto <span style="color: #339933;">=</span> <span style="color: #3366CC;">'1234'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// text + 10 = 123410</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> numero<span style="color: #339933;">;</span>
numero <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>texto<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span><span style="color: #CC0000;">10</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">//numero= 1244</span></pre></td></tr></table></div>

<p>String a decimal:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> texto <span style="color: #339933;">=</span> <span style="color: #3366CC;">'1234.0987'</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//texto + 10 = 1234.098710</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">var</span> entero <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// entero = 1234</span>
<span style="color: #003366; font-weight: bold;">var</span> decimal <span style="color: #339933;">=</span> parseFloat<span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// decimal = 1234.0987</span>
<span style="color: #006600; font-style: italic;">//decimal + 10 = 1244.098710</span></pre></td></tr></table></div>

<p>Reducir el número de decimales:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> numero <span style="color: #339933;">=</span> <span style="color: #CC0000;">1234.0987</span><span style="color: #339933;">;</span>
&nbsp;
numero <span style="color: #339933;">=</span> numero.<span style="color: #660066;">toFixed</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// numero = 1234.09</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.masquewordpress.com/convertir-cadenas-de-texto-en-numeros-en-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Contar o Limitar la cantidad de palabras con jQuery</title>
		<link>http://www.masquewordpress.com/contar-limitar-la-cantidad-de-palabras-con-jquery/</link>
		<comments>http://www.masquewordpress.com/contar-limitar-la-cantidad-de-palabras-con-jquery/#comments</comments>
		<pubDate>Thu, 13 Oct 2011 14:02:47 +0000</pubDate>
		<dc:creator>Damian</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutoriales]]></category>
		<category><![CDATA[tutorial jquery]]></category>

		<guid isPermaLink="false">http://masquewordpress.com/?p=846</guid>
		<description><![CDATA[Se acuerdan que el otro día creamos un plugin para limitar las letras de un textarea? Y que pasa si lo que necesitamos en limitar la cantidad de palabras? Aunque en principio no parezca de utilidad hay ocasiones donde necesitaremos hacerlo o simplemente necesitaremos contar la cantidad de palabras de un textarea para mostrarlo en [...]]]></description>
			<content:encoded><![CDATA[<p>Se acuerdan que el otro día <a href="http://masquewordpress.com/jquery/plugin-jquery-para-limitar-caracteres-en-un-campo-de-texto/">creamos un plugin para limitar las letras de un textarea?</a> Y que pasa si lo que necesitamos en limitar la cantidad de palabras? Aunque en principio no parezca de utilidad hay ocasiones donde necesitaremos hacerlo o simplemente necesitaremos <strong>contar la cantidad de palabras de un textarea</strong> para mostrarlo en un mensaje.</p>
<p><span id="more-846"></span></p>
<h3>Contar la cantidad de palabras de un textarea</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#textarea_id'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keyup</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> palabras <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\b[\s,\.\-:;]*/</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">lenght</span><span style="color: #339933;">;</span>
     $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#contador'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'Has escrito en total '</span><span style="color: #339933;">+</span> palabras <span style="color: #339933;">+</span><span style="color: #3366CC;">' palabras'</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>

<p>Lo que hacemos en cada vez que se levanta una tecla(<strong>keyup</strong>) comprobamos el valor del textarea y lo dividimos(<strong>split</strong>) en palabras mediante la regla de regex que prácticamente se encarga de separar las palabras por espacios, guiones ,etc. Una vez que tenemos todas las palabras con <strong>lenght</strong> obtenemos la cantidad.<br />
Por último modificamos el campo contador con la cantidad de palabras de nuestro textarea.</p>
<h3>Limitar la cantidad de palabras de un textarea</h3>
<p>Para esto vamos a crear una nueva función</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> limitar_palabras<span style="color: #009900;">&#40;</span>texto<span style="color: #339933;">,</span> limite<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
<span style="color: #003366; font-weight: bold;">var</span> palabras <span style="color: #339933;">=</span> texto.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\b[\s,\.\-:;]*/</span><span style="color: #339933;">,</span>limite<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
texto<span style="color: #339933;">=</span>palabras.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">return</span> texto<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>En esta función añadimos la <strong>variable limite</strong> al <strong>.split</strong> y luego unimos el resultado con espacios usando <strong>.join</strong>.</p>
<p>Por lo que el código todo junto quedaría de la siguiente forma:</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:monospace;">$<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: #009900;">&#40;</span><span style="color: #3366CC;">'#textarea_id'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keyup</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span>limitar_palabras<span style="color: #009900;">&#40;</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: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003366; font-weight: bold;">function</span> limitar_palabras<span style="color: #009900;">&#40;</span>texto<span style="color: #339933;">,</span> limite<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> palabras <span style="color: #339933;">=</span> texto.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\b[\s,\.\-:;]*/</span><span style="color: #339933;">,</span>limite<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    texto<span style="color: #339933;">=</span>palabras.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">return</span> texto<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Facil y sencillo verdad? Porque no prueban a crear su<a href="http://masquewordpress.com/category/jquery/"> propio plugin de jQuery</a> con estos sencillos pasos? Saludos!!</p>
<p>&nbsp;</p>
<p>Actualizado<div class="iconbox"><span class="iconbox_icon"><img src='http://www.masquewordpress.com/wp-content/themes/brightbox/images/icons/iconbox/info.png' alt='' /></span><div class="iconbox_content"><h3 class="iconbox_content_title">Actualización</h3><p>He cambiado el regex para que también detecte números como palabras . Ahora &#8220;-&#8221; esta &#8220;\-&#8221;. </p>
</div></div></p>
]]></content:encoded>
			<wfw:commentRss>http://www.masquewordpress.com/contar-limitar-la-cantidad-de-palabras-con-jquery/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Plugin jQuery para limitar caracteres en un campo de texto</title>
		<link>http://www.masquewordpress.com/plugin-jquery-para-limitar-caracteres-en-un-campo-de-texto/</link>
		<comments>http://www.masquewordpress.com/plugin-jquery-para-limitar-caracteres-en-un-campo-de-texto/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 15:36:02 +0000</pubDate>
		<dc:creator>Damian</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[Tutoriales]]></category>
		<category><![CDATA[jquery.plugin]]></category>
		<category><![CDATA[tutorial jquery]]></category>

		<guid isPermaLink="false">http://masquewordpress.com/?p=811</guid>
		<description><![CDATA[[offtopic] Antes de empezar este artículo quiero dar mis condolencias a la Familia Jobs. Para mi Steve Jobs siempre fue un grande , incluso antes de enamorarme de sus productos y SO. Siempre recomiendo ver un discurso dado por el para los alumnos de Standford Bridge. Lo pueden encontrar en http://www.youtube.com/watch?feature=player_embedded&#38;v=14v3kV47oZU [/offtopic] Hoy les voy [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>[offtopic] Antes de empezar este artículo quiero dar mis condolencias a la Familia Jobs. Para mi Steve Jobs siempre fue un grande , incluso antes de enamorarme de sus productos y SO. Siempre recomiendo ver un discurso dado por el para los alumnos de Standford Bridge. Lo pueden encontrar en http://www.youtube.com/watch?feature=player_embedded&amp;v=14v3kV47oZU [/offtopic]</p></blockquote>
<p>Hoy les voy a enseñar 2 cosas. <strong>Como limitar los caracteres de un campo de texto ya sea un textarea o un input</strong> y <strong>como crear un plugin de Jquery</strong>.<br />
<span id="more-811"></span><br />
Lo primero que necesitamos en un nuevo formulario dentro de una <strong>página HTML</strong> y le vamos a agregar un <strong>etiqueta span</strong> que será donde mostremos los caracteres que nos quedan con <strong>id=&#8221;counter&#8221;</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
15
16
17
18
19
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;!DOCTYPE  HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;  &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
&lt;html&gt;
&lt;head&gt;
   &lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/jsapi&quot;&gt;&lt;/script&gt;
    &lt;script src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
    &lt;script  type=&quot;text/javascript&quot;&gt;
        $(document).ready(function() {
        //Nuestras funciones jQuery
        });
    &lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form  id=&quot;formulario&quot;  method=&quot;POST&quot; action=&quot;?&quot;&gt;
    &lt;textarea  id=&quot;text&quot;&gt;&lt;/textarea&gt;
    &lt;span  id=&quot;counter&quot;&gt;&lt;/span&gt;
    &lt;input type=&quot;submit&quot;  value=&quot;submit&quot;&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>Ahora escribamos nuestra función para mostrar cuantos caracteres nos quedan.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> caracteres<span style="color: #339933;">=</span> <span style="color: #CC0000;">100</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#counter&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Te quedan &lt;strong&gt;&quot;</span><span style="color: #339933;">+</span> caracteres<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/strong&gt; caracteres&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Creamos una función que en el evento keyup que compruebe que la cantidad de caracteres escritos no es mayor que el limite que establecimos anteriormente. En caso contrario borra el valor de campo que excede dicho limite:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#text&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keyup</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> caracteres<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</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: #660066;">val</span><span style="color: #009900;">&#40;</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: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> caracteres<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Explicando un poco esta función vemos que cada vez que se levanta el dedo de un tecla <strong>obtenemos el length(cantidad)</strong> de caracteres del <strong>valor(val)</strong> de nuestro campo de texto y lo comparamos con la cantidad estipulada anteriormente.<br />
Si es mayor el valor del campo es sustituido por el valor actual menos el limite estipulado. Es decir, con la <strong>función substr</strong> recortamos la cadena de texto desde el caracter 0 hasta 100 y el resultado sustituye el valor del campo de texto.</p>
<p>Ahora cambiemos la frase de nuestro counter.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span>  quedan <span style="color: #339933;">=</span> caracteres <span style="color: #339933;">-</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#counter&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Te quedan &lt;strong&gt;&quot;</span><span style="color: #339933;">+</span> quedan<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/strong&gt; caracteres.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Aquí solamente restamos el limite establecido menos la cantidad de caracteres de nuestro campo.</p>
<p>Y si queremos agregarle un toque de color podemos hacer lo siguiente:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>quedan <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#counter&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;color&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;red&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">else</span>
<span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#counter&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;color&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;black&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Si nos quedan menos de diez caracteres , nuestro mensaje se volvera rojo!</p>
<p>El script entero entonces queda de la siguiente forma:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> caracteres <span style="color: #339933;">=</span> <span style="color: #CC0000;">220</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#counter&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Te quedan &lt;strong&gt;&quot;</span><span style="color: #339933;">+</span>  caracteres<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/strong&gt; caracteres.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#text&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keyup</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> caracteres<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</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: #660066;">val</span><span style="color: #009900;">&#40;</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: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> caracteres<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #003366; font-weight: bold;">var</span> quedan <span style="color: #339933;">=</span> caracteres <span style="color: #339933;">-</span>  $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#counter&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Te quedan &lt;strong&gt;&quot;</span><span style="color: #339933;">+</span>  quedan<span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/strong&gt; caracteres.&quot;</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>quedan <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#counter&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;color&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;red&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#counter&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;color&quot;</span><span style="color: #339933;">,</span><span style="color: #3366CC;">&quot;black&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#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>

<p><strong>Pueden ver el ejemplo funcionando en <a href="http://jsfiddle.net/sa4HH/">http://jsfiddle.net/sa4HH/</a></strong></p>
<h3>Crear un Plugin jQuery para delimitar los campos de texto</h3>
<p>Por lo general vamos a necesitar este código en más de una ocasión y para varios campos de texto, por lo que repetir todo una y otra vez no es aceptable. En este caso nos conviene crear un simple plugin de jQuery que será facil de aplicar.<br />
Para ello siguiendo la lógica de jQuery vamos a crear la base de nuestro plugin que lo vamos a llamar <strong>&#8220;limitar&#8221;</strong>:<br />
¡</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">limitar</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        limite<span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span>
        id_counter<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
        clase_alert<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
     <span style="color: #009900;">&#125;</span>
   <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>defaults<span style="color: #339933;">,</span>  options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Al declarar nuestro <strong>plugin limitar</strong> hemos creado unos valores por defecto que paso a explicar.</p>
<ul>
<li><strong>limite</strong>: Es el límite por defecto. En este caso <strong>200</strong> caracteres.</li>
<li><strong>id_counter</strong>: Es el id del campo donde mostraremos el mensaje de caracteres faltantes. Por defecto es <strong>false</strong>, por lo que no mostraríamos ningún mensaje.</li>
<li><strong>clase_alert</strong>: En lugar de cambiar el color si los caracteres son menos que diez vamos a asignarle un clase para así dar más libertad a la hora de aplicar estilo a este mensaje de alerta. Por defecto no se asigna ninguna clase ya que es <strong>false</strong>.</li>
</ul>
<p>Ahora debemos terminar la función de nuestro plugin:</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:monospace;"><span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> caracteres <span style="color: #339933;">=</span> options.<span style="color: #660066;">limite</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">id_counter</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">+</span>options.<span style="color: #660066;">id_counter</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Te quedan &lt;strong&gt;&quot;</span><span style="color: #339933;">+</span> caracteres <span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/strong&gt; caracteres.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</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: #660066;">keyup</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> caracteres<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</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: #660066;">val</span><span style="color: #009900;">&#40;</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: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> caracteres<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">id_counter</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> quedan <span style="color: #339933;">=</span>  caracteres <span style="color: #339933;">-</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">+</span>options.<span style="color: #660066;">id_counter</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Te quedan &lt;strong&gt;&quot;</span><span style="color: #339933;">+</span> quedan <span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/strong&gt; caracteres&quot;</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>quedan <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">+</span>options.<span style="color: #660066;">id_counter</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">clase_alert</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span>
            <span style="color: #009900;">&#123;</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">+</span>options.<span style="color: #660066;">id_counter</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">clase_alert</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><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>

<p>Estamos replicando nuestra función del principio con la única diferencia que usamos los valores dentro del array <strong>options</strong> para dar más flexibilidad al código y miren que sin por ejemplo <strong>options.id_counter es false</strong> nunca mostraremos el mensaje.</p>
<p>El plugin entero que debemos guardar como jquery.limitar.js quedaría de la siguiente forma:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    $.<span style="color: #660066;">fn</span>.<span style="color: #660066;">limitar</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>options<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      defaults <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
        limite<span style="color: #339933;">:</span> <span style="color: #CC0000;">200</span><span style="color: #339933;">,</span>
        id_counter<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
        clase_alert<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span>
     <span style="color: #009900;">&#125;</span>
   <span style="color: #003366; font-weight: bold;">var</span> options <span style="color: #339933;">=</span> $.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>defaults<span style="color: #339933;">,</span>  options<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> caracteres <span style="color: #339933;">=</span> options.<span style="color: #660066;">limite</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">id_counter</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">+</span>options.<span style="color: #660066;">id_counter</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Te quedan &lt;strong&gt;&quot;</span><span style="color: #339933;">+</span> caracteres <span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/strong&gt; caracteres.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</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: #660066;">keyup</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span> <span style="color: #339933;">&gt;</span> caracteres<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</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: #660066;">val</span><span style="color: #009900;">&#40;</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: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> caracteres<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">id_counter</span> <span style="color: #339933;">!=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #003366; font-weight: bold;">var</span> quedan <span style="color: #339933;">=</span>  caracteres <span style="color: #339933;">-</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">+</span>options.<span style="color: #660066;">id_counter</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Te quedan &lt;strong&gt;&quot;</span><span style="color: #339933;">+</span> quedan <span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;&lt;/strong&gt; caracteres&quot;</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>quedan <span style="color: #339933;">&lt;=</span> <span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">+</span>options.<span style="color: #660066;">id_counter</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">clase_alert</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066; font-weight: bold;">else</span>
            <span style="color: #009900;">&#123;</span>
                $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#&quot;</span><span style="color: #339933;">+</span>options.<span style="color: #660066;">id_counter</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span>options.<span style="color: #660066;">clase_alert</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><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Para usarlo tan solo debemos llamarlo de la siguiente manera (no se olviden de crear la clase para dar estilo al mensaje de alerta):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;script  type=&quot;text/javascript&quot; src=&quot;jquery.limit.js&quot;&gt;&lt;/script&gt;
&lt;style&gt;
.alert{
    color: red;
    font-weight:bold;
}
&lt;/style&gt;
&lt;script  type=&quot;text/javascript&quot;&gt;
    $(document).ready(function() {
        $(&quot;#testo&quot;).limitar({
            limite: 100,
            id_counter: &quot;counter&quot;,
            clase_alert: &quot;alert&quot;
            });
         });
&lt;/script&gt;</pre></td></tr></table></div>

<p>Pueden ver el ejemplo funcionando en <a href="http://jsfiddle.net/V7Gs6/1/">http://jsfiddle.net/V7Gs6/1/</a></p>
<p>Saludos!!!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.masquewordpress.com/plugin-jquery-para-limitar-caracteres-en-un-campo-de-texto/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Como crear una aplicación de Twitter con PHP</title>
		<link>http://www.masquewordpress.com/como-crear-una-aplicacion-de-twitter-con-php/</link>
		<comments>http://www.masquewordpress.com/como-crear-una-aplicacion-de-twitter-con-php/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 02:28:35 +0000</pubDate>
		<dc:creator>Damian</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutoriales]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorial jquery]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://masquewordpress.com/?p=694</guid>
		<description><![CDATA[Hace unos días les hable de como integrar Twitter anywhere en 5 minutos y luego les mostré un poco acerca de la nueva api javascript de @anywhere, incluso hace tiempo les explique como actualizar twitter a través de PHP + Oauth. En este último articulo utilizaba una librería de PHP llamada twitteroauth.php que hoy voy [...]]]></description>
			<content:encoded><![CDATA[<p>Hace unos días les hable de <a href="http://masquewordpress.com/tutoriales/como-integrar-twitter-anywhere-en-5-minutos/">como integrar Twitter anywhere en 5 minutos</a> y luego les mostré un poco acerca de la <a href="http://masquewordpress.com/tutoriales/anywhere-javascript-api-jugando-un-poco/">nueva api javascript de @anywhere</a>, incluso hace tiempo les explique como <a href="http://masquewordpress.com/tutoriales/actualizar-twitter-a-traves-de-php-y-oauth/">actualizar twitter a través de PHP + Oauth</a>.</p>
<p>En este último articulo utilizaba una librería de PHP llamada <a href="http://github.com/abraham/twitteroauth">twitteroauth.php</a> que hoy voy a explicar un poco más , y les va a permitir junto con un poquito de <a href="http://masquewordpress.com/tag/jquery/">JQuery</a> crear una <a href="http://masquewordpress.com/ejemplos/aplicacion-twitter-php/">aplicación completa de twitter en PHP</a> siempre que lo requieran.</p>
<p><span id="more-694"></span></p>
<div id="ejemplo">
<div class="wrap-ej"><a class="descarga" href="http://masquewordpress.com/ejemplos/aplicacion-twitter-php.zip"></a><a class="demo" href="http://masquewordpress.com/ejemplos/aplicacion-twitter-php/"></a></div>
</div>
<h3>1. Estructura HTML de la aplicación</h3>
<p> Nuestra aplicación consta de un<strong> boton para hacer login a Twitter</strong> que solo aparece la primera vez que ingresamos.<br />
Una vez echo login nos mostrará un <strong>formulario de texto</strong> donde escribiremos los tweets junto a <strong>un boton</strong> para enviar, <strong><a href="http://masquewordpress.com/jquery/tabs-en-jquery-y-reconocimiento-de-hashtags/">tres pestañas en JQuery</a></strong> para cambiar del Timeline a los @Mentions y a los Mensajes directos.<br />
Y por último el <strong>timeline</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
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;twitter-feed&quot;</span>&gt;</span>
                 <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;letras&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tweet_post&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;width: 400px; margin: 0pt auto;clear:right;&quot;</span>&gt;</span>
                	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">textarea</span> <span style="color: #000066;">rows</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span> <span style="color: #000066;">cols</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;49&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tweet_txt&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tweet_txt&quot;</span> <span style="color: #000066;">onKeyUp</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;contar(this);&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">textarea</span>&gt;</span>
						<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;hidden&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;reply_id&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;t_reply&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
                	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">button</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tweet_submit&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tweet_button&quot;</span>&gt;</span>Submit<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">button</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span>
&nbsp;
               <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;t_tab&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;t_selected&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#t_timeline&quot;</span>&gt;</span>Timeline<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#t_mentions&quot;</span>&gt;</span>@Mentions<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#t_messages&quot;</span>&gt;</span>Messages<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
&nbsp;
               <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;t_timeline&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tab_content&quot;</span>&gt;</span>
               <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
                   <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;foto&quot;</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span> 
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span>Nombre de usuario Twitter<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span><span style="color: #66cc66;">/</span>&gt;</span>Texto del tweet<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">br</span><span style="color: #66cc66;">/</span>&gt;</span>
                        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text-align:right&quot;</span>&gt;</span>
				 <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&quot;</span> <span style="color: #000066;">onClick</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:&quot;</span>&gt;</span>Reply<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		 <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
           <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
          <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clear: both;&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>Una vez realizada la estructura de nuestra aplicación vamos a llenarla con PHP y todos los valores necesarios</p>
<h3>2. Estructura de archivos &#8211; Como funciona la aplicación</h3>
<p>La aplicación funciona de la siguiente manera :<br />
El usuario ingresa a <strong>index.php</strong> y hace click en conectar que lo lleva a <strong>redirect.php</strong> (aunque no se percata de ello) que es donde se obtiene las credenciales temporales, de aquí va a la página de Twitter donde se loguea con sus datos.<br />
Una vez logueado es redirigido a <strong>callback.php</strong>( no se percata de ello) donde se verifica que las credenciales sean correctas y se envia de vuelta a la página principal.<br />
En caso de que algo falle tanto en redirect.php o callback.php el usuario es enviado a <strong>clearsessions.php</strong>( no se percata de ello) que es donde se borran todas las sesiones y se envia el usuario a la página principal para que empieze el proceso nuevamente.<br />
Como pueden ver para ojos del usuario será tan simple como boton de loguin , ingresar datos de su cuenta en twitter.com y vuelta a la aplicación ya funcionando.</p>
<p>Veamos todos los archivos involucrados</p>
<ul>
<li><strong>index.php</strong>: Será la página principal donde enlazaremos nuestra hoja de estilos css, Jquery y donde se verá la estructura principal.</li>
<li><strong>twitter_init.php</strong> : Aca vamos a inicializar la librería de twitter y almacenar todo en la variable <strong>$twitter_content</strong>.</li>
<li><strong>callback.php</strong>: Archivo que recibe al usuario desde twitter </li>
<li><strong>redirect.php</strong>: Archivo que enviar al usuario a twitter</li>
<li><strong>clearsessions.php</strong>: Archivo que borra las sesiones en caso de error</li>
<li><strong>twitteroauth/config.php</strong>: Archivo de configuración con los datos de nuestro programa</li>
<li><strong>twitteroauth/twitteroauth.php</strong>: Librería twitteroauth</li>
<li><strong>twitteroauth/OAuth.php</strong>: Librería OAuth</li>
</ul>
<h3>3. La aplicación y los tres archivos importantes </h3>
<p>Para nosotros los únicos archivos importante seran index.php , twitter_init.php y config.php. Los demás voy a obviarlos para no complicarlos, simplemente porque son archivos que no van a cambiar nunca, igualmente esta comentados paso por paso en el código. </p>
<p><strong>index.php</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
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;? session_start<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;?&gt;</span>
<span style="color: #00bbdd;">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">html</span> xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.w3.org/1999/xhtml&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">http-equiv</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Content-Type&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/html; charset=utf-8&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
   <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">title</span>&gt;</span>Como Crear una aplicación de  Twitter con PHP + OAuth<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">title</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;estilo.css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span><span style="color: #66cc66;">/</span>&gt;</span> 
   <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
   <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span>
   $(document).ready(function(){
&nbsp;
	    $(&quot;ul.t_tab li&quot;).click(function()     //cada vez que se hace click en un li
       {
		$(&quot;ul.t_tab li&quot;).removeClass(&quot;t_selected&quot;); //removemos clase active de todos
		$(this).addClass(&quot;t_selected&quot;); //añadimos a la actual la clase active
		$(&quot;.tab_content&quot;).hide(); //escondemos todo el contenido
&nbsp;
		var content = $(this).attr(&quot;id&quot;); //obtenemos el atributo id
		$(content).fadeIn(); // mostramos el contenido
		return false; //devolvemos false para el evento click
	});
&nbsp;
});
&nbsp;
function replyTo(id,name){
			$('#t_reply').val(id);
			$('#tweet_txt').val(&quot;@&quot;+name+&quot; &quot;).focus();
&nbsp;
			return false;
}
function contar(input) {
//Comprobamos que no pase de 140 caracteres y si pasa, que borre los sobrantes
if (input.value.length &gt;= 140) {
input.value = input.value.substring(0,140);
}
//alamacenamos el resto
var resto = 140 - input.value.length;
&nbsp;
//imprimimos los caracteres restantes en el span
$('#letras').html(resto);
&nbsp;
}
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span> 
<span style="color: #009900;">&lt;?</span>
<span style="color: #009900;">include_once<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">'twitter_init.php'</span><span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #009900;">?&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;header&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>Como crear una aplicaci<span style="color: #ddbb00;">&amp;oacute;</span>n de Twitter con PHP. M<span style="color: #ddbb00;">&amp;aacute;</span>s tutoriales en <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://masquewordpress.com&quot;</span>&gt;</span>http://masquewordpress.com<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;twitter-feed&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;? echo $twitter_content;?&gt;</span>
&nbsp;
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;clear: both;&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">html</span>&gt;</span></pre></td></tr></table></div>

<p>Como pueden ver es muy sencillo, igualmente vamos a explicar un poco que es lo que vemos:</p>
<ul>
<li> Primero iniciamos con session_start() , esto lo usaremos para almacenar los tokens de Twitter en vez de usar los mismos siempre como hacíamos en mi tutorial de <a href="http://masquewordpress.com/tutoriales/actualizar-twitter-a-traves-de-php-y-oauth/">Actualizar twitter con PHP + Oauth</a>, ya que ahora no serán nuestros tokens, sino que serán los de los diferentes usuarios que quieran usar nuestro programa</li>
<li>Enlazamos nuestra hoja de estilo CSS</li>
<li>Enlazamos a la última versión de JQuery</li>
<li>Creamos la<a href="http://masquewordpress.com/jquery/tabs-en-jquery-y-reconocimiento-de-hashtags/"> función JQuery para las pestañas</a></li>
<li>Función que se encarga de escoger el atributo id en caso de que respondamos algún tweet y añade su @nombre al formulario</li>
<li>Función que cuenta los caracteres restantes de nuestro tweet</li>
<li>Incluimos twitter_init.php</li>
<li>Y por último imprimos el resultado con <? echo $twitter_content;?></li>
</ul>
<p><strong><br />
twitter_init.php</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
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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitteroauth/twitteroauth.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'twitteroauth/config.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<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;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'oauth_token'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'oauth_token_secret'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
   <span style="color: #000088;">$twitter_content</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'&lt;div class=&quot;tweet_login&quot;&gt;&lt;a href=&quot;redirect.php&quot;&gt;&lt;img src=&quot;twitteroauth/images/lighter.png&quot; alt=&quot;Sign in with Twitter&quot;/&gt;&lt;/a&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
				<span style="color: #666666; font-style: italic;">/* Recuperar los datos de la session. */</span>
				<span style="color: #000088;">$access_token</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'access_token'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">/* Creamos el objeto twitterOauth. */</span>
				<span style="color: #000088;">$connection</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> TwitterOAuth<span style="color: #009900;">&#40;</span>CONSUMER_KEY<span style="color: #339933;">,</span> CONSUMER_SECRET<span style="color: #339933;">,</span> <span style="color: #000088;">$access_token</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'oauth_token'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$access_token</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'oauth_token_secret'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">/* Verificamos credenciales. */</span>
				<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'account/verify_credentials'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
				<span style="color: #666666; font-style: italic;">/* Formulario */</span>
				<span style="color: #000088;">$twitter_content</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'&lt;span id=&quot;letras&quot;&gt;&lt;/span&gt;
                &lt;form name=&quot;tweet_post&quot; method=&quot;post&quot; style=&quot;width: 400px; margin: 0pt auto;clear:right;&quot;&gt;
                	&lt;textarea rows=&quot;4&quot; cols=&quot;49&quot; name=&quot;tweet_txt&quot; id=&quot;tweet_txt&quot; onKeyUp=&quot;contar(this);&quot;&gt;&lt;/textarea&gt;
						&lt;input type=&quot;hidden&quot; name=&quot;reply_id&quot; id=&quot;t_reply&quot;/&gt;
                	&lt;button id=&quot;tweet_submit&quot; class=&quot;tweet_button&quot;&gt;Submit&lt;/button&gt;
                &lt;/form&gt;
				'</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">/* Si hay un mensaje nuevo lo publicamos */</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tweet_txt'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
						<span style="color: #666666; font-style: italic;">/* En caso de ser respuesta, publicarlo como tal */</span>
						<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'reply_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">!=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
							<span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'statuses/update'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tweet_txt'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'in_reply_to_status_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'reply_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
							<span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'statuses/update'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'status'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'tweet_txt'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
&nbsp;
				<span style="color: #009900;">&#125;</span>
				<span style="color: #666666; font-style: italic;">/*Función que añade los links */</span>
				<span style="color: #000000; font-weight: bold;">function</span> twitify<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$t</span><span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(http|https)(:\/\/)([^ ]+)/i'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;a href=&quot;$1$2$3&quot;&gt;$1$2$3&lt;/a&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
					<span style="color: #000088;">$t</span><span style="color: #339933;">=</span>  <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/@([^ :]+)/i'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;a href=&quot;http://twitter.com/$1&quot;&gt;@$1&lt;/a&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$t</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$t</span><span style="color: #339933;">=</span>  <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/#([^ :]+)/i'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;a href=&quot;http://search.twitter.com/search?q=%23$1&quot;&gt;#$1&lt;/a&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$t</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">return</span> <span style="color: #000088;">$t</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				 <span style="color: #666666; font-style: italic;">/* Pestañas */</span>
				 <span style="color: #000088;">$twitter_content</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">'&lt;ul class=&quot;t_tab&quot;&gt;
				 						&lt;li class=&quot;t_selected&quot; id=&quot;#t_timeline&quot;&gt;Timeline&lt;/li&gt;
										&lt;li id=&quot;#t_mentions&quot;&gt;@Mentions&lt;/li&gt;
										&lt;li id=&quot;#t_messages&quot;&gt;Messages&lt;/li&gt;
									&lt;/ul&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
				<span style="color: #666666; font-style: italic;">/* Obtenemos el timeline */</span>
				<span style="color: #000088;">$t</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'statuses/home_timeline'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'count'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">40</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>					
				<span style="color: #000088;">$twitter_content</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">'&lt;div id=&quot;t_timeline&quot; class=&quot;tab_content&quot;&gt;&lt;ul&gt;'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
					<span style="color: #000088;">$twitter_content</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">'&lt;li&gt;
						&lt;div class=&quot;foto&quot;&gt;
							&lt;img src=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">profile_image_url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; alt=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; width=&quot;48px&quot; /&gt; 
						&lt;/div&gt;
						&lt;a href=&quot;http://twitter.com/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">screen_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;
						&lt;br/&gt;'</span><span style="color: #339933;">.</span>twitify<span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br/&gt;
						&lt;div style=&quot;text-align:right&quot;&gt;
							&lt;a href=&quot;#&quot; onClick=&quot;javascript: replyTo(\''</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\',\''</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">screen_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\');&quot;&gt;Reply&lt;/a&gt;
						&lt;/div&gt;
&nbsp;
						&lt;/li&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000088;">$twitter_content</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">'&lt;/ul&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">/* Obtenemos las menciones */</span>
				<span style="color: #000088;">$t</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'statuses/mentions'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'count'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
				<span style="color: #000088;">$twitter_content</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">'&lt;div id=&quot;t_mentions&quot; class=&quot;tab_content&quot; style=&quot;display:none;&quot;&gt;&lt;ul&gt;'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
					<span style="color: #000088;">$twitter_content</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">'&lt;li&gt;
					&lt;div class=&quot;foto&quot;&gt;
						&lt;img src=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">profile_image_url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; alt=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; width=&quot;48px&quot; /&gt;
					&lt;/div&gt; 
					&lt;a href=&quot;http://twitter.com/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">screen_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;
					&lt;br/&gt;'</span><span style="color: #339933;">.</span>twitify<span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br/&gt;
					&lt;div style=&quot;text-align:right&quot;&gt;
						&lt;a href=&quot;#&quot; onClick=&quot;javascript: replyTo(\''</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\',\''</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">screen_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\');&quot;&gt;Reply&lt;/a&gt;
					&lt;/div&gt;
					&lt;/li&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000088;">$twitter_content</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">'&lt;/ul&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>	
&nbsp;
				<span style="color: #666666; font-style: italic;">/* Mensajes directos */</span>	
				<span style="color: #000088;">$t</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$connection</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'direct_messages'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'count'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">20</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
				<span style="color: #000088;">$twitter_content</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">'&lt;div id=&quot;t_messages&quot; class=&quot;tab_content&quot; style=&quot;display:none;&quot;&gt;&lt;ul&gt;'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$t</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$val</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
					<span style="color: #000088;">$twitter_content</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">'&lt;li&gt;
					&lt;div class=&quot;foto&quot;&gt;
						&lt;img src=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sender</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">profile_image_url</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; alt=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sender</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; width=&quot;48px&quot; /&gt;
					&lt;/div&gt; 
					&lt;a href=&quot;http://twitter.com/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sender</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">screen_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; title=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sender</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sender</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/a&gt;
					&lt;br/&gt;'</span><span style="color: #339933;">.</span>twitify<span style="color: #009900;">&#40;</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;br/&gt;
					&lt;div style=&quot;text-align:right&quot;&gt;
						&lt;a href=&quot;#&quot; onClick=&quot;javascript: replyTo(\''</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\',\''</span><span style="color: #339933;">.</span><span style="color: #000088;">$val</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sender</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">screen_name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'\');&quot;&gt;Reply&lt;/a&gt;
					&lt;/div&gt;
					&lt;/li&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000088;">$twitter_content</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">'&lt;/ul&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>	
&nbsp;
&nbsp;
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Expliquemos un poco que es lo que vemos:</p>
<ul>
<li>Incluyo las dos librerías necesarias para que todo funcione</li>
<li> Compruebo si esta el usuario loguedo y muestro boton en caso negativo ( siempre almaceno todo en $twitter_content)</li>
<li>En caso de estar logueado recupero los datos de la sesion.</li>
<li>Creo el objeto twitterOauth</li>
<li>Verifico las credenciales</li>
<li>Creo el formulario</li>
<li>Compruebo si se ha enviado un mensaje y si es en respuesta de algún otro. En caso afirmativo lo posteo en twitter</li>
<li>La siguiente función es muy interesante ya que se encarga de añadir los links a los @usuarios ,#tags y url ya que cuando recuperamos un timeline de twitter este lo envía en texto plano ( sin código HTML como &lt;a href&gt;)</li>
<li>Añado las pestañas para moverme por los diferentes timelines</li>
<li>Y por último obtengo los tres timeline ( Timeline, menciones y mensajes directos)</li>
</ul>
<p><strong><br />
config.php</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CONSUMER_KEY'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Tu consumer key'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'CONSUMER_SECRET'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' Tu consumer secret'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'OAUTH_CALLBACK'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Tu dirección donde tienes el archivo callback.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Como ven este archivo no tiene complicación alguna y se trata simplemente de configurar unos valores predeterminados. Para obtener el CONSUMER_KEY pueden leer mi tutorial de <a href="http://masquewordpress.com/tutoriales/actualizar-twitter-a-traves-de-php-y-oauth/">Twitter + PHP + OAuth</a></p>
<p>Y con todo lo visto anteriormente más un poco de CSS podemos crear una <a href="http://masquewordpress.com/ejemplos/aplicacion-twitter-php/">aplicación para Twitter echa en PHP</a></p>
<p>Les recomiendo ampliamente echar un vistazo a todos los archivos para entender mejor su funcionamiento. Un saludo y espero que les haya gustado.</p>
<div id="ejemplo">
<div class="wrap-ej"><a class="descarga" href="http://masquewordpress.com/ejemplos/aplicacion-twitter-php.zip"></a><a class="demo" href="http://masquewordpress.com/ejemplos/aplicacion-twitter-php/"></a></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.masquewordpress.com/como-crear-una-aplicacion-de-twitter-con-php/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Como redondear las esquinas de un DIV con jquery.corners</title>
		<link>http://www.masquewordpress.com/como-redondear-las-esquinas-de-un-div-con-jquery-corners/</link>
		<comments>http://www.masquewordpress.com/como-redondear-las-esquinas-de-un-div-con-jquery-corners/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 21:40:12 +0000</pubDate>
		<dc:creator>Damian</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Tutoriales]]></category>
		<category><![CDATA[jquery.plugin]]></category>
		<category><![CDATA[tutorial jquery]]></category>

		<guid isPermaLink="false">http://masquewordpress.com/?p=177</guid>
		<description><![CDATA[Si hay algo que me gusta usar en mis proyectos son cuadros con esquinas redondeadas. Siempre queda bien y le da un aire moderno a la web. Es muy facil de hacer y tiene un monton de utilidades como por ejemplo para marcos de fotos, redondear tablas, botones o simplemente divs redondos. Hay infinidad de [...]]]></description>
			<content:encoded><![CDATA[<p>Si hay algo que me gusta usar en mis proyectos son cuadros con esquinas redondeadas. Siempre queda bien y le da un aire moderno a la web. Es muy facil de hacer  y tiene un monton de utilidades como por ejemplo para marcos de fotos, redondear tablas, botones o simplemente divs redondos.</p>
<p align="center"><img src="http://masquewordpress.com/wp-content/uploads/2009/07/rounded.jpg" alt="rounded" title="rounded" width="458" height="450" class="aligncenter size-full wp-image-179" /></p>
<p>Hay <a title="240 plugins para jquery" href="http://masquewordpress.com/recursos/240-plugins-para-jquery-lo-mejor-de-lo-mejor/">infinidad de plugins</a> que cumplen esta función pero a mi el que más me gusta es <a href="http://www.atblabs.com/jquery.corners.html" target="_blank">JQuery Corners.</a> </p>
<p>Para utilizarlo como siempre debemos utilizar la ultima version de <a href="http://jquery.com/" target="_blank">JQuery</a> y del <a href="http://plugins.jquery.com/project/corners" target="_blank">plugin</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/jquery-latest.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;js/jquery.corners.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span></pre></td></tr></table></div>

<p>Con esto tendriamos el plugin cargado. En este ejemplo voy a hacer que tanto el div como la foto tengan tengan la clase &#8220;rounded&#8221; por lo que para aplicar el plugin hago lo siguiente:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
$<span style="color: #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;">//espero que cargue el DOM y aplico el plugin a todos los elemento con clase rounded</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.rounded'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">corners</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Tan solo nos quedaria añadir el código HTML :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrapper&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cuadro1&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rounded&quot;</span>&gt;</span> Div con gif degradado de fondo <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cuadro2&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rounded&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/gatito.jpg&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>  Marco para foto redondo 
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>

<p>Y aplicarle un estilo:</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="css" style="font-family:monospace;">&lt;style<span style="color: #00AA00;">&gt;</span>
body <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#666666</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">font-family</span><span style="color: #00AA00;">:</span><span style="color: #ff0000;">'Trebuchet MS'</span><span style="color: #00AA00;">,</span><span style="color: #993333;">sans-serif</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</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;">1.5em</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;">justify</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#cuadro1</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#D7E9F3</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>images/intro2.gif<span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span> <span style="color: #993333;">scroll</span> <span style="color: #000000; font-weight: bold;">left</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">30px</span> <span style="color: #933;">80px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#cuadro2</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#EEEEEE</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#CCCCCC</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#wrapper</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;">370px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&lt;/style<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p>Otra cosa a tener en cuenta es que podemos pasarle opciones como por ejemplo un radio de 8px y que sea transparente (en caso de tener imagenes o hover states):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.rounded'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">corners</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;8px transparent&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Pueden ver el ejemplo terminado en <a href="http://masquewordpress.com/ejemplos/como-redondear-esquinas/">esta página</a>.</p>
<p><a href="http://masquewordpress.com/ejemplos/como-redondear-esquinas.zip">Descargar Ejemplo</a></p>
<p><font color="red">ACTUALIZACIÓN</font><br />
Como menciona Jereny en IE no redondea las imágenes. Si quieren hacer un marco para la imagen redondeado lo pueden hacer de la siguiente forma:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;cuadro2&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;rounded&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">img</span>  <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/gatito.jpg&quot;</span><span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>  Marco para foto redondo</pre></td></tr></table></div>

<p>El código CSS varia en cuanto a IE como Firefox</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#cuadro2</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#EEEEEE</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#CCCCCC</span><span style="color: #00AA00;">;</span>  &lt;------ ESTA LINEA NO FUNCIONA EN IE<span style="color: #00AA00;">,</span> ya que no redondea el borde
	<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.masquewordpress.com/como-redondear-las-esquinas-de-un-div-con-jquery-corners/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

