Mejorando el plugin StyleSwichter
Publicada el 20/4/2008 18:48 PM por David Esperalta
Me gusta cómo ha quedado al cabo el plugin StyleSwichter para jQuery. 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.
(function($){ $.fn.StyleSwichter = function(options){ var opts = $.extend({}, $.fn.StyleSwichter.defaults, options); var o = $.meta ? $.extend({}, opts, $this.data()) : opts; $('link').each(function(i){ if(this.rel == 'stylesheet' && this.title == o.linkTitle){ if(o.cssPath != ''){ this.href = o.cssPath; $.cookie(o.cookieName,this.href,{ path: o.cookiePath, expires: o.cookieDays, domain: o.cookieDomain, secure: o.cookieSecure }); }else if($.cookie(o.cookieName)){ this.href = $.cookie(o.cookieName); } return true; } }); return false; }; $.fn.StyleSwichter.defaults={ cssPath: '', cookiePath: '', cookieDays: 30, cookieDomain: '', cookieSecure: false, linkTitle: 'styleswichter', cookieName: 'selected-style' }; })(jQuery);
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...
Categorías: Software
Mejorando el plugin StyleSwichter
Publicada el 20/4/2008 18:48 PM por David Esperalta
Suscribirse a esta entrada - URL para Trackbacks
Publicada el 20/4/2008 18:48 PM por David Esperalta
Suscribirse a esta entrada - URL para Trackbacks
Sin comentarios, ¡escribe uno ahora!