roundedpanel.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2008 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <!--
  9. Demo file for goog.ui.RoundedPanel component
  10. -->
  11. <head>
  12. <title>goog.ui.RoundedPanel Demo</title>
  13. <link rel="stylesheet" href="css/demo.css">
  14. <link rel="stylesheet" href="../css/roundedpanel.css">
  15. <script src="../base.js"></script>
  16. <script>
  17. goog.require('goog.dom');
  18. goog.require('goog.ui.RoundedPanel');
  19. </script>
  20. <script>
  21. var INT_BASE = 10;
  22. var rp;
  23. /**
  24. * Decorates roundedPanel node through a RoundedPanel instance.
  25. */
  26. function decorateRoundedPanel() {
  27. // Obtain the values from the 'input' and 'select' elements.
  28. var panelWidth = goog.dom.getElement('panelWidth').value;
  29. var panelHeight = goog.dom.getElement('panelHeight').value;
  30. var borderWidth = parseInt(
  31. goog.dom.getElement('borderWidth').value,
  32. INT_BASE);
  33. var borderColor = goog.dom.getElement('borderColor').value;
  34. var radius = parseInt(goog.dom.getElement('radius').value, INT_BASE);
  35. var backgroundColor = goog.dom.getElement('backgroundColor').value;
  36. var cornersSelect = goog.dom.getElement('corners');
  37. var corners = parseInt(
  38. cornersSelect.options[cornersSelect.selectedIndex].value);
  39. // Dispose of any existing RoundedPanel instance before creating
  40. // a new one.
  41. if (rp) {
  42. rp.dispose();
  43. rp = null;
  44. }
  45. // Set the dimensions of the panel and decorate roundedPanel.
  46. var roundedPanelNode = goog.dom.getElement('roundedPanel');
  47. roundedPanelNode.style.height = panelHeight;
  48. roundedPanelNode.style.width = panelWidth;
  49. var startTime = new Date();
  50. rp = goog.ui.RoundedPanel.create(radius,
  51. borderWidth,
  52. borderColor,
  53. backgroundColor,
  54. corners);
  55. rp.decorate(roundedPanelNode);
  56. var endTime = new Date();
  57. // Display the amount of time taken to render the RoundedPanel.
  58. var debugNode = goog.dom.getElement('debug');
  59. debugNode.innerHTML = 'Rendering time: ' +
  60. (endTime - startTime) + 'ms';
  61. };
  62. /**
  63. * Sets event handlers on the 'input' and 'select' elements containing
  64. * values needed to create the rounded panel.
  65. */
  66. function init() {
  67. // Set the event handler for the 'select' element to update the panel
  68. // when onchange fires.
  69. var cornersSelect = goog.dom.getElement('corners');
  70. cornersSelect.onchange = decorateRoundedPanel;
  71. // Set the event handlers for the 'input' elements to update the panel
  72. // when onchange fires.
  73. var inputs = goog.dom.getElementsByTagNameAndClass(null, 'rpInput');
  74. for (var i = 0; i < inputs.length; i++) {
  75. inputs[i].onchange = decorateRoundedPanel;
  76. }
  77. decorateRoundedPanel();
  78. };
  79. </script>
  80. </head>
  81. <body>
  82. <div id="roundedPanel">
  83. <div class="goog-roundedpanel-content">
  84. <div>
  85. Panel Width:<br>
  86. <input type="text" class="rpInput" id="panelWidth">
  87. </div>
  88. <div>
  89. Panel Height:<br>
  90. <input type="text" class="rpInput" id="panelHeight">
  91. </div>
  92. <div>
  93. Border Width:<br>
  94. <input type="text" class="rpInput" value="1" id="borderWidth">
  95. </div>
  96. <div>
  97. Border Color:<br>
  98. <input type="text" class="rpInput" value="#fedcba" id="borderColor">
  99. </div>
  100. <div>
  101. Radius:<br>
  102. <input type="text" class="rpInput" value="1" id="radius">
  103. </div>
  104. <div>
  105. Background Color:<br>
  106. <input type="text" class="rpInput" value="#abcdef" id="backgroundColor">
  107. </div>
  108. <div>
  109. Corners:<br>
  110. <select id="corners">
  111. <option value="15">All</option>
  112. <option value="12">Top</option>
  113. <option value="3">Bottom</option>
  114. <option value="6">Left</option>
  115. <option value="9">Right</option>
  116. <option value="4">Top Left</option>
  117. <option value="8">Top Right</option>
  118. <option value="2">Bottom Left</option>
  119. <option value="1">Bottom Right</option>
  120. </select>
  121. </div>
  122. <div id="debug">Rendering Time:</div>
  123. </div>
  124. </div>
  125. <script type="text/javascript">
  126. init();
  127. </script>
  128. </body>
  129. </html>