Posted By

conspirator on 11/12/08


Tagged

textmate jquery text cookies resizer


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

sulfurito


Smart Text Re-sizer ala jQuery (and cookies)


 / Published in: Other
 

You'll need the latest version of jQuery and the jquery.cookie plugin(Snag it here!)

  1. <script src="graphics/js/jquery-1.2.6.min.js" type="text/javascript"></script>
  2. <script src="graphics/js/jquery.cookie.js" type="text/javascript"></script>
  3. <script type="text/javascript" charset="utf-8">
  4. $(document).ready(function() {
  5. // See which font size the user wants
  6. $(".text a").click(function() {
  7. switch ($(this).attr("class")) {
  8. case 'small' : setFontSize(.8); break;
  9. case 'large' : setFontSize(1.6); break;
  10. case 'default' : setFontSize(1.2); break;
  11. }
  12. return false;
  13. });
  14.  
  15. // Set the font size and set a cookie
  16. function setFontSize(size) {
  17. $("#wrap, input, textarea").animate({fontSize: size+"em"}, 500).fadeIn("slow");
  18. createCookie(size);
  19. }
  20.  
  21. // Create and read coookies
  22. // Code functions by: Peter-Paul Koch
  23. // http://www.quirksmode.org/js/cookies.html
  24. function createCookie(value) {
  25. var date = new Date();
  26. date.setTime(date.getTime()+(30*24*60*60*1000));
  27. var expires = "; expires="+date.toGMTString();
  28. document.cookie = "font_size="+value+expires+"; path=/";
  29. }
  30. var font_size = $.cookie('font_size');
  31. if (font_size == '0.8') {
  32. $('#wrap').css("font-size",".8em");
  33. }
  34. if (font_size == '1.6') {
  35. $('#wrap').css("font-size","1.6em");
  36. }
  37. if (font_size == '1.2') {
  38. $('#wrap').css("font-size","1.2em");
  39. }
  40. });
  41. </script>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: retrolution on January 20, 2009

Hi! Thank! This is exactly what I'm looking for - but it there a HTML example of how it should be activated ? Thanks in advance. Cheers Kenneth

You need to login to post a comment.