forked from probonogeek/extjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractComponent.js
3343 lines (2939 loc) · 119 KB
/
AbstractComponent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This file is part of Ext JS 4
Copyright (c) 2011 Sencha Inc
Contact: http://www.sencha.com/contact
GNU General Public License Usage
This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
*/
/**
* An abstract base class which provides shared methods for Components across the Sencha product line.
*
* Please refer to sub class's documentation
* @private
*/
Ext.define('Ext.AbstractComponent', {
/* Begin Definitions */
requires: [
'Ext.ComponentQuery',
'Ext.ComponentManager'
],
mixins: {
observable: 'Ext.util.Observable',
animate: 'Ext.util.Animate',
state: 'Ext.state.Stateful'
},
// The "uses" property specifies class which are used in an instantiated AbstractComponent.
// They do *not* have to be loaded before this class may be defined - that is what "requires" is for.
uses: [
'Ext.PluginManager',
'Ext.ComponentManager',
'Ext.Element',
'Ext.DomHelper',
'Ext.XTemplate',
'Ext.ComponentQuery',
'Ext.ComponentLoader',
'Ext.EventManager',
'Ext.layout.Layout',
'Ext.layout.component.Auto',
'Ext.LoadMask',
'Ext.ZIndexManager'
],
statics: {
AUTO_ID: 1000
},
/* End Definitions */
isComponent: true,
getAutoId: function() {
return ++Ext.AbstractComponent.AUTO_ID;
},
/**
* @cfg {String} id
* The **unique id of this component instance.**
*
* It should not be necessary to use this configuration except for singleton objects in your application. Components
* created with an id may be accessed globally using {@link Ext#getCmp Ext.getCmp}.
*
* Instead of using assigned ids, use the {@link #itemId} config, and {@link Ext.ComponentQuery ComponentQuery}
* which provides selector-based searching for Sencha Components analogous to DOM querying. The {@link
* Ext.container.Container Container} class contains {@link Ext.container.Container#down shortcut methods} to query
* its descendant Components by selector.
*
* Note that this id will also be used as the element id for the containing HTML element that is rendered to the
* page for this component. This allows you to write id-based CSS rules to style the specific instance of this
* component uniquely, and also to select sub-elements using this component's id as the parent.
*
* **Note**: to avoid complications imposed by a unique id also see `{@link #itemId}`.
*
* **Note**: to access the container of a Component see `{@link #ownerCt}`.
*
* Defaults to an {@link #getId auto-assigned id}.
*/
/**
* @cfg {String} itemId
* An itemId can be used as an alternative way to get a reference to a component when no object reference is
* available. Instead of using an `{@link #id}` with {@link Ext}.{@link Ext#getCmp getCmp}, use `itemId` with
* {@link Ext.container.Container}.{@link Ext.container.Container#getComponent getComponent} which will retrieve
* `itemId`'s or {@link #id}'s. Since `itemId`'s are an index to the container's internal MixedCollection, the
* `itemId` is scoped locally to the container -- avoiding potential conflicts with {@link Ext.ComponentManager}
* which requires a **unique** `{@link #id}`.
*
* var c = new Ext.panel.Panel({ //
* {@link Ext.Component#height height}: 300,
* {@link #renderTo}: document.body,
* {@link Ext.container.Container#layout layout}: 'auto',
* {@link Ext.container.Container#items items}: [
* {
* itemId: 'p1',
* {@link Ext.panel.Panel#title title}: 'Panel 1',
* {@link Ext.Component#height height}: 150
* },
* {
* itemId: 'p2',
* {@link Ext.panel.Panel#title title}: 'Panel 2',
* {@link Ext.Component#height height}: 150
* }
* ]
* })
* p1 = c.{@link Ext.container.Container#getComponent getComponent}('p1'); // not the same as {@link Ext#getCmp Ext.getCmp()}
* p2 = p1.{@link #ownerCt}.{@link Ext.container.Container#getComponent getComponent}('p2'); // reference via a sibling
*
* Also see {@link #id}, `{@link Ext.container.Container#query}`, `{@link Ext.container.Container#down}` and
* `{@link Ext.container.Container#child}`.
*
* **Note**: to access the container of an item see {@link #ownerCt}.
*/
/**
* @property {Ext.Container} ownerCt
* This Component's owner {@link Ext.container.Container Container} (is set automatically
* when this Component is added to a Container). Read-only.
*
* **Note**: to access items within the Container see {@link #itemId}.
*/
/**
* @property {Boolean} layoutManagedWidth
* @private
* Flag set by the container layout to which this Component is added.
* If the layout manages this Component's width, it sets the value to 1.
* If it does NOT manage the width, it sets it to 2.
* If the layout MAY affect the width, but only if the owning Container has a fixed width, this is set to 0.
*/
/**
* @property {Boolean} layoutManagedHeight
* @private
* Flag set by the container layout to which this Component is added.
* If the layout manages this Component's height, it sets the value to 1.
* If it does NOT manage the height, it sets it to 2.
* If the layout MAY affect the height, but only if the owning Container has a fixed height, this is set to 0.
*/
/**
* @cfg {String/Object} autoEl
* A tag name or {@link Ext.DomHelper DomHelper} spec used to create the {@link #getEl Element} which will
* encapsulate this Component.
*
* You do not normally need to specify this. For the base classes {@link Ext.Component} and
* {@link Ext.container.Container}, this defaults to **'div'**. The more complex Sencha classes use a more
* complex DOM structure specified by their own {@link #renderTpl}s.
*
* This is intended to allow the developer to create application-specific utility Components encapsulated by
* different DOM elements. Example usage:
*
* {
* xtype: 'component',
* autoEl: {
* tag: 'img',
* src: 'http://www.example.com/example.jpg'
* }
* }, {
* xtype: 'component',
* autoEl: {
* tag: 'blockquote',
* html: 'autoEl is cool!'
* }
* }, {
* xtype: 'container',
* autoEl: 'ul',
* cls: 'ux-unordered-list',
* items: {
* xtype: 'component',
* autoEl: 'li',
* html: 'First list item'
* }
* }
*/
/**
* @cfg {Ext.XTemplate/String/String[]} renderTpl
* An {@link Ext.XTemplate XTemplate} used to create the internal structure inside this Component's encapsulating
* {@link #getEl Element}.
*
* You do not normally need to specify this. For the base classes {@link Ext.Component} and
* {@link Ext.container.Container}, this defaults to **`null`** which means that they will be initially rendered
* with no internal structure; they render their {@link #getEl Element} empty. The more specialized ExtJS and Touch
* classes which use a more complex DOM structure, provide their own template definitions.
*
* This is intended to allow the developer to create application-specific utility Components with customized
* internal structure.
*
* Upon rendering, any created child elements may be automatically imported into object properties using the
* {@link #renderSelectors} and {@link #childEls} options.
*/
renderTpl: null,
/**
* @cfg {Object} renderData
*
* The data used by {@link #renderTpl} in addition to the following property values of the component:
*
* - id
* - ui
* - uiCls
* - baseCls
* - componentCls
* - frame
*
* See {@link #renderSelectors} and {@link #childEls} for usage examples.
*/
/**
* @cfg {Object} renderSelectors
* An object containing properties specifying {@link Ext.DomQuery DomQuery} selectors which identify child elements
* created by the render process.
*
* After the Component's internal structure is rendered according to the {@link #renderTpl}, this object is iterated through,
* and the found Elements are added as properties to the Component using the `renderSelector` property name.
*
* For example, a Component which renderes a title and description into its element:
*
* Ext.create('Ext.Component', {
* renderTo: Ext.getBody(),
* renderTpl: [
* '<h1 class="title">{title}</h1>',
* '<p>{desc}</p>'
* ],
* renderData: {
* title: "Error",
* desc: "Something went wrong"
* },
* renderSelectors: {
* titleEl: 'h1.title',
* descEl: 'p'
* },
* listeners: {
* afterrender: function(cmp){
* // After rendering the component will have a titleEl and descEl properties
* cmp.titleEl.setStyle({color: "red"});
* }
* }
* });
*
* For a faster, but less flexible, alternative that achieves the same end result (properties for child elements on the
* Component after render), see {@link #childEls} and {@link #addChildEls}.
*/
/**
* @cfg {Object[]} childEls
* An array describing the child elements of the Component. Each member of the array
* is an object with these properties:
*
* - `name` - The property name on the Component for the child element.
* - `itemId` - The id to combine with the Component's id that is the id of the child element.
* - `id` - The id of the child element.
*
* If the array member is a string, it is equivalent to `{ name: m, itemId: m }`.
*
* For example, a Component which renders a title and body text:
*
* Ext.create('Ext.Component', {
* renderTo: Ext.getBody(),
* renderTpl: [
* '<h1 id="{id}-title">{title}</h1>',
* '<p>{msg}</p>',
* ],
* renderData: {
* title: "Error",
* msg: "Something went wrong"
* },
* childEls: ["title"],
* listeners: {
* afterrender: function(cmp){
* // After rendering the component will have a title property
* cmp.title.setStyle({color: "red"});
* }
* }
* });
*
* A more flexible, but somewhat slower, approach is {@link #renderSelectors}.
*/
/**
* @cfg {String/HTMLElement/Ext.Element} renderTo
* Specify the id of the element, a DOM element or an existing Element that this component will be rendered into.
*
* **Notes:**
*
* Do *not* use this option if the Component is to be a child item of a {@link Ext.container.Container Container}.
* It is the responsibility of the {@link Ext.container.Container Container}'s
* {@link Ext.container.Container#layout layout manager} to render and manage its child items.
*
* When using this config, a call to render() is not required.
*
* See `{@link #render}` also.
*/
/**
* @cfg {Boolean} frame
* Specify as `true` to have the Component inject framing elements within the Component at render time to provide a
* graphical rounded frame around the Component content.
*
* This is only necessary when running on outdated, or non standard-compliant browsers such as Microsoft's Internet
* Explorer prior to version 9 which do not support rounded corners natively.
*
* The extra space taken up by this framing is available from the read only property {@link #frameSize}.
*/
/**
* @property {Object} frameSize
* Read-only property indicating the width of any framing elements which were added within the encapsulating element
* to provide graphical, rounded borders. See the {@link #frame} config.
*
* This is an object containing the frame width in pixels for all four sides of the Component containing the
* following properties:
*
* @property {Number} frameSize.top The width of the top framing element in pixels.
* @property {Number} frameSize.right The width of the right framing element in pixels.
* @property {Number} frameSize.bottom The width of the bottom framing element in pixels.
* @property {Number} frameSize.left The width of the left framing element in pixels.
*/
/**
* @cfg {String/Object} componentLayout
* The sizing and positioning of a Component's internal Elements is the responsibility of the Component's layout
* manager which sizes a Component's internal structure in response to the Component being sized.
*
* Generally, developers will not use this configuration as all provided Components which need their internal
* elements sizing (Such as {@link Ext.form.field.Base input fields}) come with their own componentLayout managers.
*
* The {@link Ext.layout.container.Auto default layout manager} will be used on instances of the base Ext.Component
* class which simply sizes the Component's encapsulating element to the height and width specified in the
* {@link #setSize} method.
*/
/**
* @cfg {Ext.XTemplate/Ext.Template/String/String[]} tpl
* An {@link Ext.Template}, {@link Ext.XTemplate} or an array of strings to form an Ext.XTemplate. Used in
* conjunction with the `{@link #data}` and `{@link #tplWriteMode}` configurations.
*/
/**
* @cfg {Object} data
* The initial set of data to apply to the `{@link #tpl}` to update the content area of the Component.
*/
/**
* @cfg {String} xtype
* The `xtype` configuration option can be used to optimize Component creation and rendering. It serves as a
* shortcut to the full componet name. For example, the component `Ext.button.Button` has an xtype of `button`.
*
* You can define your own xtype on a custom {@link Ext.Component component} by specifying the
* {@link Ext.Class#alias alias} config option with a prefix of `widget`. For example:
*
* Ext.define('PressMeButton', {
* extend: 'Ext.button.Button',
* alias: 'widget.pressmebutton',
* text: 'Press Me'
* })
*
* Any Component can be created implicitly as an object config with an xtype specified, allowing it to be
* declared and passed into the rendering pipeline without actually being instantiated as an object. Not only is
* rendering deferred, but the actual creation of the object itself is also deferred, saving memory and resources
* until they are actually needed. In complex, nested layouts containing many Components, this can make a
* noticeable improvement in performance.
*
* // Explicit creation of contained Components:
* var panel = new Ext.Panel({
* ...
* items: [
* Ext.create('Ext.button.Button', {
* text: 'OK'
* })
* ]
* };
*
* // Implicit creation using xtype:
* var panel = new Ext.Panel({
* ...
* items: [{
* xtype: 'button',
* text: 'OK'
* }]
* };
*
* In the first example, the button will always be created immediately during the panel's initialization. With
* many added Components, this approach could potentially slow the rendering of the page. In the second example,
* the button will not be created or rendered until the panel is actually displayed in the browser. If the panel
* is never displayed (for example, if it is a tab that remains hidden) then the button will never be created and
* will never consume any resources whatsoever.
*/
/**
* @cfg {String} tplWriteMode
* The Ext.(X)Template method to use when updating the content area of the Component.
* See `{@link Ext.XTemplate#overwrite}` for information on default mode.
*/
tplWriteMode: 'overwrite',
/**
* @cfg {String} [baseCls='x-component']
* The base CSS class to apply to this components's element. This will also be prepended to elements within this
* component like Panel's body will get a class x-panel-body. This means that if you create a subclass of Panel, and
* you want it to get all the Panels styling for the element and the body, you leave the baseCls x-panel and use
* componentCls to add specific styling for this component.
*/
baseCls: Ext.baseCSSPrefix + 'component',
/**
* @cfg {String} componentCls
* CSS Class to be added to a components root level element to give distinction to it via styling.
*/
/**
* @cfg {String} [cls='']
* An optional extra CSS class that will be added to this component's Element. This can be useful
* for adding customized styles to the component or any of its children using standard CSS rules.
*/
/**
* @cfg {String} [overCls='']
* An optional extra CSS class that will be added to this component's Element when the mouse moves over the Element,
* and removed when the mouse moves out. This can be useful for adding customized 'active' or 'hover' styles to the
* component or any of its children using standard CSS rules.
*/
/**
* @cfg {String} [disabledCls='x-item-disabled']
* CSS class to add when the Component is disabled. Defaults to 'x-item-disabled'.
*/
disabledCls: Ext.baseCSSPrefix + 'item-disabled',
/**
* @cfg {String/String[]} ui
* A set style for a component. Can be a string or an Array of multiple strings (UIs)
*/
ui: 'default',
/**
* @cfg {String[]} uiCls
* An array of of classNames which are currently applied to this component
* @private
*/
uiCls: [],
/**
* @cfg {String} style
* A custom style specification to be applied to this component's Element. Should be a valid argument to
* {@link Ext.Element#applyStyles}.
*
* new Ext.panel.Panel({
* title: 'Some Title',
* renderTo: Ext.getBody(),
* width: 400, height: 300,
* layout: 'form',
* items: [{
* xtype: 'textarea',
* style: {
* width: '95%',
* marginBottom: '10px'
* }
* },
* new Ext.button.Button({
* text: 'Send',
* minWidth: '100',
* style: {
* marginBottom: '10px'
* }
* })
* ]
* });
*/
/**
* @cfg {Number} width
* The width of this component in pixels.
*/
/**
* @cfg {Number} height
* The height of this component in pixels.
*/
/**
* @cfg {Number/String} border
* Specifies the border for this component. The border can be a single numeric value to apply to all sides or it can
* be a CSS style specification for each style, for example: '10 5 3 10'.
*/
/**
* @cfg {Number/String} padding
* Specifies the padding for this component. The padding can be a single numeric value to apply to all sides or it
* can be a CSS style specification for each style, for example: '10 5 3 10'.
*/
/**
* @cfg {Number/String} margin
* Specifies the margin for this component. The margin can be a single numeric value to apply to all sides or it can
* be a CSS style specification for each style, for example: '10 5 3 10'.
*/
/**
* @cfg {Boolean} hidden
* True to hide the component.
*/
hidden: false,
/**
* @cfg {Boolean} disabled
* True to disable the component.
*/
disabled: false,
/**
* @cfg {Boolean} [draggable=false]
* Allows the component to be dragged.
*/
/**
* @property {Boolean} draggable
* Read-only property indicating whether or not the component can be dragged
*/
draggable: false,
/**
* @cfg {Boolean} floating
* Create the Component as a floating and use absolute positioning.
*
* The z-index of floating Components is handled by a ZIndexManager. If you simply render a floating Component into the DOM, it will be managed
* by the global {@link Ext.WindowManager WindowManager}.
*
* If you include a floating Component as a child item of a Container, then upon render, ExtJS will seek an ancestor floating Component to house a new
* ZIndexManager instance to manage its descendant floaters. If no floating ancestor can be found, the global WindowManager will be used.
*
* When a floating Component which has a ZindexManager managing descendant floaters is destroyed, those descendant floaters will also be destroyed.
*/
floating: false,
/**
* @cfg {String} hideMode
* A String which specifies how this Component's encapsulating DOM element will be hidden. Values may be:
*
* - `'display'` : The Component will be hidden using the `display: none` style.
* - `'visibility'` : The Component will be hidden using the `visibility: hidden` style.
* - `'offsets'` : The Component will be hidden by absolutely positioning it out of the visible area of the document.
* This is useful when a hidden Component must maintain measurable dimensions. Hiding using `display` results in a
* Component having zero dimensions.
*/
hideMode: 'display',
/**
* @cfg {String} contentEl
* Specify an existing HTML element, or the `id` of an existing HTML element to use as the content for this component.
*
* This config option is used to take an existing HTML element and place it in the layout element of a new component
* (it simply moves the specified DOM element _after the Component is rendered_ to use as the content.
*
* **Notes:**
*
* The specified HTML element is appended to the layout element of the component _after any configured
* {@link #html HTML} has been inserted_, and so the document will not contain this element at the time
* the {@link #render} event is fired.
*
* The specified HTML element used will not participate in any **`{@link Ext.container.Container#layout layout}`**
* scheme that the Component may use. It is just HTML. Layouts operate on child
* **`{@link Ext.container.Container#items items}`**.
*
* Add either the `x-hidden` or the `x-hide-display` CSS class to prevent a brief flicker of the content before it
* is rendered to the panel.
*/
/**
* @cfg {String/Object} [html='']
* An HTML fragment, or a {@link Ext.DomHelper DomHelper} specification to use as the layout element content.
* The HTML content is added after the component is rendered, so the document will not contain this HTML at the time
* the {@link #render} event is fired. This content is inserted into the body _before_ any configured {@link #contentEl}
* is appended.
*/
/**
* @cfg {Boolean} styleHtmlContent
* True to automatically style the html inside the content target of this component (body for panels).
*/
styleHtmlContent: false,
/**
* @cfg {String} [styleHtmlCls='x-html']
* The class that is added to the content target when you set styleHtmlContent to true.
*/
styleHtmlCls: Ext.baseCSSPrefix + 'html',
/**
* @cfg {Number} minHeight
* The minimum value in pixels which this Component will set its height to.
*
* **Warning:** This will override any size management applied by layout managers.
*/
/**
* @cfg {Number} minWidth
* The minimum value in pixels which this Component will set its width to.
*
* **Warning:** This will override any size management applied by layout managers.
*/
/**
* @cfg {Number} maxHeight
* The maximum value in pixels which this Component will set its height to.
*
* **Warning:** This will override any size management applied by layout managers.
*/
/**
* @cfg {Number} maxWidth
* The maximum value in pixels which this Component will set its width to.
*
* **Warning:** This will override any size management applied by layout managers.
*/
/**
* @cfg {Ext.ComponentLoader/Object} loader
* A configuration object or an instance of a {@link Ext.ComponentLoader} to load remote content for this Component.
*/
/**
* @cfg {Boolean} autoShow
* True to automatically show the component upon creation. This config option may only be used for
* {@link #floating} components or components that use {@link #autoRender}. Defaults to false.
*/
autoShow: false,
/**
* @cfg {Boolean/String/HTMLElement/Ext.Element} autoRender
* This config is intended mainly for non-{@link #floating} Components which may or may not be shown. Instead of using
* {@link #renderTo} in the configuration, and rendering upon construction, this allows a Component to render itself
* upon first _{@link #show}_. If {@link #floating} is true, the value of this config is omited as if it is `true`.
*
* Specify as `true` to have this Component render to the document body upon first show.
*
* Specify as an element, or the ID of an element to have this Component render to a specific element upon first
* show.
*
* **This defaults to `true` for the {@link Ext.window.Window Window} class.**
*/
autoRender: false,
needsLayout: false,
// @private
allowDomMove: true,
/**
* @cfg {Object/Object[]} plugins
* An object or array of objects that will provide custom functionality for this component. The only requirement for
* a valid plugin is that it contain an init method that accepts a reference of type Ext.Component. When a component
* is created, if any plugins are available, the component will call the init method on each plugin, passing a
* reference to itself. Each plugin can then call methods or respond to events on the component as needed to provide
* its functionality.
*/
/**
* @property {Boolean} rendered
* Read-only property indicating whether or not the component has been rendered.
*/
rendered: false,
/**
* @property {Number} componentLayoutCounter
* @private
* The number of component layout calls made on this object.
*/
componentLayoutCounter: 0,
weight: 0,
trimRe: /^\s+|\s+$/g,
spacesRe: /\s+/,
/**
* @property {Boolean} maskOnDisable
* This is an internal flag that you use when creating custom components. By default this is set to true which means
* that every component gets a mask when its disabled. Components like FieldContainer, FieldSet, Field, Button, Tab
* override this property to false since they want to implement custom disable logic.
*/
maskOnDisable: true,
/**
* Creates new Component.
* @param {Object} config (optional) Config object.
*/
constructor : function(config) {
var me = this,
i, len;
config = config || {};
me.initialConfig = config;
Ext.apply(me, config);
me.addEvents(
/**
* @event beforeactivate
* Fires before a Component has been visually activated. Returning false from an event listener can prevent
* the activate from occurring.
* @param {Ext.Component} this
*/
'beforeactivate',
/**
* @event activate
* Fires after a Component has been visually activated.
* @param {Ext.Component} this
*/
'activate',
/**
* @event beforedeactivate
* Fires before a Component has been visually deactivated. Returning false from an event listener can
* prevent the deactivate from occurring.
* @param {Ext.Component} this
*/
'beforedeactivate',
/**
* @event deactivate
* Fires after a Component has been visually deactivated.
* @param {Ext.Component} this
*/
'deactivate',
/**
* @event added
* Fires after a Component had been added to a Container.
* @param {Ext.Component} this
* @param {Ext.container.Container} container Parent Container
* @param {Number} pos position of Component
*/
'added',
/**
* @event disable
* Fires after the component is disabled.
* @param {Ext.Component} this
*/
'disable',
/**
* @event enable
* Fires after the component is enabled.
* @param {Ext.Component} this
*/
'enable',
/**
* @event beforeshow
* Fires before the component is shown when calling the {@link #show} method. Return false from an event
* handler to stop the show.
* @param {Ext.Component} this
*/
'beforeshow',
/**
* @event show
* Fires after the component is shown when calling the {@link #show} method.
* @param {Ext.Component} this
*/
'show',
/**
* @event beforehide
* Fires before the component is hidden when calling the {@link #hide} method. Return false from an event
* handler to stop the hide.
* @param {Ext.Component} this
*/
'beforehide',
/**
* @event hide
* Fires after the component is hidden. Fires after the component is hidden when calling the {@link #hide}
* method.
* @param {Ext.Component} this
*/
'hide',
/**
* @event removed
* Fires when a component is removed from an Ext.container.Container
* @param {Ext.Component} this
* @param {Ext.container.Container} ownerCt Container which holds the component
*/
'removed',
/**
* @event beforerender
* Fires before the component is {@link #rendered}. Return false from an event handler to stop the
* {@link #render}.
* @param {Ext.Component} this
*/
'beforerender',
/**
* @event render
* Fires after the component markup is {@link #rendered}.
* @param {Ext.Component} this
*/
'render',
/**
* @event afterrender
* Fires after the component rendering is finished.
*
* The afterrender event is fired after this Component has been {@link #rendered}, been postprocesed by any
* afterRender method defined for the Component.
* @param {Ext.Component} this
*/
'afterrender',
/**
* @event beforedestroy
* Fires before the component is {@link #destroy}ed. Return false from an event handler to stop the
* {@link #destroy}.
* @param {Ext.Component} this
*/
'beforedestroy',
/**
* @event destroy
* Fires after the component is {@link #destroy}ed.
* @param {Ext.Component} this
*/
'destroy',
/**
* @event resize
* Fires after the component is resized.
* @param {Ext.Component} this
* @param {Number} adjWidth The box-adjusted width that was set
* @param {Number} adjHeight The box-adjusted height that was set
*/
'resize',
/**
* @event move
* Fires after the component is moved.
* @param {Ext.Component} this
* @param {Number} x The new x position
* @param {Number} y The new y position
*/
'move'
);
me.getId();
me.mons = [];
me.additionalCls = [];
me.renderData = me.renderData || {};
me.renderSelectors = me.renderSelectors || {};
if (me.plugins) {
me.plugins = [].concat(me.plugins);
me.constructPlugins();
}
me.initComponent();
// ititComponent gets a chance to change the id property before registering
Ext.ComponentManager.register(me);
// Dont pass the config so that it is not applied to 'this' again
me.mixins.observable.constructor.call(me);
me.mixins.state.constructor.call(me, config);
// Save state on resize.
this.addStateEvents('resize');
// Move this into Observable?
if (me.plugins) {
me.plugins = [].concat(me.plugins);
for (i = 0, len = me.plugins.length; i < len; i++) {
me.plugins[i] = me.initPlugin(me.plugins[i]);
}
}
me.loader = me.getLoader();
if (me.renderTo) {
me.render(me.renderTo);
// EXTJSIV-1935 - should be a way to do afterShow or something, but that
// won't work. Likewise, rendering hidden and then showing (w/autoShow) has
// implications to afterRender so we cannot do that.
}
if (me.autoShow) {
me.show();
}
//<debug>
if (Ext.isDefined(me.disabledClass)) {
if (Ext.isDefined(Ext.global.console)) {
Ext.global.console.warn('Ext.Component: disabledClass has been deprecated. Please use disabledCls.');
}
me.disabledCls = me.disabledClass;
delete me.disabledClass;
}
//</debug>
},
initComponent: function () {
// This is called again here to allow derived classes to add plugin configs to the
// plugins array before calling down to this, the base initComponent.
this.constructPlugins();
},
/**
* The supplied default state gathering method for the AbstractComponent class.
*
* This method returns dimension settings such as `flex`, `anchor`, `width` and `height` along with `collapsed`
* state.
*
* Subclasses which implement more complex state should call the superclass's implementation, and apply their state
* to the result if this basic state is to be saved.
*
* Note that Component state will only be saved if the Component has a {@link #stateId} and there as a StateProvider
* configured for the document.
*
* @return {Object}
*/
getState: function() {
var me = this,
layout = me.ownerCt ? (me.shadowOwnerCt || me.ownerCt).getLayout() : null,
state = {
collapsed: me.collapsed
},
width = me.width,
height = me.height,
cm = me.collapseMemento,
anchors;
// If a Panel-local collapse has taken place, use remembered values as the dimensions.
// TODO: remove this coupling with Panel's privates! All collapse/expand logic should be refactored into one place.
if (me.collapsed && cm) {
if (Ext.isDefined(cm.data.width)) {
width = cm.width;
}
if (Ext.isDefined(cm.data.height)) {
height = cm.height;
}
}
// If we have flex, only store the perpendicular dimension.
if (layout && me.flex) {
state.flex = me.flex;
if (layout.perpendicularPrefix) {
state[layout.perpendicularPrefix] = me['get' + layout.perpendicularPrefixCap]();
} else {
//<debug>
if (Ext.isDefined(Ext.global.console)) {
Ext.global.console.warn('Ext.Component: Specified a flex value on a component not inside a Box layout');
}
//</debug>
}
}
// If we have anchor, only store dimensions which are *not* being anchored
else if (layout && me.anchor) {
state.anchor = me.anchor;
anchors = me.anchor.split(' ').concat(null);
if (!anchors[0]) {
if (me.width) {
state.width = width;
}
}
if (!anchors[1]) {
if (me.height) {
state.height = height;
}
}
}
// Store dimensions.
else {
if (me.width) {
state.width = width;
}
if (me.height) {
state.height = height;
}
}
// Don't save dimensions if they are unchanged from the original configuration.
if (state.width == me.initialConfig.width) {
delete state.width;
}
if (state.height == me.initialConfig.height) {
delete state.height;
}
// If a Box layout was managing the perpendicular dimension, don't save that dimension
if (layout && layout.align && (layout.align.indexOf('stretch') !== -1)) {
delete state[layout.perpendicularPrefix];
}
return state;
},
show: Ext.emptyFn,
animate: function(animObj) {
var me = this,
to;
animObj = animObj || {};
to = animObj.to || {};
if (Ext.fx.Manager.hasFxBlock(me.id)) {
return me;
}
// Special processing for animating Component dimensions.