UNPKG

@aurelia-mdc-web/base

Version:

Base classes for Aurelia Material Components Web

87 lines 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MdcComponent = void 0; var tslib_1 = require("tslib"); var MdcComponent = /** @class */ (function () { function MdcComponent(root) { this.root = root; this.initialised = this.createInitiliasedPromise(); } MdcComponent.prototype.createInitiliasedPromise = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var _this = this; return tslib_1.__generator(this, function (_a) { return [2 /*return*/, new Promise(function (r) { return _this.initialisedResolve = r; })]; }); }); }; // eslint-disable-next-line @typescript-eslint/no-empty-function MdcComponent.prototype.initialise = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { return [2 /*return*/]; }); }); }; // eslint-disable-next-line @typescript-eslint/no-empty-function MdcComponent.prototype.initialSyncWithDOM = function () { }; MdcComponent.prototype.attached = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: this.continueAttaching = true; return [4 /*yield*/, this.initialise()]; case 1: _a.sent(); // detached might be called straight after attached starts // do not continue attaching if that's the case if (!this.continueAttaching) { return [2 /*return*/]; } this.foundation = this.getDefaultFoundation(); this.foundation.init(); this.initialisedResolve(); this.initialSyncWithDOM(); return [2 /*return*/]; } }); }); }; // eslint-disable-next-line @typescript-eslint/no-empty-function MdcComponent.prototype.destroy = function () { }; MdcComponent.prototype.detached = function () { var _a; this.continueAttaching = false; this.destroy(); (_a = this.foundation) === null || _a === void 0 ? void 0 : _a.destroy(); this.foundation = undefined; this.initialised = this.createInitiliasedPromise(); }; MdcComponent.prototype.listen = function (evtType, handler, options) { this.root.addEventListener(evtType, handler, options); }; MdcComponent.prototype.unlisten = function (evtType, handler, options) { this.root.removeEventListener(evtType, handler, options); }; /** * @hidden * Fires a cross-browser-compatible custom event from the component root of the given type, with the given data. */ MdcComponent.prototype.emit = function (evtType, evtData, shouldBubble) { if (shouldBubble === void 0) { shouldBubble = false; } var evt; if (typeof CustomEvent === 'function') { evt = new CustomEvent(evtType, { bubbles: shouldBubble, detail: evtData, }); } else { evt = document.createEvent('CustomEvent'); evt.initCustomEvent(evtType, shouldBubble, false, evtData); } this.root.dispatchEvent(evt); }; return MdcComponent; }()); exports.MdcComponent = MdcComponent; //# sourceMappingURL=mdc-component.js.map