refactor attr swap.

This commit is contained in:
Christopher Jeffrey 2013-06-13 02:26:09 -05:00
parent 607013b22b
commit bca271fbe6
1 changed files with 7 additions and 34 deletions

View File

@ -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;