source: Dev/trunk/src/client/dijit/form/SimpleTextarea.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.8 KB
Line 
1define([
2        "dojo/_base/declare", // declare
3        "dojo/dom-class", // domClass.add
4        "dojo/sniff", // has("ie") has("opera")
5        "./TextBox"
6], function(declare, domClass, has, TextBox){
7
8        // module:
9        //              dijit/form/SimpleTextarea
10
11        return declare("dijit.form.SimpleTextarea", TextBox, {
12                // summary:
13                //              A simple textarea that degrades, and responds to
14                //              minimal LayoutContainer usage, and works with dijit/form/Form.
15                //              Doesn't automatically size according to input, like Textarea.
16                //
17                // example:
18                //      |       <textarea data-dojo-type="dijit/form/SimpleTextarea" name="foo" value="bar" rows=30 cols=40></textarea>
19                //
20                // example:
21                //      |       new SimpleTextarea({ rows:20, cols:30 }, "foo");
22
23                baseClass: "dijitTextBox dijitTextArea",
24
25                // rows: Number
26                //              The number of rows of text.
27                rows: "3",
28
29                // rows: Number
30                //              The number of characters per line.
31                cols: "20",
32
33                templateString: "<textarea ${!nameAttrSetting} data-dojo-attach-point='focusNode,containerNode,textbox' autocomplete='off'></textarea>",
34
35                postMixInProperties: function(){
36                        // Copy value from srcNodeRef, unless user specified a value explicitly (or there is no srcNodeRef)
37                        // TODO: parser will handle this in 2.0
38                        if(!this.value && this.srcNodeRef){
39                                this.value = this.srcNodeRef.value;
40                        }
41                        this.inherited(arguments);
42                },
43
44                buildRendering: function(){
45                        this.inherited(arguments);
46                        if(has("ie") && this.cols){ // attribute selectors is not supported in IE6
47                                domClass.add(this.textbox, "dijitTextAreaCols");
48                        }
49                },
50
51                filter: function(/*String*/ value){
52                        // Override TextBox.filter to deal with newlines... specifically (IIRC) this is for IE which writes newlines
53                        // as \r\n instead of just \n
54                        if(value){
55                                value = value.replace(/\r/g, "");
56                        }
57                        return this.inherited(arguments);
58                },
59
60                _onInput: function(/*Event?*/ e){
61                        // Override TextBox._onInput() to enforce maxLength restriction
62                        if(this.maxLength){
63                                var maxLength = parseInt(this.maxLength);
64                                var value = this.textbox.value.replace(/\r/g, '');
65                                var overflow = value.length - maxLength;
66                                if(overflow > 0){
67                                        var textarea = this.textbox;
68                                        if(textarea.selectionStart){
69                                                var pos = textarea.selectionStart;
70                                                var cr = 0;
71                                                if(has("opera")){
72                                                        cr = (this.textbox.value.substring(0, pos).match(/\r/g) || []).length;
73                                                }
74                                                this.textbox.value = value.substring(0, pos - overflow - cr) + value.substring(pos - cr);
75                                                textarea.setSelectionRange(pos - overflow, pos - overflow);
76                                        }else if(this.ownerDocument.selection){ //IE
77                                                textarea.focus();
78                                                var range = this.ownerDocument.selection.createRange();
79                                                // delete overflow characters
80                                                range.moveStart("character", -overflow);
81                                                range.text = '';
82                                                // show cursor
83                                                range.select();
84                                        }
85                                }
86                        }
87                        this.inherited(arguments);
88                }
89        });
90});
Note: See TracBrowser for help on using the repository browser.