enigma-bbs/core/button_view.js

35 lines
983 B
JavaScript
Raw Normal View History

2014-10-23 22:40:52 +00:00
/* jslint node: true */
'use strict';
var TextView = require('./text_view.js').TextView;
var miscUtil = require('./misc_util.js');
2014-10-23 22:40:52 +00:00
var util = require('util');
var assert = require('assert');
exports.ButtonView = ButtonView;
function ButtonView(options) {
options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true);
options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, true);
options.justify = miscUtil.valueWithDefault(options.justify, 'center');
options.cursor = miscUtil.valueWithDefault(options.cursor, 'hide');
2014-10-23 22:40:52 +00:00
TextView.call(this, options);
2014-10-23 22:40:52 +00:00
}
util.inherits(ButtonView, TextView);
ButtonView.prototype.onKeyPress = function(key, isSpecial) {
ButtonView.super_.prototype.onKeyPress.call(this, key, isSpecial);
2014-10-23 22:40:52 +00:00
// allow spacebar to 'click' buttons
// :TODO: need to check configurable mapping here
if(' ' === key) {
this.emit('action', 'accept');
}
};
ButtonView.prototype.getData = function() {
return null;
};