VAFont.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. VAFont = function(w, fontSize) {
  2. this.window = w ? w : window;
  3. this.fontMax = 24;
  4. this.fontMin = 10;
  5. this.fontSize = fontSize ? fontSize : 12;
  6. this.area = "a, span, p, li, b, div, td, h1, h2, h3, h4, h5, h6, font";
  7. this.active = jQuery.proxy(this.active, this);
  8. this.fontPlus = jQuery.proxy(this.fontPlus, this);
  9. this.fontMinus = jQuery.proxy(this.fontMinus, this);
  10. this.size = jQuery.proxy(this.size, this);
  11. }
  12. VAFont.prototype = {
  13. active: function() {
  14. if (typeof (this.fontSize) == "number") {
  15. jQuery(this.area, this.window.document.body).css("font-size", this.fontSize);
  16. }
  17. },
  18. fontPlus: function() {
  19. if (typeof (this.fontSize) != "number") {
  20. this.fontSize = 12;
  21. }
  22. if (this.fontSize == this.fontMax) {
  23. return false;
  24. }
  25. this.fontSize += 2;
  26. if (this.fontSize > this.fontMax) {
  27. this.fontSize = this.fontMax;
  28. }
  29. jQuery(this.area, this.window.document.body).css("font-size", this.fontSize);
  30. return this.fontSize < this.fontMax;
  31. },
  32. fontMinus: function() {
  33. if (typeof (this.fontSize) != "number") {
  34. this.fontSize = 12;
  35. }
  36. if (this.fontSize == this.fontMin) {
  37. return false;
  38. }
  39. this.fontSize -= 2;
  40. if (this.fontSize < this.fontMin) {
  41. this.fontSize = this.fontMin;
  42. }
  43. jQuery(this.area, this.window.document.body).css("font-size", this.fontSize);
  44. return this.fontSize > this.fontMin;
  45. },
  46. size: function(s) {
  47. if (s) {
  48. this.fontSize = s;
  49. if (typeof (this.fontSize) == "number") {
  50. jQuery(this.area, this.window.document.body).css("font-size", this.fontSize);
  51. }
  52. else {
  53. jQuery(this.area, this.window.document.body).css("font-size", "");
  54. }
  55. }
  56. else {
  57. return this.fontSize;
  58. }
  59. }
  60. }