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