Viewport.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-container-Viewport'>/**
  19. </span> * A specialized container representing the viewable application area (the browser viewport).
  20. *
  21. * The Viewport renders itself to the document body, and automatically sizes itself to the size of
  22. * the browser viewport and manages window resizing. There may only be one Viewport created
  23. * in a page.
  24. *
  25. * Like any {@link Ext.container.Container Container}, a Viewport will only perform sizing and positioning
  26. * on its child Components if you configure it with a {@link #layout}.
  27. *
  28. * A Common layout used with Viewports is {@link Ext.layout.container.Border border layout}, but if the
  29. * required layout is simpler, a different layout should be chosen.
  30. *
  31. * For example, to simply make a single child item occupy all available space, use
  32. * {@link Ext.layout.container.Fit fit layout}.
  33. *
  34. * To display one &quot;active&quot; item at full size from a choice of several child items, use
  35. * {@link Ext.layout.container.Card card layout}.
  36. *
  37. * Inner layouts are available because all {@link Ext.panel.Panel Panel}s
  38. * added to the Viewport, either through its {@link #cfg-items}, or the {@link #method-add}
  39. * method of any of its child Panels may themselves have a layout.
  40. *
  41. * The Viewport does not provide scrolling, so child Panels within the Viewport should provide
  42. * for scrolling if needed using the {@link #autoScroll} config.
  43. *
  44. * An example showing a classic application border layout:
  45. *
  46. * @example
  47. * Ext.create('Ext.container.Viewport', {
  48. * layout: 'border',
  49. * items: [{
  50. * region: 'north',
  51. * html: '&lt;h1 class=&quot;x-panel-header&quot;&gt;Page Title&lt;/h1&gt;',
  52. * border: false,
  53. * margins: '0 0 5 0'
  54. * }, {
  55. * region: 'west',
  56. * collapsible: true,
  57. * title: 'Navigation',
  58. * width: 150
  59. * // could use a TreePanel or AccordionLayout for navigational items
  60. * }, {
  61. * region: 'south',
  62. * title: 'South Panel',
  63. * collapsible: true,
  64. * html: 'Information goes here',
  65. * split: true,
  66. * height: 100,
  67. * minHeight: 100
  68. * }, {
  69. * region: 'east',
  70. * title: 'East Panel',
  71. * collapsible: true,
  72. * split: true,
  73. * width: 150
  74. * }, {
  75. * region: 'center',
  76. * xtype: 'tabpanel', // TabPanel itself has no title
  77. * activeTab: 0, // First tab active by default
  78. * items: {
  79. * title: 'Default Tab',
  80. * html: 'The first tab\'s content. Others may be added dynamically'
  81. * }
  82. * }]
  83. * });
  84. */
  85. Ext.define('Ext.container.Viewport', {
  86. extend: 'Ext.container.Container',
  87. alias: 'widget.viewport',
  88. requires: ['Ext.EventManager'],
  89. alternateClassName: 'Ext.Viewport',
  90. // Privatize config options which, if used, would interfere with the
  91. // correct operation of the Viewport as the sole manager of the
  92. // layout of the document body.
  93. <span id='Ext-container-Viewport-cfg-applyTo'> /**
  94. </span> * @cfg {String/HTMLElement/Ext.Element} applyTo
  95. * @private
  96. */
  97. <span id='Ext-container-Viewport-cfg-allowDomMove'> /**
  98. </span> * @cfg {Boolean} allowDomMove
  99. * @private
  100. */
  101. <span id='Ext-container-Viewport-cfg-renderTo'> /**
  102. </span> * @cfg {String/HTMLElement/Ext.Element} renderTo
  103. * Always renders to document body.
  104. * @private
  105. */
  106. <span id='Ext-container-Viewport-cfg-height'> /**
  107. </span> * @cfg {Number} height
  108. * Sets itself to viewport width.
  109. * @private
  110. */
  111. <span id='Ext-container-Viewport-cfg-width'> /**
  112. </span> * @cfg {Number} width
  113. * Sets itself to viewport height.
  114. * @private
  115. */
  116. <span id='Ext-container-Viewport-property-isViewport'> /**
  117. </span> * @property {Boolean} isViewport
  118. * `true` in this class to identify an object as an instantiated Viewport, or subclass thereof.
  119. */
  120. isViewport: true,
  121. ariaRole: 'application',
  122. preserveElOnDestroy: true,
  123. initComponent : function() {
  124. var me = this,
  125. html = document.body.parentNode,
  126. el;
  127. // Get the DOM disruption over with beforfe the Viewport renders and begins a layout
  128. Ext.getScrollbarSize();
  129. // Clear any dimensions, we will size later on
  130. me.width = me.height = undefined;
  131. me.callParent(arguments);
  132. Ext.fly(html).addCls(Ext.baseCSSPrefix + 'viewport');
  133. if (me.autoScroll) {
  134. delete me.autoScroll;
  135. Ext.fly(html).setStyle('overflow', 'auto');
  136. }
  137. me.el = el = Ext.getBody();
  138. el.setHeight = Ext.emptyFn;
  139. el.setWidth = Ext.emptyFn;
  140. el.setSize = Ext.emptyFn;
  141. el.dom.scroll = 'no';
  142. me.allowDomMove = false;
  143. me.renderTo = me.el;
  144. },
  145. onRender: function() {
  146. var me = this;
  147. me.callParent(arguments);
  148. // Important to start life as the proper size (to avoid extra layouts)
  149. // But after render so that the size is not stamped into the body
  150. me.width = Ext.Element.getViewportWidth();
  151. me.height = Ext.Element.getViewportHeight();
  152. },
  153. afterFirstLayout: function() {
  154. var me = this;
  155. me.callParent(arguments);
  156. setTimeout(function() {
  157. Ext.EventManager.onWindowResize(me.fireResize, me);
  158. }, 1);
  159. },
  160. fireResize : function(width, height){
  161. // In IE we can get resize events that have our current size, so we ignore them
  162. // to avoid the useless layout...
  163. if (width != this.width || height != this.height) {
  164. this.setSize(width, height);
  165. }
  166. }
  167. });
  168. </pre>
  169. </body>
  170. </html>