diff options
Diffstat (limited to 'js/lex.js')
| -rw-r--r-- | js/lex.js | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -10,12 +10,14 @@ function Lex (x,y) { this.fg = colors.white this.bg = colors.black this.char = " " + this.opacity = 1 } Lex.prototype.build = function(){ this.span.className = this.css() this.span.innerHTML = this.html() } Lex.prototype.css = function(){ + if (this.opacity == 0) return "fabb" return "f" + letters[mod(this.fg,16)] + "b" + letters[mod(this.bg,16)] } Lex.prototype.html = function(){ @@ -52,23 +54,32 @@ Lex.prototype.clone = function (lex){ this.fg = lex.fg this.bg = lex.bg this.char = lex.char + this.opacity = lex.opacity this.build() } -Lex.prototype.erase = function (lex){ - if (lex.opacity == 0) return +Lex.prototype.copy = function () { + var lex = new Lex (0,0) + lex.clone(this) + return lex +} +Lex.prototype.erase = function (){ this.fg = colors.white this.bg = colors.black this.char = " " + this.opacity = 0 this.build() } -Lex.prototype.fill = function(fg,bg){ +Lex.prototype.fill = function(fg, bg){ this.fg = fg this.bg = bg this.opacity = 1 this.build() } Lex.prototype.eq = function(lex){ - return lex && this.fg == lex.fg && this.bg == lex.fg && this.char == lex.char + return lex && this.fg == lex.fg && this.bg == lex.bg && this.char == lex.char +} +Lex.prototype.ne = function(lex){ + return ! this.eq(lex) } Lex.prototype.clear = function(){ this.bg = 1 @@ -88,9 +99,10 @@ Lex.prototype.focus = function(){ Lex.prototype.blur = function(){ this.span.classList.remove('focused') focused = null + this.onBlur && this.onBlur() } Lex.prototype.demolish = function(){ - this.span.parentNode.removeChild(this.span) + if (this.span.parentNode) { this.span.parentNode.removeChild(this.span) } this.span = null } Lex.prototype.key = function(char, keyCode) { |
