]>
git.wh0rd.org - tt-rss.git/blob - lib/dijit/form/TextBox.js.uncompressed.js
2 'url:dijit/form/templates/TextBox.html':"<div class=\"dijit dijitReset dijitInline dijitLeft\" id=\"widget_${id}\" role=\"presentation\"\n\t><div class=\"dijitReset dijitInputField dijitInputContainer\"\n\t\t><input class=\"dijitReset dijitInputInner\" data-dojo-attach-point='textbox,focusNode' autocomplete=\"off\"\n\t\t\t${!nameAttrSetting} type='${type}'\n\t/></div\n></div>\n"}});
3 define("dijit/form/TextBox", [
4 "dojo/_base/declare", // declare
5 "dojo/dom-construct", // domConstruct.create
6 "dojo/dom-style", // domStyle.getComputedStyle
7 "dojo/_base/kernel", // kernel.deprecated
8 "dojo/_base/lang", // lang.hitch
9 "dojo/sniff", // has("ie") has("mozilla")
12 "dojo/text!./templates/TextBox.html",
13 "../main" // to export dijit._setSelectionRange, remove in 2.0
14 ], function(declare
, domConstruct
, domStyle
, kernel
, lang
, has
,
15 _FormValueWidget
, _TextBoxMixin
, template
, dijit
){
20 var TextBox
= declare("dijit.form.TextBox", [_FormValueWidget
, _TextBoxMixin
], {
22 // A base class for textbox form inputs
24 templateString
: template
,
25 _singleNodeTemplate
: '<input class="dijit dijitReset dijitLeft dijitInputField" data-dojo-attach-point="textbox,focusNode" autocomplete="off" type="${type}" ${!nameAttrSetting} />',
27 _buttonInputDisabled
: has("ie") ? "disabled" : "", // allows IE to disallow focus, but Firefox cannot be disabled for mousedown events
29 baseClass
: "dijitTextBox",
31 postMixInProperties: function(){
32 var type
= this.type
.toLowerCase();
33 if(this.templateString
&& this.templateString
.toLowerCase() == "input" || ((type
== "hidden" || type
== "file") && this.templateString
== this.constructor.prototype.templateString
)){
34 this.templateString
= this._singleNodeTemplate
;
36 this.inherited(arguments
);
39 postCreate: function(){
40 this.inherited(arguments
);
43 // IE INPUT tag fontFamily has to be set directly using STYLE
44 // the defer gives IE a chance to render the TextBox and to deal with font inheritance
45 this.defer(function(){
47 var s
= domStyle
.getComputedStyle(this.domNode
); // can throw an exception if widget is immediately destroyed
49 var ff
= s
.fontFamily
;
51 var inputs
= this.domNode
.getElementsByTagName("INPUT");
53 for(var i
=0; i
< inputs
.length
; i
++){
54 inputs
[i
].style
.fontFamily
= ff
;
59 }catch(e
){/*when used in a Dialog, and this is called before the dialog is
60 shown, s.fontFamily would trigger "Invalid Argument" error.*/}
65 _onInput: function(e
){
66 this.inherited(arguments
);
67 if(this.intermediateChanges
){ // _TextBoxMixin uses onInput
68 // allow the key to post to the widget input box
69 this.defer(function(){ this._handleOnChange(this.get('value'), false); });
73 _setPlaceHolderAttr: function(v
){
74 this._set("placeHolder", v
);
76 this._attachPoints
.push('_phspan');
77 // dijitInputField class gives placeHolder same padding as the input field
78 // parent node already has dijitInputField class but it doesn't affect this <span>
79 // since it's position: absolute.
80 this._phspan
= domConstruct
.create('span',{ onmousedown:function(e
){ e
.preventDefault(); }, className
:'dijitPlaceHolder dijitInputField'},this.textbox
,'after');
82 this._phspan
.innerHTML
="";
83 this._phspan
.appendChild(this._phspan
.ownerDocument
.createTextNode(v
));
84 this._updatePlaceHolder();
87 _updatePlaceHolder: function(){
89 this._phspan
.style
.display
=(this.placeHolder
&&!this.focused
&&!this.textbox
.value
)?"":"none";
93 _setValueAttr: function(value
, /*Boolean?*/ priorityChange
, /*String?*/ formattedValue
){
94 this.inherited(arguments
);
95 this._updatePlaceHolder();
98 getDisplayedValue: function(){
100 // Deprecated. Use get('displayedValue') instead.
103 kernel
.deprecated(this.declaredClass
+"::getDisplayedValue() is deprecated. Use get('displayedValue') instead.", "", "2.0");
104 return this.get('displayedValue');
107 setDisplayedValue: function(/*String*/ value
){
109 // Deprecated. Use set('displayedValue', ...) instead.
112 kernel
.deprecated(this.declaredClass
+"::setDisplayedValue() is deprecated. Use set('displayedValue', ...) instead.", "", "2.0");
113 this.set('displayedValue', value
);
116 _onBlur: function(e
){
117 if(this.disabled
){ return; }
118 this.inherited(arguments
);
119 this._updatePlaceHolder();
122 if(this.selectOnClick
){
123 // clear selection so that the next mouse click doesn't reselect
124 this.textbox
.selectionStart
= this.textbox
.selectionEnd
= undefined;
129 _onFocus: function(/*String*/ by
){
130 if(this.disabled
|| this.readOnly
){ return; }
131 this.inherited(arguments
);
132 this._updatePlaceHolder();
137 TextBox
.prototype._isTextSelected = function(){
138 var range
= this.ownerDocument
.selection
.createRange();
139 var parent
= range
.parentElement();
140 return parent
== this.textbox
&& range
.text
.length
> 0;
143 // Overrides definition of _setSelectionRange from _TextBoxMixin (TODO: move to _TextBoxMixin.js?)
144 dijit
._setSelectionRange
= _TextBoxMixin
._setSelectionRange = function(/*DomNode*/ element
, /*Number?*/ start
, /*Number?*/ stop
){
145 if(element
.createTextRange
){
146 var r
= element
.createTextRange();
148 r
.moveStart("character", -99999); // move to 0
149 r
.moveStart("character", start
); // delta from 0 is the correct position
150 r
.moveEnd("character", stop
-start
);