Is there any way that I can make a textarea wrap in firefox?
I've tried this:
Code:
calculateLines: function(text){
text = text.split('\n').join('');
temp = '';
chcount = tchs = c= 0;
do {
ch = text.substring(c, c+1); // first character
if(ch == '\n'){ // if character is a hard return
temp += ch;
chcount = 1;
} else if(chcount == 9) { // line has max chacters on this line
temp += '\n' + ch; // go to next line
chcount = 1; // reset chcount
} else {// Not a newline or max characters ...
temp += ch;
chcount++; // so add 1 to chcount
}
} while(++c<text.length);
return temp;
}
updateInput: function(){
val=this.textarea.val();
if($('textarea',this.name).length==0){
return false;
}
lastval=val;
if(!val){
this.textarea.height(14);
return false;
}
input=this.textarea[0];
if(document.selection) {
r = document.selection.createRange();
re = input.createTextRange();
rc = re.duplicate();
re.moveToBookmark(r.getBookmark());
rc.setEndPoint('EndToStart', re);
lastsel = rc.text.length;
} else if(input.selectionStart || input.selectionStart == '0'){
lastsel = input.selectionStart;
}
toomuch=false;
if(val.length>199){
val=this.textarea.data('val');
this.textarea.val(val);
--lastsel;
toomuch=true;
}
text=this.calculateLines(val);
ns=text.split('\n').length;
if(this.textarea.data('ns')!=ns){
this.textarea.height( ns*14 ).data('ns',ns);
}
if(!toomuch && text!=lastval){
this.textarea.val(text);
tmp=text.split('\n').join('');
if(tmp!=lastval && tmp.length<=199 || ns-1==1){
if(Math.round(lastsel/10)*10==lastsel){
++lastsel;
}
this.textarea.data('val',text.split('\n').join(''));
}
}
if(!document.selection){
input.selectionStart=input.selectionEnd=lastsel;
} else {
var selRange = input.createTextRange();
selRange.collapse(true);
selRange.moveStart("character", lastsel);
selRange.moveEnd("character", 0);
selRange.select();
input.focus();
}
}
I am calling updateInput with this:
setInterval(function() { self.updateInput() }, 10);
it's kinda not understandable but maybe someone can figure it out.
thanks.