splitpane.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2010 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. <head>
  9. <title>goog.ui.SplitPane</title>
  10. <script src="../base.js"></script>
  11. <script>
  12. goog.require('goog.dom');
  13. goog.require('goog.events');
  14. goog.require('goog.ui.Component');
  15. goog.require('goog.ui.Ratings');
  16. goog.require('goog.ui.ServerChart');
  17. goog.require('goog.ui.SplitPane');
  18. goog.require('goog.ui.SplitPane.Orientation');
  19. </script>
  20. <link rel="stylesheet" href="css/demo.css">
  21. <style class="text/css">
  22. /* NOTE: A bug in Safari 3 requires these css definitions to be in here.
  23. Do not move these to a separate file without testing safari 3! */
  24. /* These are recommended styles for the default splitpane */
  25. .goog-splitpane {
  26. height: 200px;
  27. width: 300px;
  28. }
  29. .goog-splitpane-handle {
  30. border-left: 1px solid gray;
  31. border-right: 1px solid gray;
  32. background: #ccc;
  33. position: absolute;
  34. }
  35. .goog-splitpane-handle-horizontal {
  36. cursor: col-resize;
  37. }
  38. .goog-splitpane-handle-vertical {
  39. cursor: row-resize;
  40. }
  41. .goog-splitpane-first-container,
  42. .goog-splitpane-second-container {
  43. border: 5px solid black;
  44. overflow: auto;
  45. position: absolute;
  46. }
  47. /* The rest of these styles are for the splitpane demo, splitpane.html */
  48. /* Example of styling a particular handle */
  49. #another-splitpane .goog-splitpane-handle {
  50. background: gray;
  51. }
  52. /* The following styles are for the rating widget, which is used in the splipane
  53. example. These have nothing to do with the splitpane! */
  54. .goog-ratings {
  55. display: block;
  56. float: left;
  57. height: 20px;
  58. height: 20px;
  59. }
  60. .goog-ratings-star {
  61. display: block;
  62. float: left;
  63. padding-left: 13px;
  64. height: 19px;
  65. cursor: pointer;
  66. background-image: url('../images/ratingstars.gif');
  67. background-repeat: no-repeat;
  68. }
  69. .goog-ratings-firststar-off {
  70. padding-left: 20px;
  71. background-position: 0px 0px;
  72. }
  73. .goog-ratings-firststar-on {
  74. padding-left: 20px;
  75. background-position: 0px -20px;
  76. }
  77. .goog-ratings-midstar-off {
  78. background-position: 0px -40px;
  79. }
  80. .goog-ratings-midstar-on {
  81. background-position: 0px -60px;
  82. }
  83. .goog-ratings-laststar-off {
  84. padding-left: 18px;
  85. background-position: 0px -80px;
  86. }
  87. .goog-ratings-laststar-on {
  88. padding-left: 18px;
  89. background-position: 0px -100px;
  90. }
  91. </style>
  92. </head>
  93. <body>
  94. <h1>goog.ui.SplitPane</h1>
  95. Left Component Size: <input type='text' id='firstComponentSize' size='4' value=''>
  96. Width: <input type='text' id='newWidth' size='5' value='300'>
  97. Height: <input type='text' id='newHeight' size='5' value='200'>
  98. <br>
  99. <input type='radio' id='select1' name='selectSplitter' checked='true' value='first'>First One
  100. <input type='radio' id='select2' name='selectSplitter' value='second'>Second One
  101. <input type='button' value='Update Splitter' onclick='updatePane_()'>
  102. <input type='button' value='Change Orientation' onclick='changeOrientation_()'>
  103. <p>
  104. <div class='goog-splitpane' id='anotherSplitter'>
  105. <div class='goog-splitpane-first-container'>
  106. Left Frame
  107. </div>
  108. <div class='goog-splitpane-second-container'>
  109. <iframe style='z-index:10; width:100%; height:100%' src='http://www.google.com/'></iframe>
  110. </div>
  111. <div class='goog-splitpane-handle'></div>
  112. </div>
  113. First Component Width: <span id='componentOneWidth'></span>
  114. <div id="test1">
  115. <select name="sel">
  116. <option>Aweful</option>
  117. <option>Bad</option>
  118. <option selected>Ok</option>
  119. <option>Good</option>
  120. <option>Excellent</option>
  121. </select>
  122. </div>
  123. <p/>
  124. <p/>
  125. <div id="chart"></div>
  126. <script>
  127. /**
  128. * Show the width of the first splitpane on event changes.
  129. * @param {goog.events.Event} e The event
  130. */
  131. var showWidth_ = function(e) {
  132. var el = document.getElementById('componentOneWidth');
  133. if (el) {
  134. goog.dom.setTextContent(el, e.target.getFirstComponentSize());
  135. }
  136. }
  137. var lhs = new goog.ui.Component();
  138. var rhs = new goog.ui.Component();
  139. // Set up splitpane with already existing DOM.
  140. var splitpane1 = new goog.ui.SplitPane(lhs, rhs,
  141. goog.ui.SplitPane.Orientation.HORIZONTAL);
  142. // Listen for change events and call showWidth.
  143. goog.events.listen(splitpane1, goog.ui.Component.EventType.CHANGE,
  144. showWidth_);
  145. splitpane1.setInitialSize(100);
  146. splitpane1.setHandleSize(10);
  147. splitpane1.decorate(document.getElementById('anotherSplitter'));
  148. splitpane1.setSize(new goog.math.Size(600,300));
  149. var rw1 = new goog.ui.Ratings();
  150. rw1.decorate(document.getElementById('test1'));
  151. // Create a barchart to put in a splitpane
  152. bar = new goog.ui.ServerChart(goog.ui.ServerChart.ChartType.BAR, 180, 104);
  153. bar.addDataSet([8,23,7], '008000');
  154. bar.addDataSet([31,11,7], 'ffcc33');
  155. bar.addDataSet([2,43,70,3,43,74], '3072f3');
  156. bar.setLeftLabels(['','20K','','60K','','100K']);
  157. bar.setXLabels(['O','N','D']);
  158. bar.setMaxValue(100);
  159. var splitpane2 = new goog.ui.SplitPane(rw1, bar,
  160. goog.ui.SplitPane.Orientation.HORIZONTAL);
  161. splitpane2.render();
  162. splitpane2.setContinuousResize(false);
  163. /**
  164. * Change the left splitter size or size a split pane.
  165. * This method reads the form fields to choose the splitter
  166. * and get the new values.
  167. */
  168. var updatePane_ = function() {
  169. var componentSizeValue =
  170. document.getElementById('firstComponentSize').value;
  171. var width = document.getElementById('newWidth').value;
  172. var height = document.getElementById('newHeight').value;
  173. var s1Checked = document.getElementById('select1').checked;
  174. // Which splitter to update.
  175. var whichSplitter = (s1Checked) ? splitpane1 : splitpane2;
  176. var componentSize;
  177. if ('' != componentSizeValue) {
  178. componentSize = parseInt(componentSizeValue, 10);
  179. }
  180. else {
  181. componentSize = whichSplitter.getFirstComponentSize();
  182. }
  183. whichSplitter.setFirstComponentSize(componentSize);
  184. whichSplitter.setSize(new goog.math.Size(width, height));
  185. // If the first pane height is changed, force the second one to update
  186. // so it moves up or down the page.
  187. splitpane2.setFirstComponentSize();
  188. }
  189. /**
  190. * Change the orientation of the splitter pane.
  191. */
  192. var changeOrientation_ = function() {
  193. var s1Checked = document.getElementById('select1').checked;
  194. // Which splitter to update.
  195. var whichSplitter = s1Checked ? splitpane1 : splitpane2;
  196. var orientation = whichSplitter.getOrientation();
  197. if (orientation == goog.ui.SplitPane.Orientation.VERTICAL) {
  198. whichSplitter.setOrientation(goog.ui.SplitPane.Orientation.HORIZONTAL);
  199. } else {
  200. whichSplitter.setOrientation(goog.ui.SplitPane.Orientation.VERTICAL);
  201. }
  202. }
  203. </script>
  204. </body>
  205. </html>