function obfuscatePassword(value) { var res=[]; for(var i=0; i=1) { return value.charAt(0).toUpperCase() + value.slice(1); } else return ''; } var StringInput = Class.create({ initialize: function(input) { this.input=input; this.ID_=this.input.readAttribute('id'); this.mode='input'; this.input.JSControl=this; this.passwd=this.input.readAttribute('password'); var trim=this.input.readAttribute('trim'); if(trim=='yes' || trim=='true') this.doTrim=true; this.capitalizeFirst=this.input.readAttribute('capitalize-first'); this.capitalizeAll=this.input.readAttribute('capitalize-all'); this.prevent_enter_propagation = false; // var url = Element.readAttribute(this.input, "url"); // if (url && url.length > 0) new DynamicAutosuggest(this); $(this.input).observe('change', this.OnChange.bind(this)); if(Prototype.Browser.IE) { $(this.input).observe('keydown', this.OnInput.bind(this)); } else { $(this.input).observe('input', this.OnInput.bind(this)); } $(this.input).observe('drop', this.OnChange.bind(this)); $(this.input).observe('blur', this.OnChange.bind(this)); $(this.input).observe('keydown', this.OnKeyDown.bind(this)); this.parent=input.parentNode; this.span=new Element('span', {id: this.ID_, localid: this.input.readAttribute('localid'), 'class': this.input.className}); this.span.JSControl=this; this.CapitalizeInputValueIfNecessary(); this.UpdateSpan(); this.visibility='yes'; // initial visibility var vis=this.input.readAttribute('visibility'); this.setVisibility(vis); }, OnChange: function(evt) { this.CapitalizeInputValueIfNecessary(); this.UpdateSpan(); new AEvent("CHANGE", {}, this); }, OnClick: function(evt) { new AEvent("CLICK", {}, this); }, OnInput: function(evt) { var fn = function () { new AEvent("INPUT", {}, this); }; fn.bind(this).defer(); }, OnKeyDown: function(evt) { var key = evt.which || evt.keyCode; new AEvent("KEYDOWN", [key], this); if (key == Event.KEY_RETURN) { if (this.prevent_enter_propagation) evt.stop(); new AEvent("KEY_ENTER", [key], this); } }, SetValue: function(value) { if (value instanceof Optional && value.Value() != undefined) { this.input.value=value.Value(); } // second check is not necessary: string cannot be undefined // mvel@ else if (typeof(value) == 'string' && value!=undefined) { this.input.value=value; } else { this.input.value=''; } this.CapitalizeInputValueIfNecessary(); this.UpdateSpan(); }, CapitalizeInputValueIfNecessary: function() { if(this.capitalizeFirst=='yes') { this.input.value=capitalizeFirstLetter(this.input.value); } if(this.capitalizeAll=='yes'){ this.input.value=this.input.value.toUpperCase(); } }, UpdateSpan: function() { if(this.passwd=='yes') this.span.innerHTML=obfuscatePassword(this.input.value); else this.span.innerHTML=this.input.value.replace(/&/g,'&').replace(//g,'>'); }, Value: function() { if(typeof(this.input.value) == 'undefined' || this.input.value===null) return optional(undefined); if (this.input.value === "") return optional(undefined); if(this.doTrim) { var val=this.input.value.toString(); val=val.replace(/^\s*/g, ''); val=val.replace(/\s*$/g, ''); if(val==="") return optional(undefined); return optional(val); } return optional(this.input.value.toString()); }, setVisibility: function(sValue) { var old=this.visibility; if (sValue==old) return; // nothing changed if (!(sValue=='yes' || sValue=='vo' || sValue=='ro' || sValue=='link' || sValue=='no')) sValue='yes'; if (sValue!='no') { if (sValue=='yes' || sValue=='ro') { if ((old=='no' || old=='vo' || old=='link') && this.mode=='span') { this.parent.replaceChild(this.input, this.span); this.mode='input'; } } else if (sValue=='vo' || sValue=='link') { if ((old=='no' || old=='yes' || old=='ro') && this.mode=='input') { this.parent.replaceChild(this.span, this.input); this.mode='span'; } if (sValue=='link') $(this.span).observe('click', this.OnClick.bind(this)); } // ensure input is disabled if (sValue=='yes') this.input.writeAttribute('disabled', false); else if (sValue=='ro') this.input.writeAttribute('disabled', 'disabled'); } // finally, write attribute value this.visibility=sValue; }, SetAttribute: function(sName, sValue) { if(sName=='visibility') this.setVisibility(sValue); else if (sName == "prevent_enter_propagation" && sValue == "yes") this.prevent_enter_propagation = true; this.input.writeAttribute(sName, sValue); this.span.writeAttribute(sName, sValue); }, SetTabOrder: function(nTabBase) { this.input.writeAttribute('tabindex', nTabBase); return ++nTabBase; }, Focus: function() { this.input.focus(); }, ID: function() { return this.ID_; } });