preferences panel cookies - font-size and body class


/ Published in: jQuery
Save to your folder(s)

It could be a lot more reduced, but I have left the cases etc. in as I'll probably be changing more properties


Copy this code and paste it in your HTML
  1. function preferences () {
  2.  
  3. function set_font_size(string) {
  4. switch(string) {
  5. case 'largest':
  6. $('body').css({ 'font-size': '16px' });
  7. break;
  8. case 'large':
  9. $('body').css({ 'font-size': '15px' });
  10. break;
  11. case 'medium':
  12. $('body').css({ 'font-size': '14px' });
  13. break;
  14. case 'small':
  15. $('body').css({ 'font-size': '13px' });
  16. break;
  17. case 'smallest':
  18. $('body').css({ 'font-size': '12px' });
  19. break;
  20. }
  21. }
  22.  
  23. function set_contrast(body_class) {
  24. $('body').attr('class','');
  25. switch(body_class) {
  26. case 'default':
  27. $('body').addClass('default');
  28. break;
  29. case 'high-contrast':
  30. $('body').addClass('high-contrast');
  31. break;
  32. case 'high-contrast-inverse':
  33. $('body').addClass('high-contrast-inverse');
  34. break;
  35. }
  36. }
  37. var current_font_size = $.cookie('font-size');
  38. set_font_size(current_font_size);
  39.  
  40. var current_contrast = $.cookie('contrast');
  41. $('body').attr('class','').addClass(current_contrast);
  42.  
  43. $('#font-sizes li input:checked').attr('checked','');
  44. $('#font-sizes li input#'+current_font_size).attr('checked','checked');
  45.  
  46. $('#contrasts li input:checked').attr('checked','');
  47. $('#contrasts li input#'+current_contrast).attr('checked','checked');
  48.  
  49. $('ul#font-sizes li input').click(function(){
  50. var new_value = $(this).attr('value');
  51. $.cookie('font-size', '');
  52. $.cookie('font-size', new_value, { path: '/', expires: 10 });
  53. set_font_size(new_value);
  54. });
  55.  
  56. $('ul#contrasts li input').click(function(){
  57. var new_value = $(this).attr('value');
  58. $.cookie('contrast', '');
  59. $.cookie('contrast', new_value, { path: '/', expires: 10 });
  60. set_contrast(new_value);
  61. });
  62.  
  63. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.