UNPKG

@exadel/esl

Version:

Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components

46 lines (45 loc) 2.02 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { ESLMixinElement } from '../../esl-mixin-element/core'; import { ExportNs } from '../../esl-utils/environment/export-ns'; import { jsonAttr, prop } from '../../esl-utils/decorators'; import { ESLEventUtils } from '../../esl-event-listener/core/api'; /** * ESLAnchor - custom mixin element for setting up anchor for {@link ESLAnchornav} attaching * * Use example: * `<div esl-anchor id="my-anchor-id" title="My anchor title"></div>` */ let ESLAnchor = class ESLAnchor extends ESLMixinElement { connectedCallback() { super.connectedCallback(); this.sendRequestEvent(); } disconnectedCallback() { this.sendRequestEvent(); super.disconnectedCallback(); } attributeChangedCallback(name, oldValue, newValue) { super.attributeChangedCallback(name, oldValue, newValue); this.sendRequestEvent(); // Notify upon esl-anchor attribute change (the only observed attribute by default) } /** Sends a broadcast event to Anchornav components to refresh the list of anchors */ sendRequestEvent() { ESLEventUtils.dispatch(document.body, this.CHANGE_EVENT); } }; ESLAnchor.is = 'esl-anchor'; __decorate([ prop('esl:anchor:change') ], ESLAnchor.prototype, "CHANGE_EVENT", void 0); __decorate([ jsonAttr({ name: ESLAnchor.is }) ], ESLAnchor.prototype, "data", void 0); ESLAnchor = __decorate([ ExportNs('Anchor') ], ESLAnchor); export { ESLAnchor };