~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/extjs/source/widgets/form/TextArea.js

  • Committer: parra
  • Date: 2010-03-15 02:39:02 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1433
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Ext JS Library 3.0 RC2
 
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
 * @xtype textarea
 
18
 */
 
19
Ext.form.TextArea = Ext.extend(Ext.form.TextField,  {
 
20
    /**
 
21
     * @cfg {Number} growMin The minimum height to allow when <tt>{@link Ext.form.TextField#grow grow}=true</tt>
 
22
     * (defaults to <tt>60</tt>)
 
23
     */
 
24
    growMin : 60,
 
25
    /**
 
26
     * @cfg {Number} growMax The maximum height to allow when <tt>{@link Ext.form.TextField#grow grow}=true</tt>
 
27
     * (defaults to <tt>1000</tt>)
 
28
     */
 
29
    growMax: 1000,
 
30
    growAppend : '&#160;\n&#160;',
 
31
    growPad : Ext.isWebKit ? -6 : 0,
 
32
 
 
33
    enterIsSpecial : false,
 
34
 
 
35
    /**
 
36
     * @cfg {Boolean} preventScrollbars <tt>true</tt> to prevent scrollbars from appearing regardless of how much text is
 
37
     * in the field (equivalent to setting overflow: hidden, defaults to <tt>false</tt>)
 
38
     */
 
39
    preventScrollbars: false,
 
40
    /**
 
41
     * @cfg {String/Object} autoCreate <p>A {@link Ext.DomHelper DomHelper} element spec, or true for a default
 
42
     * element spec. Used to create the {@link Ext.Component#getEl Element} which will encapsulate this Component.
 
43
     * See <tt>{@link Ext.Component#autoEl autoEl}</tt> for details.  Defaults to:</p>
 
44
     * <pre><code>{tag: "textarea", style: "width:100px;height:60px;", autocomplete: "off"}</code></pre>
 
45
     */
 
46
 
 
47
    // private
 
48
    onRender : function(ct, position){
 
49
        if(!this.el){
 
50
            this.defaultAutoCreate = {
 
51
                tag: "textarea",
 
52
                style:"width:100px;height:60px;",
 
53
                autocomplete: "off"
 
54
            };
 
55
        }
 
56
        Ext.form.TextArea.superclass.onRender.call(this, ct, position);
 
57
        if(this.grow){
 
58
            this.textSizeEl = Ext.DomHelper.append(document.body, {
 
59
                tag: "pre", cls: "x-form-grow-sizer"
 
60
            });
 
61
            if(this.preventScrollbars){
 
62
                this.el.setStyle("overflow", "hidden");
 
63
            }
 
64
            this.el.setHeight(this.growMin);
 
65
        }
 
66
    },
 
67
 
 
68
    onDestroy : function(){
 
69
        Ext.destroy(this.textSizeEl);
 
70
        Ext.form.TextArea.superclass.onDestroy.call(this);
 
71
    },
 
72
 
 
73
    fireKey : function(e){
 
74
        if(e.isSpecialKey() && (this.enterIsSpecial || (e.getKey() != e.ENTER || e.hasModifier()))){
 
75
            this.fireEvent("specialkey", this, e);
 
76
        }
 
77
    },
 
78
 
 
79
    // private
 
80
    onKeyUp : function(e){
 
81
        if(!e.isNavKeyPress() || e.getKey() == e.ENTER){
 
82
            this.autoSize();
 
83
        }
 
84
        Ext.form.TextArea.superclass.onKeyUp.call(this, e);
 
85
    },
 
86
 
 
87
    /**
 
88
     * Automatically grows the field to accomodate the height of the text up to the maximum field height allowed.
 
89
     * This only takes effect if grow = true, and fires the {@link #autosize} event if the height changes.
 
90
     */
 
91
    autoSize: function(){
 
92
        if(!this.grow || !this.textSizeEl){
 
93
            return;
 
94
        }
 
95
        var el = this.el;
 
96
        var v = el.dom.value;
 
97
        var ts = this.textSizeEl;
 
98
        ts.innerHTML = '';
 
99
        ts.appendChild(document.createTextNode(v));
 
100
        v = ts.innerHTML;
 
101
        Ext.fly(ts).setWidth(this.el.getWidth());
 
102
        if(v.length < 1){
 
103
            v = "&#160;&#160;";
 
104
        }else{
 
105
            v += this.growAppend;
 
106
            if(Ext.isIE){
 
107
                v = v.replace(/\n/g, '<br />');
 
108
            }
 
109
        }
 
110
        ts.innerHTML = v;
 
111
        var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin) + this.growPad);
 
112
        if(h != this.lastHeight){
 
113
            this.lastHeight = h;
 
114
            this.el.setHeight(h);
 
115
            this.fireEvent("autosize", this, h);
 
116
        }
 
117
    }
 
118
});
 
119
Ext.reg('textarea', Ext.form.TextArea);
 
 
b'\\ No newline at end of file'