]>
git.wh0rd.org - tt-rss.git/blob - 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")
6 ], function(declare
, domClass
, has
, TextBox
){
9 // dijit/form/SimpleTextarea
12 return declare("dijit.form.SimpleTextarea", TextBox
, {
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.
19 // | <textarea data-dojo-type="dijit/form/SimpleTextarea" name="foo" value="bar" rows=30 cols=40></textarea>
22 // | new SimpleTextarea({ rows:20, cols:30 }, "foo");
24 baseClass
: "dijitTextBox dijitTextArea",
27 // The number of rows of text.
31 // The number of characters per line.
34 templateString
: "<textarea ${!nameAttrSetting} data-dojo-attach-point='focusNode,containerNode,textbox' autocomplete='off'></textarea>",
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
;
42 this.inherited(arguments
);
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");
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
56 value
= value
.replace(/\r/g,"");
58 return this.inherited(arguments
);
61 _onInput: function(/*Event?*/ e
){
62 // Override TextBox._onInput() to enforce maxLength restriction
64 var maxLength
= parseInt(this.maxLength
);
65 var value
= this.textbox
.value
.replace(/\r/g,'');
66 var overflow
= value
.length
- maxLength
;
68 var textarea
= this.textbox
;
69 if(textarea
.selectionStart
){
70 var pos
= textarea
.selectionStart
;
73 cr
= (this.textbox
.value
.substring(0,pos
).match(/\r/g) || []).length
;
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
79 var range
= this.ownerDocument
.selection
.createRange();
80 // delete overflow characters
81 range
.moveStart("character", -overflow
);
88 this.inherited(arguments
);