source: trunk/web/addons/job_monarch/lib/extjs/source/widgets/form/TextArea.js @ 619

Last change on this file since 619 was 619, checked in by ramonb, 15 years ago

lib/:

  • added new AJAX dependancies: ExtJS, pChart, Lightbox2
File size: 3.7 KB
Line 
1/*
2 * Ext JS Library 2.2.1
3 * Copyright(c) 2006-2009, Ext JS, LLC.
4 * licensing@extjs.com
5 *
6 * http://extjs.com/license
7 */
8
9/**
10 * @class Ext.form.TextArea
11 * @extends Ext.form.TextField
12 * Multiline text field.  Can be used as a direct replacement for traditional textarea fields, plus adds
13 * support for auto-sizing.
14 * @constructor
15 * Creates a new TextArea
16 * @param {Object} config Configuration options
17 */
18Ext.form.TextArea = Ext.extend(Ext.form.TextField,  {
19    /**
20     * @cfg {Number} growMin The minimum height to allow when grow = true (defaults to 60)
21     */
22    growMin : 60,
23    /**
24     * @cfg {Number} growMax The maximum height to allow when grow = true (defaults to 1000)
25     */
26    growMax: 1000,
27    growAppend : ' \n ',
28    growPad : 0,
29
30    enterIsSpecial : false,
31
32    /**
33     * @cfg {Boolean} preventScrollbars True to prevent scrollbars from appearing regardless of how much text is
34     * in the field (equivalent to setting overflow: hidden, defaults to false)
35     */
36    preventScrollbars: false,
37    /**
38     * @cfg {String/Object} autoCreate A DomHelper element spec, or true for a default element spec (defaults to
39     * {tag: "textarea", style: "width:100px;height:60px;", autocomplete: "off"})
40     */
41
42    // private
43    onRender : function(ct, position){
44        if(!this.el){
45            this.defaultAutoCreate = {
46                tag: "textarea",
47                style:"width:100px;height:60px;",
48                autocomplete: "off"
49            };
50        }
51        Ext.form.TextArea.superclass.onRender.call(this, ct, position);
52        if(this.grow){
53            this.textSizeEl = Ext.DomHelper.append(document.body, {
54                tag: "pre", cls: "x-form-grow-sizer"
55            });
56            if(this.preventScrollbars){
57                this.el.setStyle("overflow", "hidden");
58            }
59            this.el.setHeight(this.growMin);
60        }
61    },
62
63    onDestroy : function(){
64        if(this.textSizeEl){
65            Ext.removeNode(this.textSizeEl);
66        }
67        Ext.form.TextArea.superclass.onDestroy.call(this);
68    },
69
70    fireKey : function(e){
71        if(e.isSpecialKey() && (this.enterIsSpecial || (e.getKey() != e.ENTER || e.hasModifier()))){
72            this.fireEvent("specialkey", this, e);
73        }
74    },
75
76    // private
77    onKeyUp : function(e){
78        if(!e.isNavKeyPress() || e.getKey() == e.ENTER){
79            this.autoSize();
80        }
81        Ext.form.TextArea.superclass.onKeyUp.call(this, e);
82    },
83
84    /**
85     * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
86     * This only takes effect if grow = true, and fires the {@link #autosize} event if the height changes.
87     */
88    autoSize : function(){
89        if(!this.grow || !this.textSizeEl){
90            return;
91        }
92        var el = this.el;
93        var v = el.dom.value;
94        var ts = this.textSizeEl;
95        ts.innerHTML = '';
96        ts.appendChild(document.createTextNode(v));
97        v = ts.innerHTML;
98
99        Ext.fly(ts).setWidth(this.el.getWidth());
100        if(v.length < 1){
101            v = "&#160;&#160;";
102        }else{
103            if(Ext.isIE){
104                v = v.replace(/\n/g, '<p>&#160;</p>');
105            }
106            v += this.growAppend;
107        }
108        ts.innerHTML = v;
109        var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin)+this.growPad);
110        if(h != this.lastHeight){
111            this.lastHeight = h;
112            this.el.setHeight(h);
113            this.fireEvent("autosize", this, h);
114        }
115    }
116});
117Ext.reg('textarea', Ext.form.TextArea);
Note: See TracBrowser for help on using the repository browser.