/ext-4.0.7/docs/source/Component.html

https://bitbucket.org/srogerf/javascript · HTML · 1173 lines · 1050 code · 123 blank · 0 comment · 0 complexity · ff20bb1f760be3fab4908d3c6262a1a6 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-Component'>/**
  19. </span> * Base class for all Ext components. All subclasses of Component may participate in the automated Ext component
  20. * lifecycle of creation, rendering and destruction which is provided by the {@link Ext.container.Container Container}
  21. * class. Components may be added to a Container through the {@link Ext.container.Container#items items} config option
  22. * at the time the Container is created, or they may be added dynamically via the
  23. * {@link Ext.container.Container#add add} method.
  24. *
  25. * The Component base class has built-in support for basic hide/show and enable/disable and size control behavior.
  26. *
  27. * All Components are registered with the {@link Ext.ComponentManager} on construction so that they can be referenced at
  28. * any time via {@link Ext#getCmp Ext.getCmp}, passing the {@link #id}.
  29. *
  30. * All user-developed visual widgets that are required to participate in automated lifecycle and size management should
  31. * subclass Component.
  32. *
  33. * See the [Creating new UI controls][1] tutorial for details on how and to either extend or augment ExtJs base classes
  34. * to create custom Components.
  35. *
  36. * Every component has a specific xtype, which is its Ext-specific type name, along with methods for checking the xtype
  37. * like {@link #getXType} and {@link #isXType}. See the [Component Guide][2] for more information on xtypes and the
  38. * Component hierarchy.
  39. *
  40. * This is the list of all valid xtypes:
  41. *
  42. * xtype Class
  43. * ------------- ------------------
  44. * button {@link Ext.button.Button}
  45. * buttongroup {@link Ext.container.ButtonGroup}
  46. * colorpalette {@link Ext.picker.Color}
  47. * component {@link Ext.Component}
  48. * container {@link Ext.container.Container}
  49. * cycle {@link Ext.button.Cycle}
  50. * dataview {@link Ext.view.View}
  51. * datepicker {@link Ext.picker.Date}
  52. * editor {@link Ext.Editor}
  53. * editorgrid {@link Ext.grid.plugin.Editing}
  54. * grid {@link Ext.grid.Panel}
  55. * multislider {@link Ext.slider.Multi}
  56. * panel {@link Ext.panel.Panel}
  57. * progressbar {@link Ext.ProgressBar}
  58. * slider {@link Ext.slider.Single}
  59. * splitbutton {@link Ext.button.Split}
  60. * tabpanel {@link Ext.tab.Panel}
  61. * treepanel {@link Ext.tree.Panel}
  62. * viewport {@link Ext.container.Viewport}
  63. * window {@link Ext.window.Window}
  64. *
  65. * Toolbar components
  66. * ---------------------------------------
  67. * pagingtoolbar {@link Ext.toolbar.Paging}
  68. * toolbar {@link Ext.toolbar.Toolbar}
  69. * tbfill {@link Ext.toolbar.Fill}
  70. * tbitem {@link Ext.toolbar.Item}
  71. * tbseparator {@link Ext.toolbar.Separator}
  72. * tbspacer {@link Ext.toolbar.Spacer}
  73. * tbtext {@link Ext.toolbar.TextItem}
  74. *
  75. * Menu components
  76. * ---------------------------------------
  77. * menu {@link Ext.menu.Menu}
  78. * menucheckitem {@link Ext.menu.CheckItem}
  79. * menuitem {@link Ext.menu.Item}
  80. * menuseparator {@link Ext.menu.Separator}
  81. * menutextitem {@link Ext.menu.Item}
  82. *
  83. * Form components
  84. * ---------------------------------------
  85. * form {@link Ext.form.Panel}
  86. * checkbox {@link Ext.form.field.Checkbox}
  87. * combo {@link Ext.form.field.ComboBox}
  88. * datefield {@link Ext.form.field.Date}
  89. * displayfield {@link Ext.form.field.Display}
  90. * field {@link Ext.form.field.Base}
  91. * fieldset {@link Ext.form.FieldSet}
  92. * hidden {@link Ext.form.field.Hidden}
  93. * htmleditor {@link Ext.form.field.HtmlEditor}
  94. * label {@link Ext.form.Label}
  95. * numberfield {@link Ext.form.field.Number}
  96. * radio {@link Ext.form.field.Radio}
  97. * radiogroup {@link Ext.form.RadioGroup}
  98. * textarea {@link Ext.form.field.TextArea}
  99. * textfield {@link Ext.form.field.Text}
  100. * timefield {@link Ext.form.field.Time}
  101. * trigger {@link Ext.form.field.Trigger}
  102. *
  103. * Chart components
  104. * ---------------------------------------
  105. * chart {@link Ext.chart.Chart}
  106. * barchart {@link Ext.chart.series.Bar}
  107. * columnchart {@link Ext.chart.series.Column}
  108. * linechart {@link Ext.chart.series.Line}
  109. * piechart {@link Ext.chart.series.Pie}
  110. *
  111. * It should not usually be necessary to instantiate a Component because there are provided subclasses which implement
  112. * specialized Component use cases which cover most application needs. However it is possible to instantiate a base
  113. * Component, and it will be renderable, or will particpate in layouts as the child item of a Container:
  114. *
  115. * @example
  116. * Ext.create('Ext.Component', {
  117. * html: 'Hello world!',
  118. * width: 300,
  119. * height: 200,
  120. * padding: 20,
  121. * style: {
  122. * color: '#FFFFFF',
  123. * backgroundColor:'#000000'
  124. * },
  125. * renderTo: Ext.getBody()
  126. * });
  127. *
  128. * The Component above creates its encapsulating `div` upon render, and use the configured HTML as content. More complex
  129. * internal structure may be created using the {@link #renderTpl} configuration, although to display database-derived
  130. * mass data, it is recommended that an ExtJS data-backed Component such as a {@link Ext.view.View View}, or {@link
  131. * Ext.grid.Panel GridPanel}, or {@link Ext.tree.Panel TreePanel} be used.
  132. *
  133. * [1]: http://sencha.com/learn/Tutorial:Creating_new_UI_controls
  134. */
  135. Ext.define('Ext.Component', {
  136. /* Begin Definitions */
  137. alias: ['widget.component', 'widget.box'],
  138. extend: 'Ext.AbstractComponent',
  139. requires: [
  140. 'Ext.util.DelayedTask'
  141. ],
  142. uses: [
  143. 'Ext.Layer',
  144. 'Ext.resizer.Resizer',
  145. 'Ext.util.ComponentDragger'
  146. ],
  147. mixins: {
  148. floating: 'Ext.util.Floating'
  149. },
  150. statics: {
  151. // Collapse/expand directions
  152. DIRECTION_TOP: 'top',
  153. DIRECTION_RIGHT: 'right',
  154. DIRECTION_BOTTOM: 'bottom',
  155. DIRECTION_LEFT: 'left',
  156. VERTICAL_DIRECTION_Re: /^(?:top|bottom)$/,
  157. // RegExp whih specifies characters in an xtype which must be translated to '-' when generating auto IDs.
  158. // This includes dot, comma and whitespace
  159. INVALID_ID_CHARS_Re: /[\.,\s]/g
  160. },
  161. /* End Definitions */
  162. <span id='Ext-Component-cfg-resizable'> /**
  163. </span> * @cfg {Boolean/Object} resizable
  164. * Specify as `true` to apply a {@link Ext.resizer.Resizer Resizer} to this Component after rendering.
  165. *
  166. * May also be specified as a config object to be passed to the constructor of {@link Ext.resizer.Resizer Resizer}
  167. * to override any defaults. By default the Component passes its minimum and maximum size, and uses
  168. * `{@link Ext.resizer.Resizer#dynamic}: false`
  169. */
  170. <span id='Ext-Component-cfg-resizeHandles'> /**
  171. </span> * @cfg {String} resizeHandles
  172. * A valid {@link Ext.resizer.Resizer} handles config string. Only applies when resizable = true.
  173. */
  174. resizeHandles: 'all',
  175. <span id='Ext-Component-cfg-autoScroll'> /**
  176. </span> * @cfg {Boolean} [autoScroll=false]
  177. * `true` to use overflow:'auto' on the components layout element and show scroll bars automatically when necessary,
  178. * `false` to clip any overflowing content.
  179. */
  180. <span id='Ext-Component-cfg-floating'> /**
  181. </span> * @cfg {Boolean} floating
  182. * Specify as true to float the Component outside of the document flow using CSS absolute positioning.
  183. *
  184. * Components such as {@link Ext.window.Window Window}s and {@link Ext.menu.Menu Menu}s are floating by default.
  185. *
  186. * Floating Components that are programatically {@link Ext.Component#render rendered} will register themselves with
  187. * the global {@link Ext.WindowManager ZIndexManager}
  188. *
  189. * ### Floating Components as child items of a Container
  190. *
  191. * A floating Component may be used as a child item of a Container. This just allows the floating Component to seek
  192. * a ZIndexManager by examining the ownerCt chain.
  193. *
  194. * When configured as floating, Components acquire, at render time, a {@link Ext.ZIndexManager ZIndexManager} which
  195. * manages a stack of related floating Components. The ZIndexManager brings a single floating Component to the top
  196. * of its stack when the Component's {@link #toFront} method is called.
  197. *
  198. * The ZIndexManager is found by traversing up the {@link #ownerCt} chain to find an ancestor which itself is
  199. * floating. This is so that descendant floating Components of floating _Containers_ (Such as a ComboBox dropdown
  200. * within a Window) can have its zIndex managed relative to any siblings, but always **above** that floating
  201. * ancestor Container.
  202. *
  203. * If no floating ancestor is found, a floating Component registers itself with the default {@link Ext.WindowManager
  204. * ZIndexManager}.
  205. *
  206. * Floating components _do not participate in the Container's layout_. Because of this, they are not rendered until
  207. * you explicitly {@link #show} them.
  208. *
  209. * After rendering, the ownerCt reference is deleted, and the {@link #floatParent} property is set to the found
  210. * floating ancestor Container. If no floating ancestor Container was found the {@link #floatParent} property will
  211. * not be set.
  212. */
  213. floating: false,
  214. <span id='Ext-Component-cfg-toFrontOnShow'> /**
  215. </span> * @cfg {Boolean} toFrontOnShow
  216. * True to automatically call {@link #toFront} when the {@link #show} method is called on an already visible,
  217. * floating component.
  218. */
  219. toFrontOnShow: true,
  220. <span id='Ext-Component-property-zIndexManager'> /**
  221. </span> * @property {Ext.ZIndexManager} zIndexManager
  222. * Only present for {@link #floating} Components after they have been rendered.
  223. *
  224. * A reference to the ZIndexManager which is managing this Component's z-index.
  225. *
  226. * The {@link Ext.ZIndexManager ZIndexManager} maintains a stack of floating Component z-indices, and also provides
  227. * a single modal mask which is insert just beneath the topmost visible modal floating Component.
  228. *
  229. * Floating Components may be {@link #toFront brought to the front} or {@link #toBack sent to the back} of the
  230. * z-index stack.
  231. *
  232. * This defaults to the global {@link Ext.WindowManager ZIndexManager} for floating Components that are
  233. * programatically {@link Ext.Component#render rendered}.
  234. *
  235. * For {@link #floating} Components which are added to a Container, the ZIndexManager is acquired from the first
  236. * ancestor Container found which is floating, or if not found the global {@link Ext.WindowManager ZIndexManager} is
  237. * used.
  238. *
  239. * See {@link #floating} and {@link #floatParent}
  240. */
  241. <span id='Ext-Component-property-floatParent'> /**
  242. </span> * @property {Ext.Container} floatParent
  243. * Only present for {@link #floating} Components which were inserted as descendant items of floating Containers.
  244. *
  245. * Floating Components that are programatically {@link Ext.Component#render rendered} will not have a `floatParent`
  246. * property.
  247. *
  248. * For {@link #floating} Components which are child items of a Container, the floatParent will be the floating
  249. * ancestor Container which is responsible for the base z-index value of all its floating descendants. It provides
  250. * a {@link Ext.ZIndexManager ZIndexManager} which provides z-indexing services for all its descendant floating
  251. * Components.
  252. *
  253. * For example, the dropdown {@link Ext.view.BoundList BoundList} of a ComboBox which is in a Window will have the
  254. * Window as its `floatParent`
  255. *
  256. * See {@link #floating} and {@link #zIndexManager}
  257. */
  258. <span id='Ext-Component-cfg-draggable'> /**
  259. </span> * @cfg {Boolean/Object} [draggable=false]
  260. * Specify as true to make a {@link #floating} Component draggable using the Component's encapsulating element as
  261. * the drag handle.
  262. *
  263. * This may also be specified as a config object for the {@link Ext.util.ComponentDragger ComponentDragger} which is
  264. * instantiated to perform dragging.
  265. *
  266. * For example to create a Component which may only be dragged around using a certain internal element as the drag
  267. * handle, use the delegate option:
  268. *
  269. * new Ext.Component({
  270. * constrain: true,
  271. * floating: true,
  272. * style: {
  273. * backgroundColor: '#fff',
  274. * border: '1px solid black'
  275. * },
  276. * html: '&lt;h1 style=&quot;cursor:move&quot;&gt;The title&lt;/h1&gt;&lt;p&gt;The content&lt;/p&gt;',
  277. * draggable: {
  278. * delegate: 'h1'
  279. * }
  280. * }).show();
  281. */
  282. <span id='Ext-Component-cfg-maintainFlex'> /**
  283. </span> * @cfg {Boolean} [maintainFlex=false]
  284. * **Only valid when a sibling element of a {@link Ext.resizer.Splitter Splitter} within a
  285. * {@link Ext.layout.container.VBox VBox} or {@link Ext.layout.container.HBox HBox} layout.**
  286. *
  287. * Specifies that if an immediate sibling Splitter is moved, the Component on the *other* side is resized, and this
  288. * Component maintains its configured {@link Ext.layout.container.Box#flex flex} value.
  289. */
  290. hideMode: 'display',
  291. // Deprecate 5.0
  292. hideParent: false,
  293. ariaRole: 'presentation',
  294. bubbleEvents: [],
  295. actionMode: 'el',
  296. monPropRe: /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/,
  297. //renderTpl: new Ext.XTemplate(
  298. // '&lt;div id=&quot;{id}&quot; class=&quot;{baseCls} {cls} {cmpCls}&lt;tpl if=&quot;typeof ui !== \'undefined\'&quot;&gt; {uiBase}-{ui}&lt;/tpl&gt;&quot;&lt;tpl if=&quot;typeof style !== \'undefined\'&quot;&gt; style=&quot;{style}&quot;&lt;/tpl&gt;&gt;&lt;/div&gt;', {
  299. // compiled: true,
  300. // disableFormats: true
  301. // }
  302. //),
  303. <span id='Ext-Component-method-constructor'> /**
  304. </span> * Creates new Component.
  305. * @param {Ext.Element/String/Object} config The configuration options may be specified as either:
  306. *
  307. * - **an element** : it is set as the internal element and its id used as the component id
  308. * - **a string** : it is assumed to be the id of an existing element and is used as the component id
  309. * - **anything else** : it is assumed to be a standard config object and is applied to the component
  310. */
  311. constructor: function(config) {
  312. var me = this;
  313. config = config || {};
  314. if (config.initialConfig) {
  315. // Being initialized from an Ext.Action instance...
  316. if (config.isAction) {
  317. me.baseAction = config;
  318. }
  319. config = config.initialConfig;
  320. // component cloning / action set up
  321. }
  322. else if (config.tagName || config.dom || Ext.isString(config)) {
  323. // element object
  324. config = {
  325. applyTo: config,
  326. id: config.id || config
  327. };
  328. }
  329. me.callParent([config]);
  330. // If we were configured from an instance of Ext.Action, (or configured with a baseAction option),
  331. // register this Component as one of its items
  332. if (me.baseAction){
  333. me.baseAction.addComponent(me);
  334. }
  335. },
  336. <span id='Ext-Component-method-initComponent'> /**
  337. </span> * The initComponent template method is an important initialization step for a Component. It is intended to be
  338. * implemented by each subclass of Ext.Component to provide any needed constructor logic. The
  339. * initComponent method of the class being created is called first, with each initComponent method
  340. * up the hierarchy to Ext.Component being called thereafter. This makes it easy to implement and,
  341. * if needed, override the constructor logic of the Component at any step in the hierarchy.
  342. *
  343. * The initComponent method **must** contain a call to {@link Ext.Base#callParent callParent} in order
  344. * to ensure that the parent class' initComponent method is also called.
  345. *
  346. * The following example demonstrates using a dynamic string for the text of a button at the time of
  347. * instantiation of the class.
  348. *
  349. * Ext.define('DynamicButtonText', {
  350. * extend: 'Ext.button.Button',
  351. *
  352. * initComponent: function() {
  353. * this.text = new Date();
  354. * this.renderTo = Ext.getBody();
  355. * this.callParent();
  356. * }
  357. * });
  358. *
  359. * Ext.onReady(function() {
  360. * Ext.create('DynamicButtonText');
  361. * });
  362. *
  363. * @template
  364. */
  365. initComponent: function() {
  366. var me = this;
  367. me.callParent();
  368. if (me.listeners) {
  369. me.on(me.listeners);
  370. delete me.listeners;
  371. }
  372. me.enableBubble(me.bubbleEvents);
  373. me.mons = [];
  374. },
  375. // private
  376. afterRender: function() {
  377. var me = this,
  378. resizable = me.resizable;
  379. if (me.floating) {
  380. me.makeFloating(me.floating);
  381. } else {
  382. me.el.setVisibilityMode(Ext.Element[me.hideMode.toUpperCase()]);
  383. }
  384. if (Ext.isDefined(me.autoScroll)) {
  385. me.setAutoScroll(me.autoScroll);
  386. }
  387. me.callParent();
  388. if (!(me.x &amp;&amp; me.y) &amp;&amp; (me.pageX || me.pageY)) {
  389. me.setPagePosition(me.pageX, me.pageY);
  390. }
  391. if (resizable) {
  392. me.initResizable(resizable);
  393. }
  394. if (me.draggable) {
  395. me.initDraggable();
  396. }
  397. me.initAria();
  398. },
  399. initAria: function() {
  400. var actionEl = this.getActionEl(),
  401. role = this.ariaRole;
  402. if (role) {
  403. actionEl.dom.setAttribute('role', role);
  404. }
  405. },
  406. <span id='Ext-Component-method-setAutoScroll'> /**
  407. </span> * Sets the overflow on the content element of the component.
  408. * @param {Boolean} scroll True to allow the Component to auto scroll.
  409. * @return {Ext.Component} this
  410. */
  411. setAutoScroll : function(scroll){
  412. var me = this,
  413. targetEl;
  414. scroll = !!scroll;
  415. if (me.rendered) {
  416. targetEl = me.getTargetEl();
  417. targetEl.setStyle('overflow', scroll ? 'auto' : '');
  418. if (scroll &amp;&amp; (Ext.isIE6 || Ext.isIE7)) {
  419. // The scrollable container element must be non-statically positioned or IE6/7 will make
  420. // positioned children stay in place rather than scrolling with the rest of the content
  421. targetEl.position();
  422. }
  423. }
  424. me.autoScroll = scroll;
  425. return me;
  426. },
  427. // private
  428. makeFloating : function(cfg){
  429. this.mixins.floating.constructor.call(this, cfg);
  430. },
  431. initResizable: function(resizable) {
  432. var me = this;
  433. resizable = Ext.apply({
  434. target: me,
  435. dynamic: false,
  436. constrainTo: me.constrainTo || (me.floatParent ? me.floatParent.getTargetEl() : me.el.getScopeParent()),
  437. handles: me.resizeHandles
  438. }, resizable);
  439. resizable.target = me;
  440. me.resizer = Ext.create('Ext.resizer.Resizer', resizable);
  441. },
  442. getDragEl: function() {
  443. return this.el;
  444. },
  445. initDraggable: function() {
  446. var me = this,
  447. ddConfig = Ext.applyIf({
  448. el: me.getDragEl(),
  449. constrainTo: me.constrain ? (me.constrainTo || (me.floatParent ? me.floatParent.getTargetEl() : me.el.getScopeParent())) : undefined
  450. }, me.draggable);
  451. // Add extra configs if Component is specified to be constrained
  452. if (me.constrain || me.constrainDelegate) {
  453. ddConfig.constrain = me.constrain;
  454. ddConfig.constrainDelegate = me.constrainDelegate;
  455. }
  456. me.dd = Ext.create('Ext.util.ComponentDragger', me, ddConfig);
  457. },
  458. <span id='Ext-Component-method-setPosition'> /**
  459. </span> * Sets the left and top of the component. To set the page XY position instead, use {@link #setPagePosition}. This
  460. * method fires the {@link #move} event.
  461. * @param {Number} left The new left
  462. * @param {Number} top The new top
  463. * @param {Boolean/Object} [animate] If true, the Component is _animated_ into its new position. You may also pass an
  464. * animation configuration.
  465. * @return {Ext.Component} this
  466. */
  467. setPosition: function(x, y, animate) {
  468. var me = this,
  469. el = me.el,
  470. to = {},
  471. adj, adjX, adjY, xIsNumber, yIsNumber;
  472. if (Ext.isArray(x)) {
  473. animate = y;
  474. y = x[1];
  475. x = x[0];
  476. }
  477. me.x = x;
  478. me.y = y;
  479. if (!me.rendered) {
  480. return me;
  481. }
  482. adj = me.adjustPosition(x, y);
  483. adjX = adj.x;
  484. adjY = adj.y;
  485. xIsNumber = Ext.isNumber(adjX);
  486. yIsNumber = Ext.isNumber(adjY);
  487. if (xIsNumber || yIsNumber) {
  488. if (animate) {
  489. if (xIsNumber) {
  490. to.left = adjX;
  491. }
  492. if (yIsNumber) {
  493. to.top = adjY;
  494. }
  495. me.stopAnimation();
  496. me.animate(Ext.apply({
  497. duration: 1000,
  498. listeners: {
  499. afteranimate: Ext.Function.bind(me.afterSetPosition, me, [adjX, adjY])
  500. },
  501. to: to
  502. }, animate));
  503. }
  504. else {
  505. if (!xIsNumber) {
  506. el.setTop(adjY);
  507. }
  508. else if (!yIsNumber) {
  509. el.setLeft(adjX);
  510. }
  511. else {
  512. el.setLeftTop(adjX, adjY);
  513. }
  514. me.afterSetPosition(adjX, adjY);
  515. }
  516. }
  517. return me;
  518. },
  519. <span id='Ext-Component-method-afterSetPosition'> /**
  520. </span> * @private
  521. * @template
  522. * Template method called after a Component has been positioned.
  523. */
  524. afterSetPosition: function(ax, ay) {
  525. this.onPosition(ax, ay);
  526. this.fireEvent('move', this, ax, ay);
  527. },
  528. <span id='Ext-Component-method-showAt'> /**
  529. </span> * Displays component at specific xy position.
  530. * A floating component (like a menu) is positioned relative to its ownerCt if any.
  531. * Useful for popping up a context menu:
  532. *
  533. * listeners: {
  534. * itemcontextmenu: function(view, record, item, index, event, options) {
  535. * Ext.create('Ext.menu.Menu', {
  536. * width: 100,
  537. * height: 100,
  538. * margin: '0 0 10 0',
  539. * items: [{
  540. * text: 'regular item 1'
  541. * },{
  542. * text: 'regular item 2'
  543. * },{
  544. * text: 'regular item 3'
  545. * }]
  546. * }).showAt(event.getXY());
  547. * }
  548. * }
  549. *
  550. * @param {Number} x The new x position
  551. * @param {Number} y The new y position
  552. * @param {Boolean/Object} [animate] True to animate the Component into its new position. You may also pass an
  553. * animation configuration.
  554. */
  555. showAt: function(x, y, animate) {
  556. var me = this;
  557. if (me.floating) {
  558. me.setPosition(x, y, animate);
  559. } else {
  560. me.setPagePosition(x, y, animate);
  561. }
  562. me.show();
  563. },
  564. <span id='Ext-Component-method-setPagePosition'> /**
  565. </span> * Sets the page XY position of the component. To set the left and top instead, use {@link #setPosition}.
  566. * This method fires the {@link #move} event.
  567. * @param {Number} x The new x position
  568. * @param {Number} y The new y position
  569. * @param {Boolean/Object} [animate] True to animate the Component into its new position. You may also pass an
  570. * animation configuration.
  571. * @return {Ext.Component} this
  572. */
  573. setPagePosition: function(x, y, animate) {
  574. var me = this,
  575. p;
  576. if (Ext.isArray(x)) {
  577. y = x[1];
  578. x = x[0];
  579. }
  580. me.pageX = x;
  581. me.pageY = y;
  582. if (me.floating &amp;&amp; me.floatParent) {
  583. // Floating Components being positioned in their ownerCt have to be made absolute
  584. p = me.floatParent.getTargetEl().getViewRegion();
  585. if (Ext.isNumber(x) &amp;&amp; Ext.isNumber(p.left)) {
  586. x -= p.left;
  587. }
  588. if (Ext.isNumber(y) &amp;&amp; Ext.isNumber(p.top)) {
  589. y -= p.top;
  590. }
  591. me.setPosition(x, y, animate);
  592. }
  593. else {
  594. p = me.el.translatePoints(x, y);
  595. me.setPosition(p.left, p.top, animate);
  596. }
  597. return me;
  598. },
  599. <span id='Ext-Component-method-getBox'> /**
  600. </span> * Gets the current box measurements of the component's underlying element.
  601. * @param {Boolean} [local=false] If true the element's left and top are returned instead of page XY.
  602. * @return {Object} box An object in the format {x, y, width, height}
  603. */
  604. getBox : function(local){
  605. var pos = this.getPosition(local),
  606. size = this.getSize();
  607. size.x = pos[0];
  608. size.y = pos[1];
  609. return size;
  610. },
  611. <span id='Ext-Component-method-updateBox'> /**
  612. </span> * Sets the current box measurements of the component's underlying element.
  613. * @param {Object} box An object in the format {x, y, width, height}
  614. * @return {Ext.Component} this
  615. */
  616. updateBox : function(box){
  617. this.setSize(box.width, box.height);
  618. this.setPagePosition(box.x, box.y);
  619. return this;
  620. },
  621. // Include margins
  622. getOuterSize: function() {
  623. var el = this.el;
  624. return {
  625. width: el.getWidth() + el.getMargin('lr'),
  626. height: el.getHeight() + el.getMargin('tb')
  627. };
  628. },
  629. // private
  630. adjustPosition: function(x, y) {
  631. // Floating Components being positioned in their ownerCt have to be made absolute
  632. if (this.floating &amp;&amp; this.floatParent) {
  633. var o = this.floatParent.getTargetEl().getViewRegion();
  634. x += o.left;
  635. y += o.top;
  636. }
  637. return {
  638. x: x,
  639. y: y
  640. };
  641. },
  642. <span id='Ext-Component-method-getPosition'> /**
  643. </span> * Gets the current XY position of the component's underlying element.
  644. * @param {Boolean} [local=false] If true the element's left and top are returned instead of page XY.
  645. * @return {Number[]} The XY position of the element (e.g., [100, 200])
  646. */
  647. getPosition: function(local) {
  648. var me = this,
  649. el = me.el,
  650. xy,
  651. o;
  652. // Floating Components which were just rendered with no ownerCt return local position.
  653. if ((local === true) || (me.floating &amp;&amp; !me.floatParent)) {
  654. return [el.getLeft(true), el.getTop(true)];
  655. }
  656. xy = me.xy || el.getXY();
  657. // Floating Components in an ownerCt have to have their positions made relative
  658. if (me.floating) {
  659. o = me.floatParent.getTargetEl().getViewRegion();
  660. xy[0] -= o.left;
  661. xy[1] -= o.top;
  662. }
  663. return xy;
  664. },
  665. getId: function() {
  666. var me = this,
  667. xtype;
  668. if (!me.id) {
  669. xtype = me.getXType();
  670. xtype = xtype ? xtype.replace(Ext.Component.INVALID_ID_CHARS_Re, '-') : 'ext-comp';
  671. me.id = xtype + '-' + me.getAutoId();
  672. }
  673. return me.id;
  674. },
  675. onEnable: function() {
  676. var actionEl = this.getActionEl();
  677. actionEl.dom.removeAttribute('aria-disabled');
  678. actionEl.dom.disabled = false;
  679. this.callParent();
  680. },
  681. onDisable: function() {
  682. var actionEl = this.getActionEl();
  683. actionEl.dom.setAttribute('aria-disabled', true);
  684. actionEl.dom.disabled = true;
  685. this.callParent();
  686. },
  687. <span id='Ext-Component-method-show'> /**
  688. </span> * Shows this Component, rendering it first if {@link #autoRender} or {@link #floating} are `true`.
  689. *
  690. * After being shown, a {@link #floating} Component (such as a {@link Ext.window.Window}), is activated it and
  691. * brought to the front of its {@link #zIndexManager z-index stack}.
  692. *
  693. * @param {String/Ext.Element} [animateTarget=null] **only valid for {@link #floating} Components such as {@link
  694. * Ext.window.Window Window}s or {@link Ext.tip.ToolTip ToolTip}s, or regular Components which have been configured
  695. * with `floating: true`.** The target from which the Component should animate from while opening.
  696. * @param {Function} [callback] A callback function to call after the Component is displayed.
  697. * Only necessary if animation was specified.
  698. * @param {Object} [scope] The scope (`this` reference) in which the callback is executed.
  699. * Defaults to this Component.
  700. * @return {Ext.Component} this
  701. */
  702. show: function(animateTarget, cb, scope) {
  703. var me = this;
  704. if (me.rendered &amp;&amp; me.isVisible()) {
  705. if (me.toFrontOnShow &amp;&amp; me.floating) {
  706. me.toFront();
  707. }
  708. } else if (me.fireEvent('beforeshow', me) !== false) {
  709. me.hidden = false;
  710. // Render on first show if there is an autoRender config, or if this is a floater (Window, Menu, BoundList etc).
  711. if (!me.rendered &amp;&amp; (me.autoRender || me.floating)) {
  712. me.doAutoRender();
  713. }
  714. if (me.rendered) {
  715. me.beforeShow();
  716. me.onShow.apply(me, arguments);
  717. // Notify any owning Container unless it's suspended.
  718. // Floating Components do not participate in layouts.
  719. if (me.ownerCt &amp;&amp; !me.floating &amp;&amp; !(me.ownerCt.suspendLayout || me.ownerCt.layout.layoutBusy)) {
  720. me.ownerCt.doLayout();
  721. }
  722. me.afterShow.apply(me, arguments);
  723. }
  724. }
  725. return me;
  726. },
  727. beforeShow: Ext.emptyFn,
  728. // Private. Override in subclasses where more complex behaviour is needed.
  729. onShow: function() {
  730. var me = this;
  731. me.el.show();
  732. me.callParent(arguments);
  733. if (me.floating &amp;&amp; me.constrain) {
  734. me.doConstrain();
  735. }
  736. },
  737. afterShow: function(animateTarget, cb, scope) {
  738. var me = this,
  739. fromBox,
  740. toBox,
  741. ghostPanel;
  742. // Default to configured animate target if none passed
  743. animateTarget = animateTarget || me.animateTarget;
  744. // Need to be able to ghost the Component
  745. if (!me.ghost) {
  746. animateTarget = null;
  747. }
  748. // If we're animating, kick of an animation of the ghost from the target to the *Element* current box
  749. if (animateTarget) {
  750. animateTarget = animateTarget.el ? animateTarget.el : Ext.get(animateTarget);
  751. toBox = me.el.getBox();
  752. fromBox = animateTarget.getBox();
  753. me.el.addCls(Ext.baseCSSPrefix + 'hide-offsets');
  754. ghostPanel = me.ghost();
  755. ghostPanel.el.stopAnimation();
  756. // Shunting it offscreen immediately, *before* the Animation class grabs it ensure no flicker.
  757. ghostPanel.el.setX(-10000);
  758. ghostPanel.el.animate({
  759. from: fromBox,
  760. to: toBox,
  761. listeners: {
  762. afteranimate: function() {
  763. delete ghostPanel.componentLayout.lastComponentSize;
  764. me.unghost();
  765. me.el.removeCls(Ext.baseCSSPrefix + 'hide-offsets');
  766. me.onShowComplete(cb, scope);
  767. }
  768. }
  769. });
  770. }
  771. else {
  772. me.onShowComplete(cb, scope);
  773. }
  774. },
  775. onShowComplete: function(cb, scope) {
  776. var me = this;
  777. if (me.floating) {
  778. me.toFront();
  779. }
  780. Ext.callback(cb, scope || me);
  781. me.fireEvent('show', me);
  782. },
  783. <span id='Ext-Component-method-hide'> /**
  784. </span> * Hides this Component, setting it to invisible using the configured {@link #hideMode}.
  785. * @param {String/Ext.Element/Ext.Component} [animateTarget=null] **only valid for {@link #floating} Components
  786. * such as {@link Ext.window.Window Window}s or {@link Ext.tip.ToolTip ToolTip}s, or regular Components which have
  787. * been configured with `floating: true`.**. The target to which the Component should animate while hiding.
  788. * @param {Function} [callback] A callback function to call after the Component is hidden.
  789. * @param {Object} [scope] The scope (`this` reference) in which the callback is executed.
  790. * Defaults to this Component.
  791. * @return {Ext.Component} this
  792. */
  793. hide: function() {
  794. var me = this;
  795. // Clear the flag which is set if a floatParent was hidden while this is visible.
  796. // If a hide operation was subsequently called, that pending show must be hidden.
  797. me.showOnParentShow = false;
  798. if (!(me.rendered &amp;&amp; !me.isVisible()) &amp;&amp; me.fireEvent('beforehide', me) !== false) {
  799. me.hidden = true;
  800. if (me.rendered) {
  801. me.onHide.apply(me, arguments);
  802. // Notify any owning Container unless it's suspended.
  803. // Floating Components do not participate in layouts.
  804. if (me.ownerCt &amp;&amp; !me.floating &amp;&amp; !(me.ownerCt.suspendLayout || me.ownerCt.layout.layoutBusy)) {
  805. me.ownerCt.doLayout();
  806. }
  807. }
  808. }
  809. return me;
  810. },
  811. // Possibly animate down to a target element.
  812. onHide: function(animateTarget, cb, scope) {
  813. var me = this,
  814. ghostPanel,
  815. toBox;
  816. // Default to configured animate target if none passed
  817. animateTarget = animateTarget || me.animateTarget;
  818. // Need to be able to ghost the Component
  819. if (!me.ghost) {
  820. animateTarget = null;
  821. }
  822. // If we're animating, kick off an animation of the ghost down to the target
  823. if (animateTarget) {
  824. animateTarget = animateTarget.el ? animateTarget.el : Ext.get(animateTarget);
  825. ghostPanel = me.ghost();
  826. ghostPanel.el.stopAnimation();
  827. toBox = animateTarget.getBox();
  828. toBox.width += 'px';
  829. toBox.height += 'px';
  830. ghostPanel.el.animate({
  831. to: toBox,
  832. listeners: {
  833. afteranimate: function() {
  834. delete ghostPanel.componentLayout.lastComponentSize;
  835. ghostPanel.el.hide();
  836. me.afterHide(cb, scope);
  837. }
  838. }
  839. });
  840. }
  841. me.el.hide();
  842. if (!animateTarget) {
  843. me.afterHide(cb, scope);
  844. }
  845. },
  846. afterHide: function(cb, scope) {
  847. Ext.callback(cb, scope || this);
  848. this.fireEvent('hide', this);
  849. },
  850. <span id='Ext-Component-method-onDestroy'> /**
  851. </span> * @private
  852. * @template
  853. * Template method to contribute functionality at destroy time.
  854. */
  855. onDestroy: function() {
  856. var me = this;
  857. // Ensure that any ancillary components are destroyed.
  858. if (me.rendered) {
  859. Ext.destroy(
  860. me.proxy,
  861. me.proxyWrap,
  862. me.resizer
  863. );
  864. // Different from AbstractComponent
  865. if (me.actionMode == 'container' || me.removeMode == 'container') {
  866. me.container.remove();
  867. }
  868. }
  869. delete me.focusTask;
  870. me.callParent();
  871. },
  872. deleteMembers: function() {
  873. var args = arguments,
  874. len = args.length,
  875. i = 0;
  876. for (; i &lt; len; ++i) {
  877. delete this[args[i]];
  878. }
  879. },
  880. <span id='Ext-Component-method-focus'> /**
  881. </span> * Try to focus this component.
  882. * @param {Boolean} [selectText] If applicable, true to also select the text in this component
  883. * @param {Boolean/Number} [delay] Delay the focus this number of milliseconds (true for 10 milliseconds).
  884. * @return {Ext.Component} this
  885. */
  886. focus: function(selectText, delay) {
  887. var me = this,
  888. focusEl;
  889. if (delay) {
  890. if (!me.focusTask) {
  891. me.focusTask = Ext.create('Ext.util.DelayedTask', me.focus);
  892. }
  893. me.focusTask.delay(Ext.isNumber(delay) ? delay : 10, null, me, [selectText, false]);
  894. return me;
  895. }
  896. if (me.rendered &amp;&amp; !me.isDestroyed) {
  897. // getFocusEl could return a Component.
  898. focusEl = me.getFocusEl();
  899. focusEl.focus();
  900. if (focusEl.dom &amp;&amp; selectText === true) {
  901. focusEl.dom.select();
  902. }
  903. // Focusing a floating Component brings it to the front of its stack.
  904. // this is performed by its zIndexManager. Pass preventFocus true to avoid recursion.
  905. if (me.floating) {
  906. me.toFront(true);
  907. }
  908. }
  909. return me;
  910. },
  911. <span id='Ext-Component-method-getFocusEl'> /**
  912. </span> * @private
  913. * Returns the focus holder element associated with this Component. By default, this is the Component's encapsulating
  914. * element. Subclasses which use embedded focusable elements (such as Window and Button) should override this for use
  915. * by the {@link #focus} method.
  916. * @returns {Ext.Element} the focus holing element.
  917. */
  918. getFocusEl: function() {
  919. return this.el;
  920. },
  921. // private
  922. blur: function() {
  923. if (this.rendered) {
  924. this.getFocusEl().blur();
  925. }
  926. return this;
  927. },
  928. getEl: function() {
  929. return this.el;
  930. },
  931. // Deprecate 5.0
  932. getResizeEl: function() {
  933. return this.el;
  934. },
  935. // Deprecate 5.0
  936. getPositionEl: function() {
  937. return this.el;
  938. },
  939. // Deprecate 5.0
  940. getActionEl: function() {
  941. return this.el;
  942. },
  943. // Deprecate 5.0
  944. getVisibilityEl: function() {
  945. return this.el;
  946. },
  947. // Deprecate 5.0
  948. onResize: Ext.emptyFn,
  949. // private
  950. getBubbleTarget: function() {
  951. return this.ownerCt;
  952. },
  953. // private
  954. getContentTarget: function() {
  955. return this.el;
  956. },
  957. <span id='Ext-Component-method-cloneConfig'> /**
  958. </span> * Clone the current component using the original config values passed into this instance by default.
  959. * @param {Object} overrides A new config containing any properties to override in the cloned version.
  960. * An id property can be passed on this object, otherwise one will be generated to avoid duplicates.
  961. * @return {Ext.Component} clone The cloned copy of this component
  962. */
  963. cloneConfig: function(overrides) {
  964. overrides = overrides || {};
  965. var id = overrides.id || Ext.id(),
  966. cfg = Ext.applyIf(overrides, this.initialConfig),
  967. self;
  968. cfg.id = id;
  969. self = Ext.getClass(this);
  970. // prevent dup id
  971. return new self(cfg);
  972. },
  973. <span id='Ext-Component-method-getXType'> /**
  974. </span> * Gets the xtype for this component as registered with {@link Ext.ComponentManager}. For a list of all available
  975. * xtypes, see the {@link Ext.Component} header. Example usage:
  976. *
  977. * var t = new Ext.form.field.Text();
  978. * alert(t.getXType()); // alerts 'textfield'
  979. *
  980. * @return {String} The xtype
  981. */
  982. getXType: function() {
  983. return this.self.xtype;
  984. },
  985. <span id='Ext-Component-method-findParentBy'> /**
  986. </span> * Find a container above this component at any level by a custom function. If the passed function returns true, the
  987. * container will be returned.
  988. * @param {Function} fn The custom function to call with the arguments (container, this component).
  989. * @return {Ext.container.Container} The first Container for which the custom function returns true
  990. */
  991. findParentBy: function(fn) {
  992. var p;
  993. // Iterate up the ownerCt chain until there's no ownerCt, or we find an ancestor which matches using the selector function.
  994. for (p = this.ownerCt; p &amp;&amp; !fn(p, this); p = p.ownerCt);
  995. return p || null;
  996. },
  997. <span id='Ext-Component-method-findParentByType'> /**
  998. </span> * Find a container above this component at any level by xtype or class
  999. *
  1000. * See also the {@link Ext.Component#up up} method.
  1001. *
  1002. * @param {String/Ext.Class} xtype The xtype string for a component, or the class of the component directly
  1003. * @return {Ext.container.Container} The first Container which matches the given xtype or class
  1004. */
  1005. findParentByType: function(xtype) {
  1006. return Ext.isFunction(xtype) ?
  1007. this.findParentBy(function(p) {
  1008. return p.constructor === xtype;
  1009. })
  1010. :
  1011. this.up(xtype);
  1012. },
  1013. <span id='Ext-Component-method-bubble'> /**
  1014. </span> * Bubbles up the component/container heirarchy, calling the specified function with each component. The scope
  1015. * (*this*) of function call will be the scope provided or the current component. The arguments to the function will
  1016. * be the args provided or the current component. If the function returns false at any point, the bubble is stopped.
  1017. *
  1018. * @param {Function} fn The function to call
  1019. * @param {Object} [scope] The scope of the function. Defaults to current node.
  1020. * @param {Array} [args] The args to call the function with. Defaults to passing the current component.
  1021. * @return {Ext.Component} this
  1022. */
  1023. bubble: function(fn, scope, args) {
  1024. var p = this;
  1025. while (p) {
  1026. if (fn.apply(scope || p, args || [p]) === false) {
  1027. break;
  1028. }
  1029. p = p.ownerCt;
  1030. }
  1031. return this;
  1032. },
  1033. getProxy: function() {
  1034. var me = this,
  1035. target;
  1036. if (!me.proxy) {
  1037. target = Ext.getBody();
  1038. if (Ext.scopeResetCSS) {
  1039. me.proxyWrap = target = Ext.getBody().createChild({
  1040. cls: Ext.baseCSSPrefix + 'reset'
  1041. });
  1042. }
  1043. me.proxy = me.el.createProxy(Ext.baseCSSPrefix + 'proxy-el', target, true);
  1044. }
  1045. return me.proxy;
  1046. }
  1047. });
  1048. </pre>
  1049. </body>
  1050. </html>