UNPKG

@jswf/core

Version:

JavaScript Window Framework

186 lines 6.07 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); /* eslint-disable @typescript-eslint/class-name-casing */ var BaseView_1 = require("./BaseView"); require("../scss/Button.scss"); /** *ボタン用クラス * * @export * @class Button * @extends {BaseView} */ var Button = /** @class */ (function (_super) { __extends(Button, _super); /** *Creates an instance of Button. * @param {string} [text] ボタンに設定するテキスト * @memberof Button */ function Button() { var params = []; for (var _i = 0; _i < arguments.length; _i++) { params[_i] = arguments[_i]; } var _this = _super.call(this) || this; _this.setAutoSize(true); _this.setJwfStyle("Button"); //this.setAlign('center') var button = document.createElement("div"); _this.getClient().appendChild(button); button.tabIndex = 0; var nodeText = document.createElement("span"); button.appendChild(nodeText); _this.nodeText = nodeText; if (params) { if (typeof params[0] === "string") { _this.setText(params[0]); _this.nodeValue = params[1]; } else { var p = params[0]; if (p.label) { _this.setText(p.label); } _this.nodeValue = p.value; if (p.event) { button.addEventListener("click", p.event); } } } button.addEventListener("keypress", function (e) { if (e.keyCode !== 13) _this.callEvent("submit", { event: e, button: _this }); }); button.addEventListener("click", function (e) { _this.callEvent("buttonClick", { event: e, button: _this }); _this.callEvent("submit", { event: e, button: _this }); }); button.addEventListener("dblclick", function (e) { _this.callEvent("buttonDblClick", { event: e, button: _this }); }); return _this; } /** *ボタンに対してテキストを設定する * * @param {string} text * @memberof Button */ Button.prototype.setText = function (text) { var nodeText = this.nodeText; nodeText.textContent = text; this.layout(); }; /** *ボタンに設定したテキストを取得する * * @returns {string} * @memberof Button */ Button.prototype.getText = function () { return this.nodeText.textContent; }; Button.prototype.setAlign = function (style) { var node = this.getClient(); node.style.justifyContent = style; }; Button.prototype.getValue = function () { return this.nodeValue; }; return Button; }(BaseView_1.BaseView)); exports.Button = Button; var ImageButton = /** @class */ (function (_super) { __extends(ImageButton, _super); /** *Creates an instance of Button. * @param {string} [text] ボタンに設定するテキスト * @memberof Button */ function ImageButton(image, alt) { var _this = _super.call(this) || this; _this.setWidth(64); //this.setAutoSize(true) _this.setJwfStyle("Button"); //this.setAlign('center') var button = document.createElement("div"); _this.getClient().appendChild(button); button.tabIndex = 0; var nodeImg = document.createElement("img"); button.appendChild(nodeImg); _this.nodeImg = nodeImg; if (alt) nodeImg.alt = alt; nodeImg.addEventListener("load", function () { _this.layout(); }); nodeImg.src = image; button.addEventListener("keypress", function (e) { if (e.keyCode !== 13) _this.callEvent("submit", { event: e }); }); button.addEventListener("click", function (e) { _this.callEvent("buttonClick", { event: e, button: _this }); _this.callEvent("submit", { event: e }); }); button.addEventListener("dblclick", function (e) { _this.callEvent("buttonDblClick", { event: e, button: _this }); }); return _this; } /** *ボタンに対してテキストを設定する * * @param {string} text * @memberof Button */ ImageButton.prototype.setText = function (text) { this.nodeImg.alt = text; this.layout(); }; /** *ボタンに設定したテキストを取得する * * @returns {string} * @memberof Button */ ImageButton.prototype.getText = function () { return this.nodeImg.alt; }; ImageButton.prototype.setAlign = function (style) { var node = this.getClient(); node.style.justifyContent = style; }; return ImageButton; }(BaseView_1.BaseView)); exports.ImageButton = ImageButton; //# sourceMappingURL=Button.js.map