From bca271fbe65f008d686544e943243ca447430ae7 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 13 Jun 2013 02:26:09 -0500 Subject: [PATCH] refactor attr swap. --- lib/widget.js | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index 8900298..1563757 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -1430,40 +1430,13 @@ List.prototype.select = function(index) { if (this.selected === index && this._listInitialized) return; this._listInitialized = true; - if (this.selectedBg) { - this.items[this.selected].bg = this.bg; - this.items[index].bg = this.selectedBg; - } - - if (this.selectedFg) { - this.items[this.selected].fg = this.fg; - this.items[index].fg = this.selectedFg; - } - - if (this.selectedBold != null) { - this.items[this.selected].bold = this.bold; - this.items[index].bold = this.selectedBold; - } - - if (this.selectedUnderline != null) { - this.items[this.selected].underline = this.underline; - this.items[index].underline = this.selectedUnderline; - } - - if (this.selectedBlink != null) { - this.items[this.selected].blink = this.blink; - this.items[index].blink = this.selectedBlink; - } - - if (this.selectedInverse != null) { - this.items[this.selected].inverse = this.inverse; - this.items[index].inverse = this.selectedInverse; - } - - if (this.selectedInvisible != null) { - this.items[this.selected].invisible = this.invisible; - this.items[index].invisible = this.selectedInvisible; - } + ['bg', 'fg', 'bold', 'underline', + 'blink', 'inverse', 'invisible'].forEach(function(name) { + this.items[this.selected][name] = this[name]; + this.items[index][name] = this['selected' + + name.substring(0, 1).toUpperCase() + + name.substring(1)]; + }, this); var diff = index - this.selected; this.selected = index;