123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- define("dijit/form/_TextBoxMixin", [
- "dojo/_base/array",
- "dojo/_base/declare",
- "dojo/dom",
- "dojo/_base/event",
- "dojo/keys",
- "dojo/_base/lang",
- ".."
- ], function(array, declare, dom, event, keys, lang, dijit){
- var _TextBoxMixin = declare("dijit.form._TextBoxMixin", null, {
-
-
-
-
- trim: false,
-
-
- uppercase: false,
-
-
- lowercase: false,
-
-
- propercase: false,
-
-
- maxLength: "",
-
-
- selectOnClick: false,
-
-
-
- placeHolder: "",
- _getValueAttr: function(){
-
-
-
-
-
-
-
-
-
- return this.parse(this.get('displayedValue'), this.constraints);
- },
- _setValueAttr: function(value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var filteredValue;
- if(value !== undefined){
-
-
- filteredValue = this.filter(value);
- if(typeof formattedValue != "string"){
- if(filteredValue !== null && ((typeof filteredValue != "number") || !isNaN(filteredValue))){
- formattedValue = this.filter(this.format(filteredValue, this.constraints));
- }else{ formattedValue = ''; }
- }
- }
- if(formattedValue != null && formattedValue != undefined && ((typeof formattedValue) != "number" || !isNaN(formattedValue)) && this.textbox.value != formattedValue){
- this.textbox.value = formattedValue;
- this._set("displayedValue", this.get("displayedValue"));
- }
- if(this.textDir == "auto"){
- this.applyTextDir(this.focusNode, formattedValue);
- }
- this.inherited(arguments, [filteredValue, priorityChange]);
- },
-
-
-
-
-
-
-
-
-
-
-
-
- displayedValue: "",
- _getDisplayedValueAttr: function(){
-
-
-
-
-
-
-
-
-
-
-
-
- return this.filter(this.textbox.value);
- },
- _setDisplayedValueAttr: function(/*String*/ value){
-
-
-
-
-
-
- if(value === null || value === undefined){ value = '' }
- else if(typeof value != "string"){ value = String(value) }
- this.textbox.value = value;
-
-
-
- this._setValueAttr(this.get('value'), undefined);
- this._set("displayedValue", this.get('displayedValue'));
-
- if(this.textDir == "auto"){
- this.applyTextDir(this.focusNode, value);
- }
- },
- format: function(value /*=====, constraints =====*/){
-
-
-
-
-
-
- return ((value == null || value == undefined) ? "" : (value.toString ? value.toString() : value));
- },
- parse: function(value /*=====, constraints =====*/){
-
-
-
-
-
-
- return value;
- },
- _refreshState: function(){
-
-
-
-
-
-
- },
-
- onInput: function(){},
- __skipInputEvent: false,
- _onInput: function(){
-
-
-
- if(this.textDir == "auto"){
- this.applyTextDir(this.focusNode, this.focusNode.value);
- }
- this._refreshState();
-
- this._set("displayedValue", this.get("displayedValue"));
- },
- postCreate: function(){
-
-
- this.textbox.setAttribute("value", this.textbox.value);
- this.inherited(arguments);
-
-
-
-
-
-
- var handleEvent = function(e){
- var charCode = e.charOrCode || e.keyCode || 229;
- if(e.type == "keydown"){
- switch(charCode){
- case keys.SHIFT:
- case keys.ALT:
- case keys.CTRL:
- case keys.META:
- case keys.CAPS_LOCK:
- return;
- default:
- if(charCode >= 65 && charCode <= 90){ return; }
- }
- }
- if(e.type == "keypress" && typeof charCode != "string"){ return; }
- if(e.type == "input"){
- if(this.__skipInputEvent){
- this.__skipInputEvent = false;
- return;
- }
- }else{
- this.__skipInputEvent = true;
- }
-
- var faux = lang.mixin({}, e, {
- charOrCode: charCode,
- wasConsumed: false,
- preventDefault: function(){
- faux.wasConsumed = true;
- e.preventDefault();
- },
- stopPropagation: function(){ e.stopPropagation(); }
- });
-
- if(this.onInput(faux) === false){
- event.stop(faux);
- }
- if(faux.wasConsumed){ return; }
- setTimeout(lang.hitch(this, "_onInput", faux), 0);
- };
- array.forEach([ "onkeydown", "onkeypress", "onpaste", "oncut", "oninput", "oncompositionend" ], function(event){
- this.connect(this.textbox, event, handleEvent);
- }, this);
- },
- _blankValue: '',
- filter: function(val){
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if(val === null){ return this._blankValue; }
- if(typeof val != "string"){ return val; }
- if(this.trim){
- val = lang.trim(val);
- }
- if(this.uppercase){
- val = val.toUpperCase();
- }
- if(this.lowercase){
- val = val.toLowerCase();
- }
- if(this.propercase){
- val = val.replace(/[^\s]+/g, function(word){
- return word.substring(0,1).toUpperCase() + word.substring(1);
- });
- }
- return val;
- },
- _setBlurValue: function(){
- this._setValueAttr(this.get('value'), true);
- },
- _onBlur: function(e){
- if(this.disabled){ return; }
- this._setBlurValue();
- this.inherited(arguments);
- if(this._selectOnClickHandle){
- this.disconnect(this._selectOnClickHandle);
- }
- },
- _isTextSelected: function(){
- return this.textbox.selectionStart == this.textbox.selectionEnd;
- },
- _onFocus: function(/*String*/ by){
- if(this.disabled || this.readOnly){ return; }
-
-
-
- if(this.selectOnClick && by == "mouse"){
- this._selectOnClickHandle = this.connect(this.domNode, "onmouseup", function(){
-
-
- this.disconnect(this._selectOnClickHandle);
-
-
- if(this._isTextSelected()){
- _TextBoxMixin.selectInputText(this.textbox);
- }
- });
- }
-
-
- this.inherited(arguments);
- this._refreshState();
- },
- reset: function(){
-
-
- this.textbox.value = '';
- this.inherited(arguments);
- },
- _setTextDirAttr: function(/*String*/ textDir){
-
-
-
-
-
-
-
-
-
- if(!this._created
- || this.textDir != textDir){
- this._set("textDir", textDir);
-
- this.applyTextDir(this.focusNode, this.focusNode.value);
- }
- }
- });
- _TextBoxMixin._setSelectionRange = dijit._setSelectionRange = function(/*DomNode*/ element, /*Number?*/ start, /*Number?*/ stop){
- if(element.setSelectionRange){
- element.setSelectionRange(start, stop);
- }
- };
- _TextBoxMixin.selectInputText = dijit.selectInputText = function(/*DomNode*/ element, /*Number?*/ start, /*Number?*/ stop){
-
-
-
- element = dom.byId(element);
- if(isNaN(start)){ start = 0; }
- if(isNaN(stop)){ stop = element.value ? element.value.length : 0; }
- try{
- element.focus();
- _TextBoxMixin._setSelectionRange(element, start, stop);
- }catch(e){ }
- };
- return _TextBoxMixin;
- });
|