include('/jsc/fancy/events.class.js'); function input(obj,invoker) { this.simple_input = quickerElement('input','dynamic_input','','type','text'); this.multi_input = quickerElement('textarea','dynamic_input',''); this.input; this.initHeight = 0; this.newLineCount = 0; this.listener; this.visible = false; this.shiftDown = false; this.ctrlDown = false; this.altDown = false; this.init = function(obj,invoker,options) { this.listener = new eventsClass('input'); this.reset(); if(options){ this.options = options; } this.obj = obj; this.obj.input = this; this.listener.subscribe(invoker); this.lastValue = this.obj.innerHTML.replace(//g,'\n'); this.lastValue = strip_tags(this.lastValue); //this.lastValue = this.lastValue.replace(/(.)[\n]?$/g,'\\1'); if(!this.options.multiplyer){ this.options.multiplyer = Math.round(getStyle(obj,'font-size','int')*0.7); } if(this.options.multiline){ this.input = this.multi_input; setStyle(this.input,'width',getRealWidth(this.obj),'px'); } else { this.input = this.simple_input; setStyle(this.input,'width',this.lastValue.length*this.options.multiplyer+10,'px'); } this.input.value = this.lastValue; this.input.fancy = this; this.initHeight = getRealHeight(this.obj); setStyle(this.input,'height',this.initHeight,'px'); this.obj.innerHTML = ''; this.input = this.obj.appendChild(this.input); if(this.options.multiline){ if(this.input.clientHeight != this.input.scrollHeight){ setStyle(this.input,'height',this.input.scrollHeight,'px'); } } this.obj.edit = true; this.input.focus(); this.input.select(); this.visible = true; this.listener.trigger('inputinit'); } this.reset = function() { this.options = new Object(); this.newLineCount = 0; this.listener.clear(); this.shiftDown = false; this.ctrlDown = false; this.altDown = false; } this.simple_input.onblur = this.multi_input.onblur = function(){ if(!this.fancy.visible){ return ; } this.fancy.trigger('blur'); } this.onblur = function() { if(!this.input || !this.visible){ return false; } if(this.obj.input){ this.obj.input = false; } this.listener.trigger('inputblur'); var newValue = strip_tags(this.input.value); if(this.options.multiline){ newValue = newValue.replace(/\n/g,"
"); } if(newValue.replace(/\s/g,'') == ''){ newValue = this.lastValue; } if(this.obj){ this.obj.edit = false; this.obj.innerHTML = newValue; } this.visible = false; this.listener.trigger('editover',{'newValue': newValue, 'oldValue': this.lastValue, 'action': this.options.action}); } this.simple_input.onkeydown = this.multi_input.onkeydown = function(e){ if(!e){ var e = window.event; } this.fancy.checkKey(true,e); this.fancy.listener.trigger('keydown',e); if((e.keyCode == 13 && !this.fancy.options.multiline) || (e.keyCode == 13 && this.fancy.options.multiline && (this.fancy.ctrlDown || this.fancy.shiftDown))){ return this.onblur(); } if(e.keyCode == 27){ this.value = this.fancy.lastValue; return this.onblur(); } if(this.value.length > this.fancy.options.maxLength){ //substring this.value.length--; } } this.checkKey = function(down,e) { if(!e){ var e = window.event; } switch(e.keyCode){ case 16: this.shiftDown = down; break; case 17: this.ctrlDown = down; break; case 18: this.altDown = down; break; } } this.simple_input.onkeyup = function(e) { setStyle(this,'width',this.value.length*this.fancy.options.multiplyer+10,'px'); this.fancy.checkKey(false,e); } this.multi_input.onkeyup = function(e){ if(this.clientHeight != this.scrollHeight){ setStyle(this,'height',this.scrollHeight,'px'); } this.fancy.checkKey(false,e); } } input.prototype = new simple_object;