]>
Commit | Line | Data |
---|---|---|
f0cfe83e AD |
1 | require({cache:{ |
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") | |
10 | "./_FormValueWidget", | |
11 | "./_TextBoxMixin", | |
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){ | |
16 | ||
17 | // module: | |
18 | // dijit/form/TextBox | |
19 | ||
20 | var TextBox = declare("dijit.form.TextBox", [_FormValueWidget, _TextBoxMixin], { | |
21 | // summary: | |
22 | // A base class for textbox form inputs | |
23 | ||
24 | templateString: template, | |
25 | _singleNodeTemplate: '<input class="dijit dijitReset dijitLeft dijitInputField" data-dojo-attach-point="textbox,focusNode" autocomplete="off" type="${type}" ${!nameAttrSetting} />', | |
26 | ||
27 | _buttonInputDisabled: has("ie") ? "disabled" : "", // allows IE to disallow focus, but Firefox cannot be disabled for mousedown events | |
28 | ||
29 | baseClass: "dijitTextBox", | |
30 | ||
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; | |
35 | } | |
36 | this.inherited(arguments); | |
37 | }, | |
38 | ||
39 | postCreate: function(){ | |
40 | this.inherited(arguments); | |
41 | ||
42 | if(has("ie") < 9){ | |
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(){ | |
46 | try{ | |
47 | var s = domStyle.getComputedStyle(this.domNode); // can throw an exception if widget is immediately destroyed | |
48 | if(s){ | |
49 | var ff = s.fontFamily; | |
50 | if(ff){ | |
51 | var inputs = this.domNode.getElementsByTagName("INPUT"); | |
52 | if(inputs){ | |
53 | for(var i=0; i < inputs.length; i++){ | |
54 | inputs[i].style.fontFamily = ff; | |
55 | } | |
56 | } | |
57 | } | |
58 | } | |
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.*/} | |
61 | }); | |
62 | } | |
63 | }, | |
64 | ||
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); }); | |
70 | } | |
71 | }, | |
72 | ||
73 | _setPlaceHolderAttr: function(v){ | |
74 | this._set("placeHolder", v); | |
75 | if(!this._phspan){ | |
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'); | |
81 | } | |
82 | this._phspan.innerHTML=""; | |
83 | this._phspan.appendChild(this._phspan.ownerDocument.createTextNode(v)); | |
84 | this._updatePlaceHolder(); | |
85 | }, | |
86 | ||
87 | _updatePlaceHolder: function(){ | |
88 | if(this._phspan){ | |
89 | this._phspan.style.display=(this.placeHolder&&!this.focused&&!this.textbox.value)?"":"none"; | |
90 | } | |
91 | }, | |
92 | ||
93 | _setValueAttr: function(value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){ | |
94 | this.inherited(arguments); | |
95 | this._updatePlaceHolder(); | |
96 | }, | |
97 | ||
98 | getDisplayedValue: function(){ | |
99 | // summary: | |
100 | // Deprecated. Use get('displayedValue') instead. | |
101 | // tags: | |
102 | // deprecated | |
103 | kernel.deprecated(this.declaredClass+"::getDisplayedValue() is deprecated. Use get('displayedValue') instead.", "", "2.0"); | |
104 | return this.get('displayedValue'); | |
105 | }, | |
106 | ||
107 | setDisplayedValue: function(/*String*/ value){ | |
108 | // summary: | |
109 | // Deprecated. Use set('displayedValue', ...) instead. | |
110 | // tags: | |
111 | // deprecated | |
112 | kernel.deprecated(this.declaredClass+"::setDisplayedValue() is deprecated. Use set('displayedValue', ...) instead.", "", "2.0"); | |
113 | this.set('displayedValue', value); | |
114 | }, | |
115 | ||
116 | _onBlur: function(e){ | |
117 | if(this.disabled){ return; } | |
118 | this.inherited(arguments); | |
119 | this._updatePlaceHolder(); | |
120 | ||
121 | if(has("mozilla")){ | |
122 | if(this.selectOnClick){ | |
123 | // clear selection so that the next mouse click doesn't reselect | |
124 | this.textbox.selectionStart = this.textbox.selectionEnd = undefined; | |
125 | } | |
126 | } | |
127 | }, | |
128 | ||
129 | _onFocus: function(/*String*/ by){ | |
130 | if(this.disabled || this.readOnly){ return; } | |
131 | this.inherited(arguments); | |
132 | this._updatePlaceHolder(); | |
133 | } | |
134 | }); | |
135 | ||
136 | if(has("ie")){ | |
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; | |
141 | }; | |
142 | ||
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(); | |
147 | r.collapse(true); | |
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); | |
151 | r.select(); | |
152 | } | |
153 | } | |
154 | } | |
155 | ||
156 | return TextBox; | |
157 | }); |