/** * A callback function for the event: * When the user press `Up` key */ onUpKey() { var len = this.choices.realLength; this.pointer = this.pointer > 0 ? this.pointer - 1 : len - 1; this.render(); }
/** * A callback function for the event: * When the user press 'a' key */ onAllKey() { var shouldBeChecked = Boolean( this.choices.find(function(choice) { return choice.type !== 'separator' && !choice.checked; }) ); this.choices.forEach(function(choice) { if (choice.type !== 'separator') { choice.checked = shouldBeChecked; } }); this.render(); }
/** * A callback function for the event: * When the user press a number key */ onNumberKey(input) { if (input <= this.choices.realLength) { this.pointer = input - 1; this.toggleChoice(this.choices.getChoice(this.pointer)); } this.render(); }
/** * A callback function for the event: * When the user press `i` key */ onInverseKey() { this.choices.forEach(function(choice) { if (choice.type !== 'separator') { choice.checked = !choice.checked; } }); this.render(); }
self.choices.forEach(function(choice) {
/** * A callback function for the event: * When the user press `Down` key */ onDownKey() { var len = this.choices.realLength; this.pointer = this.pointer < len - 1 ? this.pointer + 1 : 0; this.render(); }