enigma-bbs/core/button_view.js

33 lines
877 B
JavaScript
Raw Normal View History

2014-10-23 22:40:52 +00:00
/* jslint node: true */
'use strict';
2017-02-08 03:14:56 +00:00
const TextView = require('./text_view.js').TextView;
const miscUtil = require('./misc_util.js');
const util = require('util');
2014-10-23 22:40:52 +00:00
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(ch, key) {
2017-02-08 03:14:56 +00:00
// allow space = submit
if(' ' === ch) {
this.emit('action', 'accept');
}
ButtonView.super_.prototype.onKeyPress.call(this, ch, key);
};
ButtonView.prototype.getData = function() {
return null;
};