/ext-4.1.0_b3/docs/source/Renderable.html

https://bitbucket.org/srogerf/javascript · HTML · 1086 lines · 933 code · 153 blank · 0 comment · 0 complexity · c3706afd7f1ffa686a9250f604400cb3 MD5 · raw file

  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-util-Renderable'>/**
  19. </span> * Given a component hierarchy of this:
  20. *
  21. * {
  22. * xtype: 'panel',
  23. * id: 'ContainerA',
  24. * layout: 'hbox',
  25. * renderTo: Ext.getBody(),
  26. * items: [
  27. * {
  28. * id: 'ContainerB',
  29. * xtype: 'container',
  30. * items: [
  31. * { id: 'ComponentA' }
  32. * ]
  33. * }
  34. * ]
  35. * }
  36. *
  37. * The rendering of the above proceeds roughly like this:
  38. *
  39. * - ContainerA's initComponent calls #render passing the `renderTo` property as the
  40. * container argument.
  41. * - `render` calls the `getRenderTree` method to get a complete {@link Ext.DomHelper} spec.
  42. * - `getRenderTree` fires the &quot;beforerender&quot; event and calls the #beforeRender
  43. * method. Its result is obtained by calling #getElConfig.
  44. * - The #getElConfig method uses the `renderTpl` and its render data as the content
  45. * of the `autoEl` described element.
  46. * - The result of `getRenderTree` is passed to {@link Ext.DomHelper#append}.
  47. * - The `renderTpl` contains calls to render things like docked items, container items
  48. * and raw markup (such as the `html` or `tpl` config properties). These calls are to
  49. * methods added to the {@link Ext.XTemplate} instance by #setupRenderTpl.
  50. * - The #setupRenderTpl method adds methods such as `renderItems`, `renderContent`, etc.
  51. * to the template. These are directed to &quot;doRenderItems&quot;, &quot;doRenderContent&quot; etc..
  52. * - The #setupRenderTpl calls traverse from components to their {@link Ext.layout.Layout}
  53. * object.
  54. * - When a container is rendered, it also has a `renderTpl`. This is processed when the
  55. * `renderContainer` method is called in the component's `renderTpl`. This call goes to
  56. * Ext.layout.container.Container#doRenderContainer. This method repeats this
  57. * process for all components in the container.
  58. * - After the top-most component's markup is generated and placed in to the DOM, the next
  59. * step is to link elements to their components and finish calling the component methods
  60. * `onRender` and `afterRender` as well as fire the corresponding events.
  61. * - The first step in this is to call #finishRender. This method descends the
  62. * component hierarchy and calls `onRender` and fires the `render` event. These calls
  63. * are delivered top-down to approximate the timing of these calls/events from previous
  64. * versions.
  65. * - During the pass, the component's `el` is set. Likewise, the `renderSelectors` and
  66. * `childEls` are applied to capture references to the component's elements.
  67. * - These calls are also made on the {@link Ext.layout.container.Container} layout to
  68. * capture its elements. Both of these classes use {@link Ext.util.ElementContainer} to
  69. * handle `childEls` processing.
  70. * - Once this is complete, a similar pass is made by calling #finishAfterRender.
  71. * This call also descends the component hierarchy, but this time the calls are made in
  72. * a bottom-up order to `afterRender`.
  73. *
  74. * @private
  75. */
  76. Ext.define('Ext.util.Renderable', {
  77. requires: [
  78. 'Ext.dom.Element'
  79. ],
  80. frameCls: Ext.baseCSSPrefix + 'frame',
  81. frameIdRegex: /[\-]frame\d+[TMB][LCR]$/,
  82. frameElementCls: {
  83. tl: [],
  84. tc: [],
  85. tr: [],
  86. ml: [],
  87. mc: [],
  88. mr: [],
  89. bl: [],
  90. bc: [],
  91. br: []
  92. },
  93. frameElNames: ['TL','TC','TR','ML','MC','MR','BL','BC','BR'],
  94. frameTpl: [
  95. '{%this.renderDockedItems(out,values,0);%}',
  96. '&lt;tpl if=&quot;top&quot;&gt;',
  97. '&lt;tpl if=&quot;left&quot;&gt;&lt;div id=&quot;{fgid}TL&quot; class=&quot;{frameCls}-tl {baseCls}-tl {baseCls}-{ui}-tl&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-tl&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {tl}; padding-left: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/tpl&gt;',
  98. '&lt;tpl if=&quot;right&quot;&gt;&lt;div id=&quot;{fgid}TR&quot; class=&quot;{frameCls}-tr {baseCls}-tr {baseCls}-{ui}-tr&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-tr&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {tr}; padding-right: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/tpl&gt;',
  99. '&lt;div id=&quot;{fgid}TC&quot; class=&quot;{frameCls}-tc {baseCls}-tc {baseCls}-{ui}-tc&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-tc&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {tc}; height: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/div&gt;',
  100. '&lt;tpl if=&quot;right&quot;&gt;&lt;/div&gt;&lt;/tpl&gt;',
  101. '&lt;tpl if=&quot;left&quot;&gt;&lt;/div&gt;&lt;/tpl&gt;',
  102. '&lt;/tpl&gt;',
  103. '&lt;tpl if=&quot;left&quot;&gt;&lt;div id=&quot;{fgid}ML&quot; class=&quot;{frameCls}-ml {baseCls}-ml {baseCls}-{ui}-ml&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-ml&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {ml}; padding-left: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/tpl&gt;',
  104. '&lt;tpl if=&quot;right&quot;&gt;&lt;div id=&quot;{fgid}MR&quot; class=&quot;{frameCls}-mr {baseCls}-mr {baseCls}-{ui}-mr&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-mr&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {mr}; padding-right: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/tpl&gt;',
  105. '&lt;div id=&quot;{fgid}MC&quot; class=&quot;{frameCls}-mc {baseCls}-mc {baseCls}-{ui}-mc&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-mc&lt;/tpl&gt;&lt;/tpl&gt;&quot; role=&quot;presentation&quot;&gt;',
  106. '{%this.applyRenderTpl(out, values)%}',
  107. '&lt;/div&gt;',
  108. '&lt;tpl if=&quot;right&quot;&gt;&lt;/div&gt;&lt;/tpl&gt;',
  109. '&lt;tpl if=&quot;left&quot;&gt;&lt;/div&gt;&lt;/tpl&gt;',
  110. '&lt;tpl if=&quot;bottom&quot;&gt;',
  111. '&lt;tpl if=&quot;left&quot;&gt;&lt;div id=&quot;{fgid}BL&quot; class=&quot;{frameCls}-bl {baseCls}-bl {baseCls}-{ui}-bl&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-bl&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {bl}; padding-left: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/tpl&gt;',
  112. '&lt;tpl if=&quot;right&quot;&gt;&lt;div id=&quot;{fgid}BR&quot; class=&quot;{frameCls}-br {baseCls}-br {baseCls}-{ui}-br&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-br&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {br}; padding-right: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/tpl&gt;',
  113. '&lt;div id=&quot;{fgid}BC&quot; class=&quot;{frameCls}-bc {baseCls}-bc {baseCls}-{ui}-bc&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-bc&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {bc}; height: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/div&gt;',
  114. '&lt;tpl if=&quot;right&quot;&gt;&lt;/div&gt;&lt;/tpl&gt;',
  115. '&lt;tpl if=&quot;left&quot;&gt;&lt;/div&gt;&lt;/tpl&gt;',
  116. '&lt;/tpl&gt;',
  117. '{%this.renderDockedItems(out,values,1);%}'
  118. ],
  119. frameTableTpl: [
  120. '{%this.renderDockedItems(out,values,0);%}',
  121. '&lt;table&gt;&lt;tbody&gt;',
  122. '&lt;tpl if=&quot;top&quot;&gt;',
  123. '&lt;tr&gt;',
  124. '&lt;tpl if=&quot;left&quot;&gt;&lt;td id=&quot;{fgid}TL&quot; class=&quot;{frameCls}-tl {baseCls}-tl {baseCls}-{ui}-tl&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-tl&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {tl}; padding-left:{frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/td&gt;&lt;/tpl&gt;',
  125. '&lt;td id=&quot;{fgid}TC&quot; class=&quot;{frameCls}-tc {baseCls}-tc {baseCls}-{ui}-tc&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-tc&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {tc}; height: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/td&gt;',
  126. '&lt;tpl if=&quot;right&quot;&gt;&lt;td id=&quot;{fgid}TR&quot; class=&quot;{frameCls}-tr {baseCls}-tr {baseCls}-{ui}-tr&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-tr&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {tr}; padding-left: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/td&gt;&lt;/tpl&gt;',
  127. '&lt;/tr&gt;',
  128. '&lt;/tpl&gt;',
  129. '&lt;tr&gt;',
  130. '&lt;tpl if=&quot;left&quot;&gt;&lt;td id=&quot;{fgid}ML&quot; class=&quot;{frameCls}-ml {baseCls}-ml {baseCls}-{ui}-ml&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-ml&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {ml}; padding-left: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/td&gt;&lt;/tpl&gt;',
  131. '&lt;td id=&quot;{fgid}MC&quot; class=&quot;{frameCls}-mc {baseCls}-mc {baseCls}-{ui}-mc&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-mc&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: 0 0;&quot; role=&quot;presentation&quot;&gt;',
  132. '{%this.applyRenderTpl(out, values)%}',
  133. '&lt;/td&gt;',
  134. '&lt;tpl if=&quot;right&quot;&gt;&lt;td id=&quot;{fgid}MR&quot; class=&quot;{frameCls}-mr {baseCls}-mr {baseCls}-{ui}-mr&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-mr&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {mr}; padding-left: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/td&gt;&lt;/tpl&gt;',
  135. '&lt;/tr&gt;',
  136. '&lt;tpl if=&quot;bottom&quot;&gt;',
  137. '&lt;tr&gt;',
  138. '&lt;tpl if=&quot;left&quot;&gt;&lt;td id=&quot;{fgid}BL&quot; class=&quot;{frameCls}-bl {baseCls}-bl {baseCls}-{ui}-bl&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-bl&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {bl}; padding-left: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/td&gt;&lt;/tpl&gt;',
  139. '&lt;td id=&quot;{fgid}BC&quot; class=&quot;{frameCls}-bc {baseCls}-bc {baseCls}-{ui}-bc&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-bc&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {bc}; height: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/td&gt;',
  140. '&lt;tpl if=&quot;right&quot;&gt;&lt;td id=&quot;{fgid}BR&quot; class=&quot;{frameCls}-br {baseCls}-br {baseCls}-{ui}-br&lt;tpl if=&quot;uiCls&quot;&gt;&lt;tpl for=&quot;uiCls&quot;&gt; {parent.baseCls}-{parent.ui}-{.}-br&lt;/tpl&gt;&lt;/tpl&gt;&quot; style=&quot;background-position: {br}; padding-left: {frameWidth}px&quot; role=&quot;presentation&quot;&gt;&lt;/td&gt;&lt;/tpl&gt;',
  141. '&lt;/tr&gt;',
  142. '&lt;/tpl&gt;',
  143. '&lt;/tbody&gt;&lt;/table&gt;',
  144. '{%this.renderDockedItems(out,values,1);%}'
  145. ],
  146. <span id='Ext-util-Renderable-method-afterRender'> /**
  147. </span> * Allows addition of behavior after rendering is complete. At this stage the Component’s Element
  148. * will have been styled according to the configuration, will have had any configured CSS class
  149. * names added, and will be in the configured visibility and the configured enable state.
  150. *
  151. * @template
  152. * @protected
  153. */
  154. afterRender : function() {
  155. var me = this,
  156. data = {},
  157. protoEl = me.protoEl,
  158. target = me.getTargetEl(),
  159. item;
  160. me.finishRenderChildren();
  161. if (me.styleHtmlContent) {
  162. target.addCls(me.styleHtmlCls);
  163. }
  164. protoEl.writeTo(data);
  165. // Here we apply any styles that were set on the protoEl during the rendering phase
  166. // A majority of times this will not happen, but we still need to handle it
  167. item = data.removed;
  168. if (item) {
  169. target.removeCls(item);
  170. }
  171. item = data.cls;
  172. if (item.length) {
  173. target.addCls(item);
  174. }
  175. item = data.style;
  176. if (data.style) {
  177. target.setStyle(item);
  178. }
  179. me.protoEl = null;
  180. // If this is the outermost Container, lay it out as soon as it is rendered.
  181. if (!me.ownerCt) {
  182. me.updateLayout();
  183. }
  184. },
  185. afterFirstLayout : function() {
  186. var me = this,
  187. hasX = Ext.isDefined(me.x),
  188. hasY = Ext.isDefined(me.y),
  189. pos, xy;
  190. // For floaters, calculate x and y if they aren't defined by aligning
  191. // the sized element to the center of either the container or the ownerCt
  192. if (me.floating &amp;&amp; (!hasX || !hasY)) {
  193. if (me.floatParent) {
  194. xy = me.el.getAlignToXY(me.floatParent.getTargetEl(), 'c-c');
  195. pos = me.floatParent.getTargetEl().translatePoints(xy[0], xy[1]);
  196. } else {
  197. xy = me.el.getAlignToXY(me.container, 'c-c');
  198. pos = me.container.translatePoints(xy[0], xy[1]);
  199. }
  200. me.x = hasX ? me.x : pos.left;
  201. me.y = hasY ? me.y : pos.top;
  202. hasX = hasY = true;
  203. }
  204. if (hasX || hasY) {
  205. me.setPosition(me.x, me.y);
  206. }
  207. me.onBoxReady();
  208. if (me.hasListeners.boxready) {
  209. me.fireEvent('boxready', me);
  210. }
  211. },
  212. onBoxReady: Ext.emptyFn,
  213. <span id='Ext-util-Renderable-method-applyRenderSelectors'> /**
  214. </span> * Sets references to elements inside the component. This applies {@link #renderSelectors}
  215. * as well as {@link #childEls}.
  216. * @private
  217. */
  218. applyRenderSelectors: function() {
  219. var me = this,
  220. selectors = me.renderSelectors,
  221. el = me.el,
  222. dom = el.dom,
  223. selector;
  224. me.applyChildEls(el);
  225. // We still support renderSelectors. There are a few places in the framework that
  226. // need them and they are a documented part of the API. In fact, we support mixing
  227. // childEls and renderSelectors (no reason not to).
  228. if (selectors) {
  229. for (selector in selectors) {
  230. if (selectors.hasOwnProperty(selector) &amp;&amp; selectors[selector]) {
  231. me[selector] = Ext.get(Ext.DomQuery.selectNode(selectors[selector], dom));
  232. }
  233. }
  234. }
  235. },
  236. beforeRender: function () {
  237. var me = this,
  238. layout = me.getComponentLayout();
  239. if (!layout.initialized) {
  240. layout.initLayout();
  241. }
  242. me.setUI(me.ui);
  243. if (me.disabled) {
  244. // pass silent so the event doesn't fire the first time.
  245. me.disable(true);
  246. }
  247. },
  248. <span id='Ext-util-Renderable-method-doApplyRenderTpl'> /**
  249. </span> * @private
  250. * Called from the selected frame generation template to insert this Component's inner structure inside the framing structure.
  251. *
  252. * When framing is used, a selected frame generation template is used as the primary template of the #getElConfig instead
  253. * of the configured {@link #renderTpl}. The {@link #renderTpl} is invoked by this method which is injected into the framing template.
  254. */
  255. doApplyRenderTpl: function(out, values) {
  256. // Careful! This method is bolted on to the frameTpl so all we get for context is
  257. // the renderData! The &quot;this&quot; pointer is the frameTpl instance!
  258. var me = values.$comp,
  259. tpl;
  260. // Don't do this if the component is already rendered:
  261. if (!me.rendered) {
  262. tpl = me.initRenderTpl();
  263. tpl.applyOut(values.renderData, out);
  264. }
  265. },
  266. <span id='Ext-util-Renderable-method-doAutoRender'> /**
  267. </span> * Handles autoRender.
  268. * Floating Components may have an ownerCt. If they are asking to be constrained, constrain them within that
  269. * ownerCt, and have their z-index managed locally. Floating Components are always rendered to document.body
  270. */
  271. doAutoRender: function() {
  272. var me = this;
  273. if (!me.rendered) {
  274. if (me.floating) {
  275. me.render(document.body);
  276. } else {
  277. me.render(Ext.isBoolean(me.autoRender) ? Ext.getBody() : me.autoRender);
  278. }
  279. }
  280. },
  281. doRenderContent: function (out, renderData) {
  282. // Careful! This method is bolted on to the renderTpl so all we get for context is
  283. // the renderData! The &quot;this&quot; pointer is the renderTpl instance!
  284. var me = renderData.$comp;
  285. if (me.html) {
  286. Ext.DomHelper.generateMarkup(me.html, out);
  287. delete me.html;
  288. }
  289. if (me.tpl) {
  290. // Make sure this.tpl is an instantiated XTemplate
  291. if (!me.tpl.isTemplate) {
  292. me.tpl = new Ext.XTemplate(me.tpl);
  293. }
  294. if (me.data) {
  295. //me.tpl[me.tplWriteMode](target, me.data);
  296. me.tpl.applyOut(me.data, out);
  297. delete me.data;
  298. }
  299. }
  300. },
  301. doRenderFramingDockedItems: function (out, renderData, after) {
  302. // Careful! This method is bolted on to the frameTpl so all we get for context is
  303. // the renderData! The &quot;this&quot; pointer is the frameTpl instance!
  304. var me = renderData.$comp;
  305. // Most components don't have dockedItems, so check for doRenderDockedItems on the
  306. // component (also, don't do this if the component is already rendered):
  307. if (!me.rendered &amp;&amp; me.doRenderDockedItems) {
  308. // The &quot;renderData&quot; property is placed in scope for the renderTpl, but we don't
  309. // want to render docked items at that level in addition to the framing level:
  310. renderData.renderData.$skipDockedItems = true;
  311. // doRenderDockedItems requires the $comp property on renderData, but this is
  312. // set on the frameTpl's renderData as well:
  313. me.doRenderDockedItems.call(this, out, renderData, after);
  314. }
  315. },
  316. <span id='Ext-util-Renderable-method-finishRender'> /**
  317. </span> * This method visits the rendered component tree in a &quot;top-down&quot; order. That is, this
  318. * code runs on a parent component before running on a child. This method calls the
  319. * {@link #onRender} method of each component.
  320. * @param {Number} containerIdx The index into the Container items of this Component.
  321. *
  322. * @private
  323. */
  324. finishRender: function(containerIdx) {
  325. var me = this,
  326. tpl, data, contentEl, el, pre, hide, target;
  327. // We are typically called w/me.el==null as a child of some ownerCt that is being
  328. // rendered. We are also called by render for a normal component (w/o a configured
  329. // me.el). In this case, render sets me.el and me.rendering (indirectly). Lastly
  330. // we are also called on a component (like a Viewport) that has a configured me.el
  331. // (body for a Viewport) when render is called. In this case, it is not flagged as
  332. // &quot;me.rendering&quot; yet becasue it does not produce a renderTree. We use this to know
  333. // not to regen the renderTpl.
  334. if (!me.el || me.$pid) {
  335. if (me.container) {
  336. el = me.container.getById(me.id, true);
  337. } else {
  338. el = Ext.getDom(me.id);
  339. }
  340. if (!me.el) {
  341. // Typical case: we produced the el during render
  342. me.wrapPrimaryEl(el);
  343. } else {
  344. // We were configured with an el and created a proxy, so now we can swap
  345. // the proxy for me.el:
  346. delete me.$pid;
  347. if (!me.el.dom) {
  348. // make sure me.el is an Element
  349. me.wrapPrimaryEl(me.el);
  350. }
  351. el.parentNode.insertBefore(me.el.dom, el);
  352. Ext.removeNode(el); // remove placeholder el
  353. // TODO - what about class/style?
  354. }
  355. } else if (!me.rendering) {
  356. // We were configured with an el and then told to render (e.g., Viewport). We
  357. // need to generate the proper DOM. Insert first because the layout system
  358. // insists that child Component elements indices match the Component indices.
  359. tpl = me.initRenderTpl();
  360. if (tpl) {
  361. data = me.initRenderData();
  362. tpl.insertFirst(me.getTargetEl(), data);
  363. }
  364. }
  365. // else we are rendering
  366. if (!me.container) {
  367. // top-level rendered components will already have me.container set up
  368. me.container = Ext.get(me.el.dom.parentNode);
  369. }
  370. if (me.ctCls) {
  371. me.container.addCls(me.ctCls);
  372. }
  373. // Sets the rendered flag and clears the redering flag
  374. me.onRender(me.container, containerIdx);
  375. // Initialize with correct overflow attributes
  376. target = me.getTargetEl();
  377. target.setStyle(me.getOverflowStyle());
  378. // Tell the encapsulating element to hide itself in the way the Component is configured to hide
  379. // This means DISPLAY, VISIBILITY or OFFSETS.
  380. me.el.setVisibilityMode(Ext.Element[me.hideMode.toUpperCase()]);
  381. if (me.overCls) {
  382. me.el.hover(me.addOverCls, me.removeOverCls, me);
  383. }
  384. if (me.hasListeners.render) {
  385. me.fireEvent('render', me);
  386. }
  387. if (me.contentEl) {
  388. pre = Ext.baseCSSPrefix;
  389. hide = pre + 'hide-';
  390. contentEl = Ext.get(me.contentEl);
  391. contentEl.removeCls([pre+'hidden', hide+'display', hide+'offsets', hide+'nosize']);
  392. target.appendChild(contentEl.dom);
  393. }
  394. me.afterRender(); // this can cause a layout
  395. if (me.hasListeners.afterrender) {
  396. me.fireEvent('afterrender', me);
  397. }
  398. me.initEvents();
  399. if (me.hidden) {
  400. // Hiding during the render process should not perform any ancillary
  401. // actions that the full hide process does; It is not hiding, it begins in a hidden state.'
  402. // So just make the element hidden according to the configured hideMode
  403. me.el.hide();
  404. }
  405. },
  406. finishRenderChildren: function () {
  407. var layout = this.getComponentLayout();
  408. layout.finishRender();
  409. },
  410. getElConfig : function() {
  411. var me = this,
  412. autoEl = me.autoEl,
  413. frameInfo = me.getFrameInfo(),
  414. config = {
  415. tag: 'div',
  416. id: me.id,
  417. tpl: frameInfo ? me.initFramingTpl(frameInfo.table) : me.initRenderTpl()
  418. };
  419. me.initStyles(me.protoEl);
  420. me.protoEl.writeTo(config);
  421. me.protoEl.flush();
  422. if (Ext.isString(autoEl)) {
  423. config.tag = autoEl;
  424. } else {
  425. Ext.apply(config, autoEl); // harmless if !autoEl
  426. }
  427. if (config.tpl) {
  428. // Use the framingTpl as the main content creating template. It will call out to this.applyRenderTpl(out, values)
  429. if (frameInfo) {
  430. var i,
  431. frameElNames = me.frameElNames,
  432. len = frameElNames.length,
  433. suffix,
  434. frameGenId = me.id + '-frame1';
  435. me.frameGenId = 1;
  436. config.tplData = Ext.apply({}, {
  437. $comp: me,
  438. fgid: frameGenId,
  439. ui: me.ui,
  440. uiCls: me.uiCls,
  441. frameCls: me.frameCls,
  442. baseCls: me.baseCls,
  443. frameWidth: frameInfo.maxWidth,
  444. top: !!frameInfo.top,
  445. left: !!frameInfo.left,
  446. right: !!frameInfo.right,
  447. bottom: !!frameInfo.bottom,
  448. renderData: me.initRenderData()
  449. }, me.getFramePositions(frameInfo));
  450. // Add the childEls for each of the frame elements
  451. for (i = 0; i &lt; len; i++) {
  452. suffix = frameElNames[i];
  453. me.addChildEls({ name: 'frame' + suffix, id: frameGenId + suffix });
  454. }
  455. // Panel must have a frameBody
  456. me.addChildEls({
  457. name: 'frameBody',
  458. id: frameGenId + 'MC'
  459. });
  460. } else {
  461. config.tplData = me.initRenderData();
  462. }
  463. }
  464. return config;
  465. },
  466. // Create the framingTpl from the string.
  467. // Poke in a reference to applyRenderTpl(frameInfo, out)
  468. initFramingTpl: function(table) {
  469. var tpl = table ? this.getTpl('frameTableTpl') : this.getTpl('frameTpl');
  470. if (tpl &amp;&amp; !tpl.applyRenderTpl) {
  471. this.setupFramingTpl(tpl);
  472. }
  473. return tpl;
  474. },
  475. <span id='Ext-util-Renderable-method-setupFramingTpl'> /**
  476. </span> * @private
  477. * Inject a reference to the function which applies the render template into the framing template. The framing template
  478. * wraps the content.
  479. */
  480. setupFramingTpl: function(frameTpl) {
  481. frameTpl.applyRenderTpl = this.doApplyRenderTpl;
  482. frameTpl.renderDockedItems = this.doRenderFramingDockedItems;
  483. },
  484. <span id='Ext-util-Renderable-method-getInsertPosition'> /**
  485. </span> * This function takes the position argument passed to onRender and returns a
  486. * DOM element that you can use in the insertBefore.
  487. * @param {String/Number/Ext.dom.Element/HTMLElement} position Index, element id or element you want
  488. * to put this component before.
  489. * @return {HTMLElement} DOM element that you can use in the insertBefore
  490. */
  491. getInsertPosition: function(position) {
  492. // Convert the position to an element to insert before
  493. if (position !== undefined) {
  494. if (Ext.isNumber(position)) {
  495. position = this.container.dom.childNodes[position];
  496. }
  497. else {
  498. position = Ext.getDom(position);
  499. }
  500. }
  501. return position;
  502. },
  503. getRenderTree: function() {
  504. var me = this;
  505. me.beforeRender();
  506. if (!me.hasListeners.beforerender || me.fireEvent('beforerender', me) !== false) {
  507. // Flag to let the layout's finishRenderItems and afterFinishRenderItems
  508. // know which items to process
  509. me.rendering = true;
  510. if (me.el) {
  511. // Since we are producing a render tree, we produce a &quot;proxy el&quot; that will
  512. // sit in the rendered DOM precisely where me.el belongs. We replace the
  513. // proxy el in the finishRender phase.
  514. return {
  515. tag: 'div',
  516. id: (me.$pid = Ext.id())
  517. };
  518. }
  519. return me.getElConfig();
  520. }
  521. return null;
  522. },
  523. initContainer: function(container) {
  524. var me = this;
  525. // If you render a component specifying the el, we get the container
  526. // of the el, and make sure we dont move the el around in the dom
  527. // during the render
  528. if (!container &amp;&amp; me.el) {
  529. container = me.el.dom.parentNode;
  530. me.allowDomMove = false;
  531. }
  532. me.container = container.dom ? container : Ext.get(container);
  533. return me.container;
  534. },
  535. <span id='Ext-util-Renderable-method-initRenderData'> /**
  536. </span> * Initialized the renderData to be used when rendering the renderTpl.
  537. * @return {Object} Object with keys and values that are going to be applied to the renderTpl
  538. * @private
  539. */
  540. initRenderData: function() {
  541. var me = this;
  542. return Ext.apply({
  543. $comp: me,
  544. id: me.id,
  545. ui: me.ui,
  546. uiCls: me.uiCls,
  547. baseCls: me.baseCls,
  548. componentCls: me.componentCls,
  549. frame: me.frame
  550. }, me.renderData);
  551. },
  552. <span id='Ext-util-Renderable-method-initRenderTpl'> /**
  553. </span> * Initializes the renderTpl.
  554. * @return {Ext.XTemplate} The renderTpl XTemplate instance.
  555. * @private
  556. */
  557. initRenderTpl: function() {
  558. var tpl = this.getTpl('renderTpl');
  559. if (tpl &amp;&amp; !tpl.renderContent) {
  560. this.setupRenderTpl(tpl);
  561. }
  562. return tpl;
  563. },
  564. <span id='Ext-util-Renderable-method-onRender'> /**
  565. </span> * Template method called when this Component's DOM structure is created.
  566. *
  567. * At this point, this Component's (and all descendants') DOM structure *exists* but it has not
  568. * been layed out (positioned and sized).
  569. *
  570. * Subclasses which override this to gain access to the structure at render time should
  571. * call the parent class's method before attempting to access any child elements of the Component.
  572. *
  573. * @param {Ext.core.Element} parentNode The parent Element in which this Component's encapsulating element is contained.
  574. * @param {Number} containerIdx The index within the parent Container's child collection of this Component.
  575. *
  576. * @template
  577. * @protected
  578. */
  579. onRender: function(parentNode, containerIdx) {
  580. var me = this,
  581. x = me.x,
  582. y = me.y,
  583. lastBox, width, height,
  584. el = me.el;
  585. // After the container property has been collected, we can wrap the Component in a reset wraper if necessary
  586. if (Ext.scopeResetCSS &amp;&amp; !me.ownerCt) {
  587. // If this component's el is the body element, we add the reset class to the html tag
  588. if (el.dom == Ext.getBody().dom) {
  589. el.parent().addCls(Ext.resetCls);
  590. }
  591. else {
  592. // Else we wrap this element in an element that adds the reset class.
  593. me.resetEl = el.wrap({
  594. cls: Ext.resetCls
  595. });
  596. }
  597. }
  598. me.applyRenderSelectors();
  599. // Flag set on getRenderTree to flag to the layout's postprocessing routine that
  600. // the Component is in the process of being rendered and needs postprocessing.
  601. delete me.rendering;
  602. me.rendered = true;
  603. // We need to remember these to avoid writing them during the initial layout:
  604. lastBox = null;
  605. if (x !== undefined) {
  606. lastBox = lastBox || {};
  607. lastBox.x = x;
  608. }
  609. if (y !== undefined) {
  610. lastBox = lastBox || {};
  611. lastBox.y = y;
  612. }
  613. // Framed components need their width/height to apply to the frame, which is
  614. // best handled in layout at present.
  615. // If we're using the content box model, we also cannot assign initial sizes since we do not know the border widths to subtract
  616. if (!me.getFrameInfo() &amp;&amp; Ext.isBorderBox) {
  617. width = me.width;
  618. height = me.height;
  619. if (typeof width == 'number') {
  620. lastBox = lastBox || {};
  621. lastBox.width = width;
  622. }
  623. if (typeof height == 'number') {
  624. lastBox = lastBox || {};
  625. lastBox.height = height;
  626. }
  627. }
  628. me.lastBox = me.el.lastBox = lastBox;
  629. },
  630. render: function(container, position) {
  631. var me = this,
  632. el = me.el &amp;&amp; (me.el = Ext.get(me.el)), // ensure me.el is wrapped
  633. tree,
  634. nextSibling;
  635. Ext.suspendLayouts();
  636. container = me.initContainer(container);
  637. nextSibling = me.getInsertPosition(position);
  638. if (!el) {
  639. tree = me.getRenderTree();
  640. if (nextSibling) {
  641. el = Ext.DomHelper.insertBefore(nextSibling, tree);
  642. } else {
  643. el = Ext.DomHelper.append(container, tree);
  644. }
  645. me.wrapPrimaryEl(el);
  646. } else {
  647. // Set configured styles on pre-rendered Component's element
  648. me.initStyles(el);
  649. if (me.allowDomMove !== false) {
  650. //debugger; // TODO
  651. if (nextSibling) {
  652. container.dom.insertBefore(el.dom, nextSibling);
  653. } else {
  654. container.dom.appendChild(el.dom);
  655. }
  656. }
  657. }
  658. me.finishRender(position);
  659. Ext.resumeLayouts(!container.isDetachedBody);
  660. },
  661. <span id='Ext-util-Renderable-method-ensureAttachedToBody'> /**
  662. </span> * Ensures that this component is attached to `document.body`. If the component was
  663. * rendered to {@link Ext#getDetachedBody}, then it will be appended to `document.body`.
  664. * Any configured position is also restored.
  665. * @param {Boolean} [runLayout=false] True to run the component's layout.
  666. */
  667. ensureAttachedToBody: function (runLayout) {
  668. var comp = this,
  669. body;
  670. while (comp.ownerCt) {
  671. comp = comp.ownerCt;
  672. }
  673. if (comp.container.isDetachedBody) {
  674. comp.container = body = Ext.getBody();
  675. body.appendChild(comp.el.dom);
  676. if (runLayout) {
  677. comp.updateLayout();
  678. }
  679. if (typeof comp.x == 'number' || typeof comp.y == 'number') {
  680. comp.setPosition(comp.x, comp.y);
  681. }
  682. }
  683. },
  684. setupRenderTpl: function (renderTpl) {
  685. renderTpl.renderBody = renderTpl.renderContent = this.doRenderContent;
  686. },
  687. wrapPrimaryEl: function (dom) {
  688. this.el = Ext.get(dom, true);
  689. },
  690. <span id='Ext-util-Renderable-method-initFrame'> /**
  691. </span> * @private
  692. */
  693. initFrame : function() {
  694. if (Ext.supports.CSS3BorderRadius) {
  695. return;
  696. }
  697. var me = this,
  698. frameInfo = me.getFrameInfo(),
  699. frameWidth, frameTpl, frameGenId,
  700. i,
  701. frameElNames = me.frameElNames,
  702. len = frameElNames.length,
  703. suffix;
  704. if (frameInfo) {
  705. frameWidth = frameInfo.maxWidth;
  706. frameTpl = me.getFrameTpl(frameInfo.table);
  707. // since we render id's into the markup and id's NEED to be unique, we have a
  708. // simple strategy for numbering their generations.
  709. me.frameGenId = frameGenId = (me.frameGenId || 0) + 1;
  710. frameGenId = me.id + '-frame' + frameGenId;
  711. // Here we render the frameTpl to this component. This inserts the 9point div or the table framing.
  712. frameTpl.insertFirst(me.el, Ext.apply({
  713. $comp: me,
  714. fgid: frameGenId,
  715. ui: me.ui,
  716. uiCls: me.uiCls,
  717. frameCls: me.frameCls,
  718. baseCls: me.baseCls,
  719. frameWidth: frameWidth,
  720. top: !!frameInfo.top,
  721. left: !!frameInfo.left,
  722. right: !!frameInfo.right,
  723. bottom: !!frameInfo.bottom
  724. }, me.getFramePositions(frameInfo)));
  725. // The frameBody is returned in getTargetEl, so that layouts render items to the correct target.
  726. me.frameBody = me.el.down('.' + me.frameCls + '-mc');
  727. // Clean out the childEls for the old frame elements (the majority of the els)
  728. me.removeChildEls(function (c) {
  729. return c.id &amp;&amp; me.frameIdRegex.test(c.id);
  730. });
  731. // Grab references to the childEls for each of the new frame elements
  732. for (i = 0; i &lt; len; i++) {
  733. suffix = frameElNames[i];
  734. me['frame' + suffix] = me.el.getById(frameGenId + suffix);
  735. }
  736. }
  737. },
  738. updateFrame: function() {
  739. if (Ext.supports.CSS3BorderRadius) {
  740. return;
  741. }
  742. var me = this,
  743. wasTable = this.frameSize &amp;&amp; this.frameSize.table,
  744. oldFrameTL = this.frameTL,
  745. oldFrameBL = this.frameBL,
  746. oldFrameML = this.frameML,
  747. oldFrameMC = this.frameMC,
  748. newMCClassName;
  749. this.initFrame();
  750. if (oldFrameMC) {
  751. if (me.frame) {
  752. // Store the class names set on the new MC
  753. newMCClassName = this.frameMC.dom.className;
  754. // Framing elements have been selected in initFrame, no need to run applyRenderSelectors
  755. // Replace the new mc with the old mc
  756. oldFrameMC.insertAfter(this.frameMC);
  757. this.frameMC.remove();
  758. // Restore the reference to the old frame mc as the framebody
  759. this.frameBody = this.frameMC = oldFrameMC;
  760. // Apply the new mc classes to the old mc element
  761. oldFrameMC.dom.className = newMCClassName;
  762. // Remove the old framing
  763. if (wasTable) {
  764. me.el.query('&gt; table')[1].remove();
  765. }
  766. else {
  767. if (oldFrameTL) {
  768. oldFrameTL.remove();
  769. }
  770. if (oldFrameBL) {
  771. oldFrameBL.remove();
  772. }
  773. if (oldFrameML) {
  774. oldFrameML.remove();
  775. }
  776. }
  777. }
  778. else {
  779. // We were framed but not anymore. Move all content from the old frame to the body
  780. }
  781. }
  782. else if (me.frame) {
  783. this.applyRenderSelectors();
  784. }
  785. },
  786. <span id='Ext-util-Renderable-method-getFrameInfo'> /**
  787. </span> * @private
  788. * On render, reads an encoded style attribute, &quot;background-position&quot; from the style of this Component's element.
  789. * This information is memoized based upon the CSS class name of this Component's element.
  790. * Because child Components are rendered as textual HTML as part of the topmost Container, a dummy div is inserted
  791. * into the document to receive the document element's CSS class name, and therefore style attributes.
  792. */
  793. getFrameInfo: function() {
  794. // If native framing can be used, or this Component is not configured (or written) to be framed,
  795. // then do not attempt to read CSS framing info.
  796. if (Ext.supports.CSS3BorderRadius) {
  797. return false;
  798. }
  799. var me = this,
  800. frameInfoCache = me.frameInfoCache,
  801. el = me.el || me.protoEl,
  802. cls = el.dom ? el.dom.className : el.classList.join(' '),
  803. frameInfo = frameInfoCache[cls],
  804. styleEl, left, top, info;
  805. if (frameInfo == null) {
  806. // Get the singleton frame style proxy with our el class name stamped into it.
  807. styleEl = Ext.fly(me.getStyleProxy(cls), 'frame-style-el');
  808. left = styleEl.getStyle('background-position-x');
  809. top = styleEl.getStyle('background-position-y');
  810. // Some browsers don't support background-position-x and y, so for those
  811. // browsers let's split background-position into two parts.
  812. if (!left &amp;&amp; !top) {
  813. info = styleEl.getStyle('background-position').split(' ');
  814. left = info[0];
  815. top = info[1];
  816. }
  817. frameInfo = me.calculateFrame(left, top);
  818. if (frameInfo) {
  819. // Just to be sure we set the background image of the el to none.
  820. el.setStyle('background-image', 'none');
  821. }
  822. //&lt;debug error&gt;
  823. // This happens when you set frame: true explicitly without using the x-frame mixin in sass.
  824. // This way IE can't figure out what sizes to use and thus framing can't work.
  825. if (me.frame === true &amp;&amp; !frameInfo) {
  826. Ext.log.error('You have set frame: true explicity on this component (' + me.getXType() + ') and it ' +
  827. 'does not have any framing defined in the CSS template. In this case IE cannot figure out ' +
  828. 'what sizes to use and thus framing on this component will be disabled.');
  829. }
  830. //&lt;/debug&gt;
  831. frameInfoCache[cls] = frameInfo;
  832. }
  833. me.frame = !!frameInfo;
  834. me.frameSize = frameInfo;
  835. return frameInfo;
  836. },
  837. calculateFrame: function(left, top){
  838. // We actually pass a string in the form of '[type][tl][tr]px [direction][br][bl]px' as
  839. // the background position of this.el from the CSS to indicate to IE that this component needs
  840. // framing. We parse it here.
  841. if (!(parseInt(left, 10) &gt;= 1000000 &amp;&amp; parseInt(top, 10) &gt;= 1000000)) {
  842. return false;
  843. }
  844. var max = Math.max,
  845. tl = parseInt(left.substr(3, 2), 10),
  846. tr = parseInt(left.substr(5, 2), 10),
  847. br = parseInt(top.substr(3, 2), 10),
  848. bl = parseInt(top.substr(5, 2), 10),
  849. frameInfo = {
  850. // Table markup starts with 110, div markup with 100.
  851. table: left.substr(0, 3) == '110',
  852. // Determine if we are dealing with a horizontal or vertical component
  853. vertical: top.substr(0, 3) == '110',
  854. // Get and parse the different border radius sizes
  855. top: max(tl, tr),
  856. right: max(tr, br),
  857. bottom: max(bl, br),
  858. left: max(tl, bl)
  859. };
  860. frameInfo.maxWidth = max(frameInfo.top, frameInfo.right, frameInfo.bottom, frameInfo.left);
  861. frameInfo.width = frameInfo.left + frameInfo.right;
  862. frameInfo.height = frameInfo.top + frameInfo.bottom;
  863. return frameInfo;
  864. },
  865. <span id='Ext-util-Renderable-method-getStyleProxy'> /**
  866. </span> * @private
  867. * Returns an offscreen div with the same class name as the element this is being rendered.
  868. * This is because child item rendering takes place in a detached div which, being ot part of the document, has no styling.
  869. */
  870. getStyleProxy: function(cls) {
  871. var result = this.styleProxyEl || (Ext.AbstractComponent.prototype.styleProxyEl = Ext.getBody().createChild({
  872. style: {
  873. position: 'absolute',
  874. top: '-10000px'
  875. }
  876. }, null, true));
  877. result.className = cls;
  878. return result;
  879. },
  880. getFramePositions: function(frameInfo) {
  881. var me = this,
  882. frameWidth = frameInfo.maxWidth,
  883. dock = me.dock,
  884. positions, tc, bc, ml, mr;
  885. if (frameInfo.vertical) {
  886. tc = '0 -' + (frameWidth * 0) + 'px';
  887. bc = '0 -' + (frameWidth * 1) + 'px';
  888. if (dock &amp;&amp; dock == &quot;right&quot;) {
  889. tc = 'right -' + (frameWidth * 0) + 'px';
  890. bc = 'right -' + (frameWidth * 1) + 'px';
  891. }
  892. positions = {
  893. tl: '0 -' + (frameWidth * 0) + 'px',
  894. tr: '0 -' + (frameWidth * 1) + 'px',
  895. bl: '0 -' + (frameWidth * 2) + 'px',
  896. br: '0 -' + (frameWidth * 3) + 'px',
  897. ml: '-' + (frameWidth * 1) + 'px 0',
  898. mr: 'right 0',
  899. tc: tc,
  900. bc: bc
  901. };
  902. } else {
  903. ml = '-' + (frameWidth * 0) + 'px 0';
  904. mr = 'right 0';
  905. if (dock &amp;&amp; dock == &quot;bottom&quot;) {
  906. ml = 'left bottom';
  907. mr = 'right bottom';
  908. }
  909. positions = {
  910. tl: '0 -' + (frameWidth * 2) + 'px',
  911. tr: 'right -' + (frameWidth * 3) + 'px',
  912. bl: '0 -' + (frameWidth * 4) + 'px',
  913. br: 'right -' + (frameWidth * 5) + 'px',
  914. ml: ml,
  915. mr: mr,
  916. tc: '0 -' + (frameWidth * 0) + 'px',
  917. bc: '0 -' + (frameWidth * 1) + 'px'
  918. };
  919. }
  920. return positions;
  921. },
  922. <span id='Ext-util-Renderable-method-getFrameTpl'> /**
  923. </span> * @private
  924. */
  925. getFrameTpl : function(table) {
  926. return this.getTpl(table ? 'frameTableTpl' : 'frameTpl');
  927. },
  928. // Cache the frame information object so as not to cause style recalculations
  929. frameInfoCache: {}
  930. });
  931. </pre>
  932. </body>
  933. </html>