| 1 |
define([ |
| 2 |
"dojo/_base/declare", |
| 3 |
"dojo/dom-construct", |
| 4 |
"dojo/dom-style", |
| 5 |
"dojo/_base/kernel", |
| 6 |
"dojo/_base/lang", |
| 7 |
"dojo/on", |
| 8 |
"dojo/sniff", |
| 9 |
"./_FormValueWidget", |
| 10 |
"./_TextBoxMixin", |
| 11 |
"dojo/text!./templates/TextBox.html", |
| 12 |
"../main" |
| 13 |
], function(declare, domConstruct, domStyle, kernel, lang, on, has, |
| 14 |
_FormValueWidget, _TextBoxMixin, template, dijit){ |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
var TextBox = declare("dijit.form.TextBox" + (has("dojo-bidi") ? "_NoBidi" : ""), [_FormValueWidget, _TextBoxMixin], { |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
templateString: template, |
| 24 |
_singleNodeTemplate: '<input class="dijit dijitReset dijitLeft dijitInputField" data-dojo-attach-point="textbox,focusNode" autocomplete="off" type="${type}" ${!nameAttrSetting} />', |
| 25 |
|
| 26 |
_buttonInputDisabled: has("ie") ? "disabled" : "", |
| 27 |
|
| 28 |
baseClass: "dijitTextBox", |
| 29 |
|
| 30 |
postMixInProperties: function(){ |
| 31 |
var type = this.type.toLowerCase(); |
| 32 |
if(this.templateString && this.templateString.toLowerCase() == "input" || ((type == "hidden" || type == "file") && this.templateString == this.constructor.prototype.templateString)){ |
| 33 |
this.templateString = this._singleNodeTemplate; |
| 34 |
} |
| 35 |
this.inherited(arguments); |
| 36 |
}, |
| 37 |
|
| 38 |
postCreate: function(){ |
| 39 |
this.inherited(arguments); |
| 40 |
|
| 41 |
if(has("ie") < 9){ |
| 42 |
|
| 43 |
|
| 44 |
this.defer(function(){ |
| 45 |
try{ |
| 46 |
var s = domStyle.getComputedStyle(this.domNode); |
| 47 |
if(s){ |
| 48 |
var ff = s.fontFamily; |
| 49 |
if(ff){ |
| 50 |
var inputs = this.domNode.getElementsByTagName("INPUT"); |
| 51 |
if(inputs){ |
| 52 |
for(var i=0; i < inputs.length; i++){ |
| 53 |
inputs[i].style.fontFamily = ff; |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
}catch(e){ |
| 59 |
} |
| 60 |
}); |
| 61 |
} |
| 62 |
}, |
| 63 |
|
| 64 |
_setPlaceHolderAttr: function(v){ |
| 65 |
this._set("placeHolder", v); |
| 66 |
if(!this._phspan){ |
| 67 |
this._attachPoints.push('_phspan'); |
| 68 |
this._phspan = domConstruct.create('span', { |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
className: 'dijitPlaceHolder dijitInputField' |
| 73 |
}, this.textbox, 'after'); |
| 74 |
this.own( |
| 75 |
on(this._phspan, "mousedown", function(evt){ evt.preventDefault(); }), |
| 76 |
on(this._phspan, "touchend, pointerup, MSPointerUp", lang.hitch(this, function(){ |
| 77 |
|
| 78 |
|
| 79 |
this.focus(); |
| 80 |
})) |
| 81 |
); |
| 82 |
} |
| 83 |
this._phspan.innerHTML=""; |
| 84 |
this._phspan.appendChild(this._phspan.ownerDocument.createTextNode(v)); |
| 85 |
this._updatePlaceHolder(); |
| 86 |
}, |
| 87 |
|
| 88 |
_onInput: function( evt){ |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
this.inherited(arguments); |
| 93 |
this._updatePlaceHolder(); |
| 94 |
}, |
| 95 |
|
| 96 |
_updatePlaceHolder: function(){ |
| 97 |
if(this._phspan){ |
| 98 |
this._phspan.style.display = (this.placeHolder && !this.textbox.value) ? "" : "none"; |
| 99 |
} |
| 100 |
}, |
| 101 |
|
| 102 |
_setValueAttr: function(value, priorityChange, formattedValue){ |
| 103 |
this.inherited(arguments); |
| 104 |
this._updatePlaceHolder(); |
| 105 |
}, |
| 106 |
|
| 107 |
getDisplayedValue: function(){ |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
kernel.deprecated(this.declaredClass+"::getDisplayedValue() is deprecated. Use get('displayedValue') instead.", "", "2.0"); |
| 113 |
return this.get('displayedValue'); |
| 114 |
}, |
| 115 |
|
| 116 |
setDisplayedValue: function( value){ |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
kernel.deprecated(this.declaredClass+"::setDisplayedValue() is deprecated. Use set('displayedValue', ...) instead.", "", "2.0"); |
| 122 |
this.set('displayedValue', value); |
| 123 |
}, |
| 124 |
|
| 125 |
_onBlur: function(e){ |
| 126 |
if(this.disabled){ return; } |
| 127 |
this.inherited(arguments); |
| 128 |
this._updatePlaceHolder(); |
| 129 |
|
| 130 |
if(has("mozilla")){ |
| 131 |
if(this.selectOnClick){ |
| 132 |
|
| 133 |
this.textbox.selectionStart = this.textbox.selectionEnd = undefined; |
| 134 |
} |
| 135 |
} |
| 136 |
}, |
| 137 |
|
| 138 |
_onFocus: function( by){ |
| 139 |
if(this.disabled || this.readOnly){ return; } |
| 140 |
this.inherited(arguments); |
| 141 |
this._updatePlaceHolder(); |
| 142 |
} |
| 143 |
}); |
| 144 |
|
| 145 |
if(has("ie") < 9){ |
| 146 |
TextBox.prototype._isTextSelected = function(){ |
| 147 |
var range = this.ownerDocument.selection.createRange(); |
| 148 |
var parent = range.parentElement(); |
| 149 |
return parent == this.textbox && range.text.length > 0; |
| 150 |
}; |
| 151 |
|
| 152 |
|
| 153 |
dijit._setSelectionRange = _TextBoxMixin._setSelectionRange = function( element, start, stop){ |
| 154 |
if(element.createTextRange){ |
| 155 |
var r = element.createTextRange(); |
| 156 |
r.collapse(true); |
| 157 |
r.moveStart("character", -99999); |
| 158 |
r.moveStart("character", start); |
| 159 |
r.moveEnd("character", stop-start); |
| 160 |
r.select(); |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
if(has("dojo-bidi")){ |
| 166 |
TextBox = declare("dijit.form.TextBox", TextBox, { |
| 167 |
_setPlaceHolderAttr: function(v){ |
| 168 |
this.inherited(arguments); |
| 169 |
this.applyTextDir(this._phspan); |
| 170 |
} |
| 171 |
}); |
| 172 |
} |
| 173 |
|
| 174 |
return TextBox; |
| 175 |
}); |