C_DisplayButton.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. define( function() {
  2. "use strict";
  3. function Control()
  4. {
  5. };
  6. Control.prototype.initialize = function( oControlHost, fnDoneInitializing )
  7. {
  8. this.m_oControlHost = oControlHost;
  9. this.m_sControlName = this.getConfigurationValue( "Control name", "Block1" );
  10. this.m_bVertical = this.getConfigurationValue( "Vertical", false );
  11. fnDoneInitializing();
  12. };
  13. Control.prototype.destroy = function( oControlHost )
  14. {
  15. this.m_oControlHost = null;
  16. };
  17. Control.prototype.getConfigurationValue = function( sName, sDefaultValue )
  18. {
  19. var o = this.m_oControlHost.configuration;
  20. return ( o && ( o[sName] !== undefined ) ) ? o[sName] : sDefaultValue;
  21. };
  22. Control.prototype.draw = function( oControlHost )
  23. {
  24. var elContainer = oControlHost.container;
  25. var sUniqueSelector = 'myDisplayButton_' + elContainer.id;
  26. var sBorderColor = this.getConfigurationValue( "Border color", null );
  27. var sHoverBackgroundColor = this.getConfigurationValue( "Hover background color", null );
  28. var sHoverColor = this.getConfigurationValue( "Hover foreground color", null );
  29. elContainer.innerHTML =
  30. '<style>' +
  31. '.' + sUniqueSelector + '\n' +
  32. '{' +
  33. 'background-color:' + this.getConfigurationValue( "Background color", "transparent" ) + ';' +
  34. 'color:' + this.getConfigurationValue( "Foreground color", "currentcolor" ) + ';' +
  35. 'font-size:' + this.getConfigurationValue( "Font size", "inherit" ) + ';' +
  36. 'padding:' + this.getConfigurationValue( "Padding", "0px 6px 0px 6px" ) + ';' +
  37. ( sBorderColor ? ( 'border:1px solid ' + sBorderColor ) : 'border:0' ) + ';' +
  38. '}' +
  39. '.' + sUniqueSelector + ':hover\n' +
  40. '{' +
  41. ( sHoverBackgroundColor ? ( 'background-color:' + sHoverBackgroundColor + ';' ) : '' ) +
  42. ( sHoverColor ? ( 'color:' + sHoverColor + ';' ) : '' ) +
  43. ( sBorderColor ? ( 'border:1px solid ' + this.getConfigurationValue( "Hover border color", "#EAEAEA" ) ) : '' ) + ';' +
  44. '}' +
  45. '</style>' +
  46. '<button class="' + sUniqueSelector + '"></button>';
  47. this.m_btn = elContainer.lastChild;
  48. this.m_btn.onclick = this.onClick.bind( this );
  49. this.updateButton();
  50. };
  51. Control.prototype.onClick = function()
  52. {
  53. this.m_oControlHost.page.getControlByName( this.m_sControlName ).toggleDisplay();
  54. this.updateButton();
  55. };
  56. Control.prototype.updateButton = function()
  57. {
  58. var b = this.m_oControlHost.page.getControlByName( this.m_sControlName ).getDisplay();
  59. this.m_btn.innerHTML = b ? ( this.m_bVertical ? '&#9660;' : '&#9664;' ) : ( this.m_bVertical ? '&#9650;' : '&#9654;' );
  60. this.m_btn.title = b ? 'Hide' : 'Show';
  61. };
  62. return Control;
  63. });