]> git.wh0rd.org Git - tt-rss.git/blob - lib/dijit/form/TextBox.js.uncompressed.js
update dojo to 1.7.3
[tt-rss.git] / lib / dijit / form / TextBox.js.uncompressed.js
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/_base/sniff", // has("ie") has("mozilla")
10         "dojo/_base/window", // win.doc.selection.createRange
11         "./_FormValueWidget",
12         "./_TextBoxMixin",
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){
17
18 /*=====
19         var _FormValueWidget = dijit.form._FormValueWidget;
20         var _TextBoxMixin = dijit.form._TextBoxMixin;
21 =====*/
22
23         // module:
24         //              dijit/form/TextBox
25         // summary:
26         //              A base class for textbox form inputs
27
28         var TextBox = declare(/*====="dijit.form.TextBox", =====*/ [_FormValueWidget, _TextBoxMixin], {
29                 // summary:
30                 //              A base class for textbox form inputs
31
32                 templateString: template,
33                 _singleNodeTemplate: '<input class="dijit dijitReset dijitLeft dijitInputField" data-dojo-attach-point="textbox,focusNode" autocomplete="off" type="${type}" ${!nameAttrSetting} />',
34
35                 _buttonInputDisabled: has("ie") ? "disabled" : "", // allows IE to disallow focus, but Firefox cannot be disabled for mousedown events
36
37                 baseClass: "dijitTextBox",
38
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;
43                         }
44                         this.inherited(arguments);
45                 },
46
47                 _onInput: function(e){
48                         this.inherited(arguments);
49                         if(this.intermediateChanges){ // _TextBoxMixin uses onInput
50                                 var _this = this;
51                                 // the setTimeout allows the key to post to the widget input box
52                                 setTimeout(function(){ _this._handleOnChange(_this.get('value'), false); }, 0);
53                         }
54                 },
55
56                 _setPlaceHolderAttr: function(v){
57                         this._set("placeHolder", v);
58                         if(!this._phspan){
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');
64                         }
65                         this._phspan.innerHTML="";
66                         this._phspan.appendChild(document.createTextNode(v));
67                         this._updatePlaceHolder();
68                 },
69
70                 _updatePlaceHolder: function(){
71                         if(this._phspan){
72                                 this._phspan.style.display=(this.placeHolder&&!this.focused&&!this.textbox.value)?"":"none";
73                         }
74                 },
75
76                 _setValueAttr: function(value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
77                         this.inherited(arguments);
78                         this._updatePlaceHolder();
79                 },
80
81                 getDisplayedValue: function(){
82                         // summary:
83                         //              Deprecated.  Use get('displayedValue') instead.
84                         // tags:
85                         //              deprecated
86                         kernel.deprecated(this.declaredClass+"::getDisplayedValue() is deprecated. Use set('displayedValue') instead.", "", "2.0");
87                         return this.get('displayedValue');
88                 },
89
90                 setDisplayedValue: function(/*String*/ value){
91                         // summary:
92                         //              Deprecated.  Use set('displayedValue', ...) instead.
93                         // tags:
94                         //              deprecated
95                         kernel.deprecated(this.declaredClass+"::setDisplayedValue() is deprecated. Use set('displayedValue', ...) instead.", "", "2.0");
96                         this.set('displayedValue', value);
97                 },
98
99                 _onBlur: function(e){
100                         if(this.disabled){ return; }
101                         this.inherited(arguments);
102                         this._updatePlaceHolder();
103                 },
104
105                 _onFocus: function(/*String*/ by){
106                         if(this.disabled || this.readOnly){ return; }
107                         this.inherited(arguments);
108                         this._updatePlaceHolder();
109                 }
110         });
111
112         if(has("ie")){
113                 TextBox = declare(/*===== "dijit.form.TextBox.IEMixin", =====*/ TextBox, {
114                         declaredClass: "dijit.form.TextBox",    // for user code referencing declaredClass
115
116                         _isTextSelected: function(){
117                                 var range = win.doc.selection.createRange();
118                                 var parent = range.parentElement();
119                                 return parent == this.textbox && range.text.length == 0;
120                         },
121
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(){
127                                         try{
128                                                 var s = domStyle.getComputedStyle(this.domNode); // can throw an exception if widget is immediately destroyed
129                                                 if(s){
130                                                         var ff = s.fontFamily;
131                                                         if(ff){
132                                                                 var inputs = this.domNode.getElementsByTagName("INPUT");
133                                                                 if(inputs){
134                                                                         for(var i=0; i < inputs.length; i++){
135                                                                                 inputs[i].style.fontFamily = ff;
136                                                                         }
137                                                                 }
138                                                         }
139                                                 }
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.*/}
142                                 }), 0);
143                         }
144                 });
145
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();
150                                 r.collapse(true);
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);
154                                 r.select();
155                         }
156                 }
157         }else if(has("mozilla")){
158                 TextBox = declare(/*===== "dijit.form.TextBox.MozMixin", =====*/TextBox, {
159                         declaredClass: "dijit.form.TextBox",    // for user code referencing declaredClass
160
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;
166                                 }
167                         }
168                 });
169         }else{
170                 TextBox.prototype.declaredClass = "dijit.form.TextBox";
171         }
172         lang.setObject("dijit.form.TextBox", TextBox);  // don't do direct assignment, it confuses API doc parser
173
174         return TextBox;
175 });