]>
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/_base/sniff", // has("ie") has("mozilla")
10 "dojo/_base/window", // win.doc.selection.createRange
13 "dojo/text!./templates/TextBox.html",
14 ".." // to export dijit._setSelectionRange, remove in 2.0
15 ], function(declare
, domConstruct
, domStyle
, kernel
, lang
, has
, win
,
16 _FormValueWidget
, _TextBoxMixin
, template
, dijit
){
19 var _FormValueWidget = dijit.form._FormValueWidget;
20 var _TextBoxMixin = dijit.form._TextBoxMixin;
26 // A base class for textbox form inputs
28 var TextBox
= declare(/*====="dijit.form.TextBox", =====*/ [_FormValueWidget
, _TextBoxMixin
], {
30 // A base class for textbox form inputs
32 templateString
: template
,
33 _singleNodeTemplate
: '<input class="dijit dijitReset dijitLeft dijitInputField" data-dojo-attach-point="textbox,focusNode" autocomplete="off" type="${type}" ${!nameAttrSetting} />',
35 _buttonInputDisabled
: has("ie") ? "disabled" : "", // allows IE to disallow focus, but Firefox cannot be disabled for mousedown events
37 baseClass
: "dijitTextBox",
39 postMixInProperties: function(){
40 var type
= this.type
.toLowerCase();
41 if(this.templateString
&& this.templateString
.toLowerCase() == "input" || ((type
== "hidden" || type
== "file") && this.templateString
== this.constructor.prototype.templateString
)){
42 this.templateString
= this._singleNodeTemplate
;
44 this.inherited(arguments
);
47 _onInput: function(e
){
48 this.inherited(arguments
);
49 if(this.intermediateChanges
){ // _TextBoxMixin uses onInput
51 // the setTimeout allows the key to post to the widget input box
52 setTimeout(function(){ _this
._handleOnChange(_this
.get('value'), false); }, 0);
56 _setPlaceHolderAttr: function(v
){
57 this._set("placeHolder", v
);
59 this._attachPoints
.push('_phspan');
60 // dijitInputField class gives placeHolder same padding as the input field
61 // parent node already has dijitInputField class but it doesn't affect this <span>
62 // since it's position: absolute.
63 this._phspan
= domConstruct
.create('span',{className
:'dijitPlaceHolder dijitInputField'},this.textbox
,'after');
65 this._phspan
.innerHTML
="";
66 this._phspan
.appendChild(document
.createTextNode(v
));
67 this._updatePlaceHolder();
70 _updatePlaceHolder: function(){
72 this._phspan
.style
.display
=(this.placeHolder
&&!this.focused
&&!this.textbox
.value
)?"":"none";
76 _setValueAttr: function(value
, /*Boolean?*/ priorityChange
, /*String?*/ formattedValue
){
77 this.inherited(arguments
);
78 this._updatePlaceHolder();
81 getDisplayedValue: function(){
83 // Deprecated. Use get('displayedValue') instead.
86 kernel
.deprecated(this.declaredClass
+"::getDisplayedValue() is deprecated. Use set('displayedValue') instead.", "", "2.0");
87 return this.get('displayedValue');
90 setDisplayedValue: function(/*String*/ value
){
92 // Deprecated. Use set('displayedValue', ...) instead.
95 kernel
.deprecated(this.declaredClass
+"::setDisplayedValue() is deprecated. Use set('displayedValue', ...) instead.", "", "2.0");
96 this.set('displayedValue', value
);
100 if(this.disabled
){ return; }
101 this.inherited(arguments
);
102 this._updatePlaceHolder();
105 _onFocus: function(/*String*/ by
){
106 if(this.disabled
|| this.readOnly
){ return; }
107 this.inherited(arguments
);
108 this._updatePlaceHolder();
113 TextBox
= declare(/*===== "dijit.form.TextBox.IEMixin", =====*/ TextBox
, {
114 declaredClass
: "dijit.form.TextBox", // for user code referencing declaredClass
116 _isTextSelected: function(){
117 var range
= win
.doc
.selection
.createRange();
118 var parent
= range
.parentElement();
119 return parent
== this.textbox
&& range
.text
.length
== 0;
122 postCreate: function(){
123 this.inherited(arguments
);
124 // IE INPUT tag fontFamily has to be set directly using STYLE
125 // the setTimeout gives IE a chance to render the TextBox and to deal with font inheritance
126 setTimeout(lang
.hitch(this, function(){
128 var s
= domStyle
.getComputedStyle(this.domNode
); // can throw an exception if widget is immediately destroyed
130 var ff
= s
.fontFamily
;
132 var inputs
= this.domNode
.getElementsByTagName("INPUT");
134 for(var i
=0; i
< inputs
.length
; i
++){
135 inputs
[i
].style
.fontFamily
= ff
;
140 }catch(e
){/*when used in a Dialog, and this is called before the dialog is
141 shown, s.fontFamily would trigger "Invalid Argument" error.*/}
146 // Overrides definition of _setSelectionRange from _TextBoxMixin (TODO: move to _TextBoxMixin.js?)
147 dijit
._setSelectionRange
= _TextBoxMixin
._setSelectionRange = function(/*DomNode*/ element
, /*Number?*/ start
, /*Number?*/ stop
){
148 if(element
.createTextRange
){
149 var r
= element
.createTextRange();
151 r
.moveStart("character", -99999); // move to 0
152 r
.moveStart("character", start
); // delta from 0 is the correct position
153 r
.moveEnd("character", stop
-start
);
157 }else if(has("mozilla")){
158 TextBox
= declare(/*===== "dijit.form.TextBox.MozMixin", =====*/TextBox
, {
159 declaredClass
: "dijit.form.TextBox", // for user code referencing declaredClass
161 _onBlur: function(e
){
162 this.inherited(arguments
);
163 if(this.selectOnClick
){
164 // clear selection so that the next mouse click doesn't reselect
165 this.textbox
.selectionStart
= this.textbox
.selectionEnd
= undefined;
170 TextBox
.prototype.declaredClass
= "dijit.form.TextBox";
172 lang
.setObject("dijit.form.TextBox", TextBox
); // don't do direct assignment, it confuses API doc parser