CIcon.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. *+------------------------------------------------------------------------+
  3. *| Licensed Materials - Property of IBM
  4. *| IBM Cognos Products: Viewer
  5. *| (C) Copyright IBM Corp. 2001, 2011
  6. *|
  7. *| US Government Users Restricted Rights - Use, duplication or
  8. *| disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  9. *|
  10. *+------------------------------------------------------------------------+
  11. */
  12. /*
  13. Class CIcon
  14. todo : Add commments describing class....
  15. */
  16. function CIcon(iconPath, toolTip) {
  17. this.m_iconPath = iconPath;
  18. this.m_toolTip = toolTip;
  19. this.m_enabled = true;
  20. // The UI framework defaults the icon width/height to 16. If you need to change this, call setHeight and/or setWidth
  21. this.m_height = 16;
  22. this.m_width = 16;
  23. }
  24. function CIcon_draw() {
  25. var html='';
  26. html += '<img src="';
  27. if(typeof this.m_iconPath != "undefined" && this.m_iconPath !== '' && this.m_iconPath != "blankIcon") {
  28. if(this.m_enabled == true) {
  29. html += this.m_iconPath;
  30. }
  31. else {
  32. html += this.getDisabledImagePath();
  33. }
  34. html += '" title="';
  35. if(typeof this.m_toolTip == "string" && this.m_toolTip.length > 0) {
  36. html += this.m_toolTip;
  37. }
  38. html += '" alt="';
  39. if(typeof this.m_toolTip == "string" && this.m_toolTip.length > 0) {
  40. html += this.m_toolTip;
  41. }
  42. html += '" width="';
  43. html += this.m_width;
  44. html += '" height="';
  45. html += this.m_height;
  46. html += '"/>';
  47. } else {
  48. html += '../common/images/spacer.gif';
  49. if (this.m_iconPath == "blankIcon")
  50. {
  51. html += '" alt="';
  52. html += '" width="';
  53. html += this.m_width;
  54. html += '" height="';
  55. html += this.m_height;
  56. html += '"/>';
  57. }
  58. else
  59. {
  60. html += '" alt="';
  61. html += '" width="1" height="1"/>';
  62. }
  63. }
  64. return html;
  65. }
  66. function CIcon_getDisabledImagePath() {
  67. var imagePathArray = this.m_iconPath.split('/');
  68. var iconPath='';
  69. for(var i = 0; i < (imagePathArray.length -1); ++i) {
  70. iconPath += imagePathArray[i] + '/';
  71. }
  72. iconPath += 'dis_' + imagePathArray[imagePathArray.length-1];
  73. return iconPath;
  74. }
  75. function CIcon_getPath() {
  76. return this.m_iconPath;
  77. }
  78. function CIcon_setPath(path) {
  79. this.m_iconPath = path;
  80. }
  81. function CIcon_getToolTip() {
  82. return this.m_toolTip;
  83. }
  84. function CIcon_setToolTip(toolTip) {
  85. this.m_toolTip = toolTip;
  86. }
  87. function CIcon_enable() {
  88. this.m_enabled = true;
  89. }
  90. function CIcon_disable() {
  91. this.m_enabled = false;
  92. }
  93. function CIcon_isEnabled() {
  94. return this.m_enabled;
  95. }
  96. function CIcon_setHeight(height) {
  97. this.m_height = height;
  98. }
  99. function CIcon_getHeight() {
  100. return this.m_height;
  101. }
  102. function CIcon_setWidth(width) {
  103. this.m_width = width;
  104. }
  105. function CIcon_getWidth() {
  106. return this.m_width;
  107. }
  108. CIcon.prototype.draw = CIcon_draw;
  109. CIcon.prototype.enable = CIcon_enable;
  110. CIcon.prototype.disable = CIcon_disable;
  111. CIcon.prototype.isEnabled = CIcon_isEnabled;
  112. CIcon.prototype.getDisabledImagePath = CIcon_getDisabledImagePath;
  113. CIcon.prototype.getPath = CIcon_getPath;
  114. CIcon.prototype.setPath = CIcon_setPath;
  115. CIcon.prototype.setHeight = CIcon_setHeight;
  116. CIcon.prototype.getHeight = CIcon_getHeight;
  117. CIcon.prototype.setWidth = CIcon_setWidth;
  118. CIcon.prototype.getWidth = CIcon_getWidth;