~crf-team/crf-irp/crf-irp

« back to all changes in this revision

Viewing changes to WebContent/js/extjs-2/source/widgets/form/TextArea.js

  • Committer: Thomas
  • Date: 2010-03-10 23:55:46 UTC
  • Revision ID: thomas@daisybox-port-20100310235546-23635dk6x5asb1ca
Upgrade ExtJs 3.1.1
Upgrade Spring 3.0.1 + dependencies
Change Jawr JS post processor : YUI
Upgrade to last build of dwr 3 trunk 69 revision 3019(after build 116), upgrade jawr-dwr plugin 1.4 unofficiale from jose noheda, Jawr 3.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Ext JS Library 2.3.0
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
 
 */
18
 
Ext.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 : Ext.isWebKit ? -6 : 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
 
        Ext.fly(ts).setWidth(this.el.getWidth());
99
 
        if(v.length < 1){
100
 
            v = "&#160;&#160;";
101
 
        }else{
102
 
            v += this.growAppend;
103
 
            if(Ext.isIE){
104
 
                v = v.replace(/\n/g, '<br />');
105
 
            }
106
 
        }
107
 
        ts.innerHTML = v;
108
 
        var h = Math.min(this.growMax, Math.max(ts.offsetHeight, this.growMin) + this.growPad);
109
 
        if(h != this.lastHeight){
110
 
            this.lastHeight = h;
111
 
            this.el.setHeight(h);
112
 
            this.fireEvent("autosize", this, h);
113
 
        }
114
 
    }
115
 
});
116
 
Ext.reg('textarea', Ext.form.TextArea);
 
 
b'\\ No newline at end of file'