101 lines
No EOL
4 KiB
HTML
101 lines
No EOL
4 KiB
HTML
<html><head><title>TextArea.js</title><link rel="stylesheet" type="text/css" href="../resources/style.css" media="screen"/></head><body><h1>TextArea.js</h1><pre class="highlighted"><code><i>/**
|
|
* @class Ext.form.TextArea
|
|
* @extends Ext.form.TextField
|
|
* Multiline text field. Can be used as a direct replacement <b>for</b> traditional textarea fields, plus adds
|
|
* support <b>for</b> auto-sizing.
|
|
* @constructor
|
|
* Creates a <b>new</b> TextArea
|
|
* @param {Object} config Configuration options
|
|
*/</i>
|
|
Ext.form.TextArea = <b>function</b>(config){
|
|
Ext.form.TextArea.superclass.constructor.call(<b>this</b>, config);
|
|
<i>// these are provided exchanges <b>for</b> backwards compat</i>
|
|
<i>// minHeight/maxHeight were replaced by growMin/growMax to be</i>
|
|
<i>// compatible <b>with</b> TextField growing config values</i>
|
|
<b>if</b>(this.minHeight !== undefined){
|
|
<b>this</b>.growMin = <b>this</b>.minHeight;
|
|
}
|
|
<b>if</b>(this.maxHeight !== undefined){
|
|
<b>this</b>.growMax = <b>this</b>.maxHeight;
|
|
}
|
|
};
|
|
|
|
Ext.extend(Ext.form.TextArea, Ext.form.TextField, {
|
|
<i>/**
|
|
* @cfg {Number} growMin The minimum height to allow when grow = true (defaults to 60)
|
|
*/</i>
|
|
growMin : 60,
|
|
<i>/**
|
|
* @cfg {Number} growMax The maximum height to allow when grow = true (defaults to 1000)
|
|
*/</i>
|
|
growMax: 1000,
|
|
<i>/**
|
|
* @cfg {Boolean} preventScrollbars True to prevent scrollbars from appearing regardless of how much text is
|
|
* <b>in</b> the field (equivalent to setting overflow: hidden, defaults to false)
|
|
*/</i>
|
|
preventScrollbars: false,
|
|
|
|
<i>// private</i>
|
|
onRender : <b>function</b>(ct, position){
|
|
<b>if</b>(!<b>this</b>.el){
|
|
<b>this</b>.defaultAutoCreate = {
|
|
tag: "textarea",
|
|
style:"width:300px;height:60px;",
|
|
autocomplete: "off"
|
|
};
|
|
}
|
|
Ext.form.TextArea.superclass.onRender.call(<b>this</b>, ct, position);
|
|
<b>if</b>(this.grow){
|
|
<b>this</b>.textSizeEl = Ext.DomHelper.append(document.body, {
|
|
tag: "pre", cls: "x-form-grow-sizer"
|
|
});
|
|
<b>if</b>(this.preventScrollbars){
|
|
<b>this</b>.el.setStyle("overflow", "hidden");
|
|
}
|
|
<b>this</b>.el.setHeight(<b>this</b>.growMin);
|
|
}
|
|
},
|
|
|
|
<i>// private</i>
|
|
onKeyUp : <b>function</b>(e){
|
|
<b>if</b>(!e.isNavKeyPress() || e.getKey() == e.ENTER){
|
|
<b>this</b>.autoSize();
|
|
}
|
|
},
|
|
|
|
<i>/**
|
|
* Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
|
|
* This only takes effect <b>if</b> grow = true and fires the autosize event.
|
|
*/</i>
|
|
autoSize : <b>function</b>(){
|
|
<b>if</b>(!<b>this</b>.grow || !<b>this</b>.textSizeEl){
|
|
<b>return</b>;
|
|
}
|
|
<b>var</b> el = <b>this</b>.el;
|
|
<b>var</b> v = el.dom.value;
|
|
<b>var</b> ts = <b>this</b>.textSizeEl;
|
|
Ext.fly(ts).setWidth(<b>this</b>.el.getWidth());
|
|
<b>if</b>(v.length < 1){
|
|
v = "&#160;&#160;";
|
|
}<b>else</b>{
|
|
v += "&#160;\n&#160;";
|
|
}
|
|
<b>if</b>(Ext.isIE){
|
|
v = v.replace(/\n/g, '<br />');
|
|
}
|
|
ts.innerHTML = v;
|
|
<b>var</b> h = Math.min(<b>this</b>.growMax, Math.max(ts.offsetHeight, <b>this</b>.growMin));
|
|
<b>if</b>(h != <b>this</b>.lastHeight){
|
|
<b>this</b>.lastHeight = h;
|
|
<b>this</b>.el.setHeight(h);
|
|
<b>this</b>.fireEvent("autosize", <b>this</b>, h);
|
|
}
|
|
},
|
|
|
|
<i>// private</i>
|
|
setValue : <b>function</b>(v){
|
|
Ext.form.TextArea.superclass.setValue.call(<b>this</b>, v);
|
|
<b>this</b>.autoSize();
|
|
}
|
|
});</code></pre><hr><div style="font-size:10px;text-align:center;color:gray;">Ext - Copyright © 2006-2007 Ext JS, LLC<br />All rights reserved.</div>
|
|
</body></html> |