UNPKG

web-atoms-core

Version:
97 lines 4.16 kB
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 __()); }; })(); (function (factory) { if (typeof module === "object" && typeof module.exports === "object") { var v = factory(require, exports); if (v !== undefined) module.exports = v; } else if (typeof define === "function" && define.amd) { define(["require", "exports", "../styles/AtomListBoxStyle", "./AtomItemsControl"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var AtomListBoxStyle_1 = require("../styles/AtomListBoxStyle"); var AtomItemsControl_1 = require("./AtomItemsControl"); var AtomListBox = /** @class */ (function (_super) { __extends(AtomListBox, _super); function AtomListBox() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.selectItemOnClick = true; return _this; } AtomListBox.prototype.preCreate = function () { var _this = this; _super.prototype.preCreate.call(this); this.defaultControlStyle = AtomListBoxStyle_1.AtomListBoxStyle; this.registerItemClick(); this.runAfterInit(function () { var _a; return _this.setElementClass(_this.element, (_a = {}, _a[_this.controlStyle.root.className] = 1, _a["atom-list-box"] = 1, _a)); }); }; AtomListBox.prototype.registerItemClick = function () { var _this = this; this.bindEvent(this.element, "click", function (e) { var p = _this.atomParent(e.target); if (p === _this) { return; } if (p.element._logicalParent === _this.element) { // this is child.. var data = p.data; if (!data) { return; } if (_this.selectItemOnClick) { _this.toggleSelection(data); var ce = new CustomEvent("selectionChanged", { bubbles: false, cancelable: false, detail: data }); _this.element.dispatchEvent(ce); } } }); }; AtomListBox.prototype.createChild = function (df, data) { var _this = this; var child = _super.prototype.createChild.call(this, df, data); child.bind(child.element, "styleClass", [ ["this", "version"], ["data"], ["this", "selectedItems"] ], false, function (version, itemData, selectedItems) { var _a; return _a = { "list-item": true, "selected-list-item": selectedItems && selectedItems.find(function (x) { return x === itemData; }) }, _a[_this.controlStyle.item.className] = true, _a[_this.controlStyle.selectedItem.className] = selectedItems && selectedItems.find(function (x) { return x === itemData; }), _a; }, this); return child; }; return AtomListBox; }(AtomItemsControl_1.AtomItemsControl)); exports.AtomListBox = AtomListBox; }); //# sourceMappingURL=AtomListBox.js.map