InfoIcon.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. define( function() {
  2. "use strict";
  3. function Control()
  4. {
  5. };
  6. Control.prototype.draw = function( oControlHost )
  7. {
  8. var o = oControlHost.configuration || {};
  9. var el = oControlHost.container;
  10. var v_iHeight = ( o.Height || el.offsetHeight );
  11. var v_iWidth = ( o.Width || el.offsetWidth );
  12. var v_bPositionOnTheRight = ( o.Position == "Right" );
  13. var sSourceType = o["Source Type"] || "Text";
  14. var sSelector = "#" + el.id;
  15. var sStyle =
  16. '<style>' +
  17. sSelector + ' svg' +
  18. '{' +
  19. 'fill:' + ( o["Fill"] || "#6D7777" ) + ';' +
  20. '}' +
  21. sSelector + ' svg:hover' +
  22. '{' +
  23. 'fill:' + ( o["Hover Fill"] || "#4178BE" ) + ';' +
  24. '}' +
  25. sSelector + ' DIV' +
  26. '{' +
  27. 'cursor: default;' +
  28. 'visibility: hidden;' +
  29. 'position: absolute;' +
  30. ( ( o["Box Shadow"] !== false ) ? 'box-shadow:0 1px 5px rgba(0, 0, 0, 0.25);' : '' ) +
  31. 'margin: ' + ( v_bPositionOnTheRight ? '0' : v_iHeight ) + 'px 0 0 ' + ( v_bPositionOnTheRight ? v_iWidth : '0' ) + 'px;';
  32. if ( sSourceType == "Text" )
  33. {
  34. sStyle +=
  35. 'max-width: ' + ( o["Max Width"] || 300 ) + 'px;' +
  36. 'padding: 2px 4px 2px 4px;' +
  37. 'border-radius: 2px;' +
  38. 'border: 1px solid ' + ( o["Border Color"] || '#E6E7E8' ) + ';' +
  39. 'color: ' + ( o["Font Color"] || '#444444' ) + ';' +
  40. 'background-color: ' + ( o["Background Color"] || '#F2F2F2' ) + ';' +
  41. ( o["Font Family"] ? ( 'font-family:' + o["Font Family"] + ';' ) : '' ) +
  42. ( o["Font Size"] ? ( 'font-size:' + o["Font Size"] + ';' ) : '' );
  43. }
  44. sStyle +=
  45. '}' +
  46. sSelector + ':hover DIV { visibility:visible; }' +
  47. '</style>';
  48. var sSvgIcon = o["SVG Icon"] || '<svg xmlns="http://www.w3.org/2000/svg" width="' + v_iWidth + 'px" height="' + v_iHeight + 'px" viewBox="0 0 32 32"><use xlink:href="#common-information"/></svg>';
  49. var sSource = o.Text || "";
  50. if ( !sSource && this.m_oDataStore )
  51. {
  52. sSource = this.m_oDataStore.getFormattedCellValue( 0, 0 );
  53. }
  54. switch ( sSourceType )
  55. {
  56. case "Text":
  57. sSource = this.HTMLEncode( sSource );
  58. break;
  59. case "URL":
  60. sSource = '<img src="' + sSource + '"/>';
  61. break;
  62. }
  63. el.innerHTML = sStyle + '<DIV>' + sSource + '</DIV>' + sSvgIcon;
  64. };
  65. Control.prototype.setData = function( oControlHost, oDataStore )
  66. {
  67. this.m_oDataStore = oDataStore;
  68. };
  69. Control.prototype.HTMLEncode = function( s )
  70. {
  71. return String( s ).replace( /&/g, "&amp;" ).replace( /</g, "&lt;" ).replace( />/g, "&gt;" );
  72. };
  73. return Control;
  74. });