AbstractPanel.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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-panel-AbstractPanel'>/**
  19. </span> * @class Ext.panel.AbstractPanel
  20. * @private
  21. *
  22. * A base class which provides methods common to Panel classes across the Sencha product range.
  23. *
  24. * Please refer to sub class's documentation
  25. */
  26. Ext.define('Ext.panel.AbstractPanel', {
  27. /* Begin Definitions */
  28. extend: 'Ext.container.Container',
  29. mixins: {
  30. docking: 'Ext.container.DockingContainer'
  31. },
  32. requires: ['Ext.util.MixedCollection', 'Ext.Element', 'Ext.toolbar.Toolbar'],
  33. /* End Definitions */
  34. <span id='Ext-panel-AbstractPanel-cfg-baseCls'> /**
  35. </span> * @cfg {String} [baseCls=x-panel]
  36. * The base CSS class to apply to this panel's element.
  37. */
  38. baseCls : Ext.baseCSSPrefix + 'panel',
  39. <span id='Ext-panel-AbstractPanel-cfg-bodyPadding'> /**
  40. </span> * @cfg {Number/String} bodyPadding
  41. * A shortcut for setting a padding style on the body element. The value can either be
  42. * a number to be applied to all sides, or a normal css string describing padding.
  43. * Defaults to &lt;code&gt;undefined&lt;/code&gt;.
  44. */
  45. <span id='Ext-panel-AbstractPanel-cfg-bodyBorder'> /**
  46. </span> * @cfg {Boolean} bodyBorder
  47. * A shortcut to add or remove the border on the body of a panel. This only applies to a panel which has the {@link #frame} configuration set to `true`.
  48. * Defaults to &lt;code&gt;undefined&lt;/code&gt;.
  49. */
  50. <span id='Ext-panel-AbstractPanel-cfg-bodyStyle'> /**
  51. </span> * @cfg {String/Object/Function} bodyStyle
  52. * Custom CSS styles to be applied to the panel's body element, which can be supplied as a valid CSS style string,
  53. * an object containing style property name/value pairs or a function that returns such a string or object.
  54. * For example, these two formats are interpreted to be equivalent:&lt;pre&gt;&lt;code&gt;
  55. bodyStyle: 'background:#ffc; padding:10px;'
  56. bodyStyle: {
  57. background: '#ffc',
  58. padding: '10px'
  59. }
  60. * &lt;/code&gt;&lt;/pre&gt;
  61. */
  62. <span id='Ext-panel-AbstractPanel-cfg-bodyCls'> /**
  63. </span> * @cfg {String/String[]} bodyCls
  64. * A CSS class, space-delimited string of classes, or array of classes to be applied to the panel's body element.
  65. * The following examples are all valid:&lt;pre&gt;&lt;code&gt;
  66. bodyCls: 'foo'
  67. bodyCls: 'foo bar'
  68. bodyCls: ['foo', 'bar']
  69. * &lt;/code&gt;&lt;/pre&gt;
  70. */
  71. <span id='Ext-panel-AbstractPanel-property-isPanel'> /**
  72. </span> * @property {Boolean} isPanel
  73. * `true` in this class to identify an object as an instantiated Panel, or subclass thereof.
  74. */
  75. isPanel: true,
  76. componentLayout: 'dock',
  77. childEls: [
  78. 'body'
  79. ],
  80. renderTpl: [
  81. // If this Panel is framed, the framing template renders the docked items round the frame
  82. '{% this.renderDockedItems(out,values,0); %}',
  83. // This empty div solves an IE6/7/Quirks problem where the margin-top on the bodyEl
  84. // is ignored. Best we can figure, this is triggered by the previousSibling being
  85. // position absolute (a docked item). The goal is to use margins to position the
  86. // bodyEl rather than left/top since that allows us to avoid writing a height on the
  87. // panel and the body. This in turn allows CSS height to expand or contract the
  88. // panel during things like portlet dragging where we want to avoid running a ton
  89. // of layouts during the drag operation.
  90. (Ext.isIE6 || Ext.isIE7 || Ext.isIEQuirks) ? '&lt;div&gt;&lt;/div&gt;' : '',
  91. '&lt;div id=&quot;{id}-body&quot; class=&quot;{baseCls}-body&lt;tpl if=&quot;bodyCls&quot;&gt; {bodyCls}&lt;/tpl&gt;',
  92. ' {baseCls}-body-{ui}&lt;tpl if=&quot;uiCls&quot;&gt;',
  93. '&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-body-{parent.ui}-{.}&lt;/tpl&gt;',
  94. '&lt;/tpl&gt;&quot;&lt;tpl if=&quot;bodyStyle&quot;&gt; style=&quot;{bodyStyle}&quot;&lt;/tpl&gt;&gt;',
  95. '{%this.renderContainer(out,values);%}',
  96. '&lt;/div&gt;',
  97. '{% this.renderDockedItems(out,values,1); %}'
  98. ],
  99. bodyPosProps: {
  100. x: 'x',
  101. y: 'y'
  102. },
  103. // TODO: Move code examples into product-specific files. The code snippet below is Touch only.
  104. <span id='Ext-panel-AbstractPanel-cfg-dockedItems'> /**
  105. </span> * @cfg {Object/Object[]} dockedItems
  106. * A component or series of components to be added as docked items to this panel.
  107. * The docked items can be docked to either the top, right, left or bottom of a panel.
  108. * This is typically used for things like toolbars or tab bars:
  109. * &lt;pre&gt;&lt;code&gt;
  110. var panel = new Ext.panel.Panel({
  111. fullscreen: true,
  112. dockedItems: [{
  113. xtype: 'toolbar',
  114. dock: 'top',
  115. items: [{
  116. text: 'Docked to the top'
  117. }]
  118. }]
  119. });&lt;/code&gt;&lt;/pre&gt;
  120. */
  121. border: true,
  122. <span id='Ext-panel-AbstractPanel-property-emptyArray'> /**
  123. </span> * @private
  124. */
  125. emptyArray: [],
  126. initComponent : function() {
  127. var me = this;
  128. //!frame
  129. //!border
  130. if (me.frame &amp;&amp; me.border &amp;&amp; me.bodyBorder === undefined) {
  131. me.bodyBorder = false;
  132. }
  133. if (me.frame &amp;&amp; me.border &amp;&amp; (me.bodyBorder === false || me.bodyBorder === 0)) {
  134. me.manageBodyBorders = true;
  135. }
  136. me.callParent();
  137. },
  138. beforeDestroy: function(){
  139. this.destroyDockedItems();
  140. this.callParent();
  141. },
  142. // @private
  143. initItems : function() {
  144. this.callParent();
  145. this.initDockingItems();
  146. },
  147. <span id='Ext-panel-AbstractPanel-method-initRenderData'> /**
  148. </span> * Initialized the renderData to be used when rendering the renderTpl.
  149. * @return {Object} Object with keys and values that are going to be applied to the renderTpl
  150. * @private
  151. */
  152. initRenderData: function() {
  153. var me = this,
  154. data = me.callParent();
  155. me.initBodyStyles();
  156. me.protoBody.writeTo(data);
  157. delete me.protoBody;
  158. return data;
  159. },
  160. <span id='Ext-panel-AbstractPanel-method-getComponent'> /**
  161. </span> * Attempts a default component lookup (see {@link Ext.container.Container#getComponent}). If the component is not found in the normal
  162. * items, the dockedItems are searched and the matched component (if any) returned (see {@link #getDockedComponent}). Note that docked
  163. * items will only be matched by component id or itemId -- if you pass a numeric index only non-docked child components will be searched.
  164. * @param {String/Number} comp The component id, itemId or position to find
  165. * @return {Ext.Component} The component (if found)
  166. */
  167. getComponent: function(comp) {
  168. var component = this.callParent(arguments);
  169. if (component === undefined &amp;&amp; !Ext.isNumber(comp)) {
  170. // If the arg is a numeric index skip docked items
  171. component = this.getDockedComponent(comp);
  172. }
  173. return component;
  174. },
  175. getProtoBody: function () {
  176. var me = this,
  177. body = me.protoBody;
  178. if (!body) {
  179. me.protoBody = body = new Ext.util.ProtoElement({
  180. cls: me.bodyCls,
  181. style: me.bodyStyle,
  182. clsProp: 'bodyCls',
  183. styleProp: 'bodyStyle',
  184. styleIsText: true
  185. });
  186. }
  187. return body;
  188. },
  189. <span id='Ext-panel-AbstractPanel-method-initBodyStyles'> /**
  190. </span> * Parses the {@link #bodyStyle} config if available to create a style string that will be applied to the body element.
  191. * This also includes {@link #bodyPadding} and {@link #bodyBorder} if available.
  192. * @return {String} A CSS style string with body styles, padding and border.
  193. * @private
  194. */
  195. initBodyStyles: function() {
  196. var me = this,
  197. body = me.getProtoBody(),
  198. Element = Ext.Element;
  199. if (me.bodyPadding !== undefined) {
  200. body.setStyle('padding', Element.unitizeBox((me.bodyPadding === true) ? 5 : me.bodyPadding));
  201. }
  202. if (me.frame &amp;&amp; me.bodyBorder) {
  203. if (!Ext.isNumber(me.bodyBorder)) {
  204. me.bodyBorder = 1;
  205. }
  206. body.setStyle('border-width', Element.unitizeBox(me.bodyBorder));
  207. }
  208. },
  209. getCollapsedDockedItems: function () {
  210. var me = this;
  211. return me.collapseMode == 'placeholder' ? me.emptyArray : [ me.getReExpander() ];
  212. },
  213. <span id='Ext-panel-AbstractPanel-method-setBodyStyle'> /**
  214. </span> * Sets the body style according to the passed parameters.
  215. * @param {Mixed} style A full style specification string, or object, or the name of a style property to set.
  216. * @param {String} value If the first param was a style property name, the style property value.
  217. * @return {Ext.panel.Panel} this
  218. */
  219. setBodyStyle: function(style, value) {
  220. var me = this,
  221. body = me.rendered ? me.body : me.getProtoBody();
  222. if (Ext.isFunction(style)) {
  223. style = style();
  224. }
  225. if (arguments.length == 1) {
  226. if (Ext.isString(style)) {
  227. style = Ext.Element.parseStyles(style);
  228. }
  229. body.setStyle(style);
  230. } else {
  231. body.setStyle(style, value);
  232. }
  233. return me;
  234. },
  235. <span id='Ext-panel-AbstractPanel-method-addBodyCls'> /**
  236. </span> * Adds a CSS class to the body element. If not rendered, the class will
  237. * be added when the panel is rendered.
  238. * @param {String} cls The class to add
  239. * @return {Ext.panel.Panel} this
  240. */
  241. addBodyCls: function(cls) {
  242. var me = this,
  243. body = me.rendered ? me.body : me.getProtoBody();
  244. body.addCls(cls);
  245. return me;
  246. },
  247. <span id='Ext-panel-AbstractPanel-method-removeBodyCls'> /**
  248. </span> * Removes a CSS class from the body element.
  249. * @param {String} cls The class to remove
  250. * @return {Ext.panel.Panel} this
  251. */
  252. removeBodyCls: function(cls) {
  253. var me = this,
  254. body = me.rendered ? me.body : me.getProtoBody();
  255. body.removeCls(cls);
  256. return me;
  257. },
  258. // inherit docs
  259. addUIClsToElement: function(cls) {
  260. var me = this,
  261. result = me.callParent(arguments);
  262. me.addBodyCls([Ext.baseCSSPrefix + cls, me.baseCls + '-body-' + cls, me.baseCls + '-body-' + me.ui + '-' + cls]);
  263. return result;
  264. },
  265. // inherit docs
  266. removeUIClsFromElement: function(cls) {
  267. var me = this,
  268. result = me.callParent(arguments);
  269. me.removeBodyCls([Ext.baseCSSPrefix + cls, me.baseCls + '-body-' + cls, me.baseCls + '-body-' + me.ui + '-' + cls]);
  270. return result;
  271. },
  272. // inherit docs
  273. addUIToElement: function() {
  274. var me = this;
  275. me.callParent(arguments);
  276. me.addBodyCls(me.baseCls + '-body-' + me.ui);
  277. },
  278. // inherit docs
  279. removeUIFromElement: function() {
  280. var me = this;
  281. me.callParent(arguments);
  282. me.removeBodyCls(me.baseCls + '-body-' + me.ui);
  283. },
  284. // @private
  285. getTargetEl : function() {
  286. return this.body;
  287. },
  288. getRefItems: function(deep) {
  289. var items = this.callParent(arguments);
  290. return this.getDockingRefItems(deep, items);
  291. },
  292. setupRenderTpl: function (renderTpl) {
  293. this.callParent(arguments);
  294. this.setupDockingRenderTpl(renderTpl);
  295. }
  296. });
  297. </pre>
  298. </body>
  299. </html>