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