3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.com/license
17 <div id="cls-Ext.ux.FieldLabeler"></div>/**
18 * @class Ext.ux.FieldLabeler
19 * <p>A plugin for Field Components which renders standard Ext form wrapping and labels
20 * round the Field at render time regardless of the layout of the Container.</p>
25 plugins: [ Ext.ux.FieldLabeler ],
27 fieldLabel: 'Select type',
32 Ext.ux.FieldLabeler = (function(){
34 // Pulls a named property down from the first ancestor Container it's found in
35 function getParentProperty(propName) {
36 for (var p = this.ownerCt; p; p = p.ownerCt) {
45 // Add behaviour at important points in the Field's lifecycle.
47 // Replace the Field's onRender method with a sequence that calls the plugin's onRender after the Field's onRender
48 f.onRender = f.onRender.createSequence(this.onRender);
50 // We need to completely override the onResize method because of the complexity
51 f.onResize = this.onResize;
53 // Replace the Field's onDestroy method with a sequence that calls the plugin's onDestroy after the Field's onRender
54 f.onDestroy = f.onDestroy.createSequence(this.onDestroy);
57 onRender: function() {
58 // Do nothing if being rendered by a form layout
60 if (this.ownerCt.layout instanceof Ext.layout.FormLayout) {
65 this.resizeEl = (this.wrap || this.el).wrap({
66 cls: 'x-form-element',
67 style: (Ext.isIE || Ext.isOpera) ? 'position:absolute;top:0;left:0;overflow:visible' : ''
69 this.positionEl = this.itemCt = this.resizeEl.wrap({
72 if (this.nextSibling()) {
76 bottom: this.positionEl.getMargins('b'),
80 this.actionMode = 'itemCt';
82 // If our Container is hiding labels, then we're done!
83 if (!Ext.isDefined(this.hideLabels)) {
84 this.hideLabels = getParentProperty.call(this, "hideLabels");
86 if (this.hideLabels) {
87 this.resizeEl.setStyle('padding-left', '0px');
91 // Collect the info we need to render the label from our Container.
92 if (!Ext.isDefined(this.labelSeparator)) {
93 this.labelSeparator = getParentProperty.call(this, "labelSeparator");
95 if (!Ext.isDefined(this.labelPad)) {
96 this.labelPad = getParentProperty.call(this, "labelPad");
98 if (!Ext.isDefined(this.labelAlign)) {
99 this.labelAlign = getParentProperty.call(this, "labelAlign") || 'left';
101 this.itemCt.addClass('x-form-label-' + this.labelAlign);
103 if(this.labelAlign == 'top'){
104 if (!this.labelWidth) {
105 this.labelWidth = 'auto';
107 this.resizeEl.setStyle('padding-left', '0px');
109 if (!Ext.isDefined(this.labelWidth)) {
110 this.labelWidth = getParentProperty.call(this, "labelWidth") || 100;
112 this.resizeEl.setStyle('padding-left', (this.labelWidth + (this.labelPad || 5)) + 'px');
113 this.labelWidth += 'px';
116 this.label = this.itemCt.insertFirst({
118 cls: 'x-form-item-label',
120 width: this.labelWidth
122 html: this.fieldLabel + (this.labelSeparator || ':')
127 // Ensure the input field is sized to fit in the content area of the resizeEl (to the right of its padding-left)
128 // We perform all necessary sizing here. We do NOT call the current class's onResize because we need this control
129 // we skip that and go up the hierarchy to Ext.form.Field
130 onResize: function(w, h) {
131 Ext.form.Field.prototype.onResize.apply(this, arguments);
132 w -= this.resizeEl.getPadding('l');
133 if (this.getTriggerWidth) {
134 this.wrap.setWidth(w);
135 this.el.setWidth(w - this.getTriggerWidth());
139 if (this.el.dom.tagName.toLowerCase() == 'textarea') {
140 var h = this.resizeEl.getHeight(true);
141 if (!this.hideLabels && (this.labelAlign == 'top')) {
142 h -= this.label.getHeight();
144 this.el.setHeight(h);
149 // Ensure that we clean up on destroy.
150 onDestroy: function() {
151 this.itemCt.remove();