<?xml version="1.0"?>
     <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
     <channel>
      <link>http://www.bitacora.davidesperalta.com/</link>
      <title>David Esperalta - Entrada "Mejorando el plugin StyleSwichter" de la bitácora</title>
      <generator>Gesbit</generator>
      <description>Bitácora personal, software, opinión</description>
      <atom:link href="http://www.bitacora.davidesperalta.com/rss/" rel="self"
       type="application/rss+xml" />
    
      <item>
       <link>http://www.bitacora.davidesperalta.com/mejorando-el-plugin-styleswichter/</link>
       <guid>http://www.bitacora.davidesperalta.com/mejorando-el-plugin-styleswichter/</guid>
       <pubDate>Sun, 20 Apr 2008 18:48:23 +0200</pubDate>
       <title><![CDATA[ Mejorando el plugin StyleSwichter ]]></title>
       <description><![CDATA[<p>Me gusta cómo ha quedado al cabo el plugin <a title="Más información, ejemplo y descarga" href="http://www.bitacora.davidesperalta.com/jquery-styleswichter/">StyleSwichter para jQuery</a>. Al cabo lo he reducido a una sola función, además de haberle añadido las opciones posibles relacionadas con la "cookie" que es preciso utilizar.</p><div class="gbhighlighcode"><div class="sourcecode"><pre class="javascript"><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>$<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
&nbsp;
  $.<span style="color: #006600;">fn</span>.<span style="color: #006600;">StyleSwichter</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>options<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> opts = $.<span style="color: #006600;">extend</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>, $.<span style="color: #006600;">fn</span>.<span style="color: #006600;">StyleSwichter</span>.<span style="color: #006600;">defaults</span>, options<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #003366; font-weight: bold;">var</span> o = $.<span style="color: #006600;">meta</span> ? $.<span style="color: #006600;">extend</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>, opts, $this.<span style="color: #006600;">data</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> : opts;
    $<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'link'</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">each</span><span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>i<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">rel</span> == <span style="color: #3366CC;">'stylesheet'</span> &amp;&amp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">title</span> == o.<span style="color: #006600;">linkTitle</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>o.<span style="color: #006600;">cssPath</span> != <span style="color: #3366CC;">''</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">href</span> = o.<span style="color: #006600;">cssPath</span>;
          $.<span style="color: #006600;">cookie</span><span style="color: #66cc66;">&#40;</span>o.<span style="color: #006600;">cookieName</span>,<span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">href</span>,<span style="color: #66cc66;">&#123;</span>
            path: o.<span style="color: #006600;">cookiePath</span>,
            expires: o.<span style="color: #006600;">cookieDays</span>,
            domain: o.<span style="color: #006600;">cookieDomain</span>,
            secure: o.<span style="color: #006600;">cookieSecure</span>
          <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span><span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>$.<span style="color: #006600;">cookie</span><span style="color: #66cc66;">&#40;</span>o.<span style="color: #006600;">cookieName</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
          <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">href</span> = $.<span style="color: #006600;">cookie</span><span style="color: #66cc66;">&#40;</span>o.<span style="color: #006600;">cookieName</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #66cc66;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span>;
      <span style="color: #66cc66;">&#125;</span>
    <span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span>;
  <span style="color: #66cc66;">&#125;</span>;
&nbsp;
  $.<span style="color: #006600;">fn</span>.<span style="color: #006600;">StyleSwichter</span>.<span style="color: #006600;">defaults</span>=<span style="color: #66cc66;">&#123;</span>
    cssPath: <span style="color: #3366CC;">''</span>,
    cookiePath: <span style="color: #3366CC;">''</span>,
    cookieDays: <span style="color: #CC0000;">30</span>,
    cookieDomain: <span style="color: #3366CC;">''</span>,
    cookieSecure: <span style="color: #003366; font-weight: bold;">false</span>,
    linkTitle: <span style="color: #3366CC;">'styleswichter'</span>,
    cookieName: <span style="color: #3366CC;">'selected-style'</span>
  <span style="color: #66cc66;">&#125;</span>;
&nbsp;
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>jQuery<span style="color: #66cc66;">&#41;</span>;</pre></div></div>
<p>Y para mí tengo que aún podría dársele alguna que otra vuelta. Que todavía podría mejorarse, sin complicarlo. Bueno. El caso es que no me he resistido a publicar aquí el código fuente. Como si pensara que fuera curioso...</p>]]></description>
      </item>
      
     </channel>
    </rss>