Cromon

Untitled

Sep 1st, 2013
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. TextBox.prototype.addCharacter = function (chr) {
  2.     var startStr = "";
  3.     if (this.caretPos > 0) {
  4.         startStr = this.curText.substr(0, this.caretPos);
  5.     }
  6.  
  7.     var endStr = "";
  8.  
  9.     if (this.caretPos < this.curText.length) {
  10.         endStr = this.curText.substr(this.caretPos, (this.curText.length - this.caretPos));
  11.     }
  12.  
  13.     this.curText = startStr + chr + endStr;
  14.     this.caretPos += 1;
  15.  
  16.     var curTotalLength = UI.measureString(this.curText);
  17.     if (curTotalLength <= 230) {
  18.         this.visibleText = this.curText;
  19.         this.visibleTextStart = 0;
  20.     } else {
  21.         if (this.caretPos === this.curText.length) {
  22.             this.visibleText += chr;
  23.             while (UI.measureString(this.visibleText) > 230) {
  24.                 this.visibleText = this.visibleText.substr(1, this.visibleText.length - 1);
  25.                 this.visibleTextStart += 1;
  26.             }
  27.         } else if ((this.caretPos - this.visibleTextStart) >= this.visibleText.length) {
  28.             var add = Math.min(this.curText.length - this.visibleTextStart - this.visibleText.length, 3);
  29.             var endIndex = this.visibleTextStart + this.visibleText.length + add;
  30.  
  31.             this.visibleText = this.curText.substr(this.visibleTextStart, endIndex - this.visibleTextStart);
  32.  
  33.             while (UI.measureString(this.visibleText) > 230) {
  34.                 this.visibleTextStart += 1;
  35.                 this.visibleText = this.curText.substr(this.visibleTextStart, endIndex - this.visibleTextStart);
  36.             }
  37.         } else {
  38.             this.visibleText = this.curText.substr(this.visibleTextStart, Math.min(this.curText.length - this.visibleTextStart, this.visibleText.length + 5));
  39.  
  40.             while (UI.measureString(this.visibleText) > 230) {
  41.                 this.visibleText = this.visibleText.substr(0, this.visibleText.length - 1);
  42.             }
  43.         }
  44.     }
  45.  
  46.     this.updatecaret();
  47. }
Advertisement
Add Comment
Please, Sign In to add comment