UNPKG

mj-context-menu

Version:
95 lines 3.06 kB
import { CloseButton } from './close_button.js'; import { HtmlClasses } from './html_classes.js'; import { AbstractPostable } from './abstract_postable.js'; export class Info extends AbstractPostable { constructor(title, content, signature) { super(); this.title = title; this.signature = signature; this.className = HtmlClasses['INFO']; this.role = 'dialog'; this.contentDiv = this.generateContent(); this.close = this.generateClose(); this.content = content || function () { return ''; }; } attachMenu(menu) { this.menu = menu; } generateHtml() { super.generateHtml(); const html = this.html; html.appendChild(this.generateTitle()); html.appendChild(this.contentDiv); html.appendChild(this.generateSignature()); html.appendChild(this.close.html); html.setAttribute('tabindex', '0'); } post() { super.post(); const doc = document.documentElement; const html = this.html; const H = window.innerHeight || doc.clientHeight || doc.scrollHeight || 0; const x = Math.floor(-html.offsetWidth / 2); const y = Math.floor((H - html.offsetHeight) / 3); html.setAttribute('style', 'margin-left: ' + x + 'px; top: ' + y + 'px;'); if (window.event instanceof MouseEvent) { html.classList.add(HtmlClasses['MOUSEPOST']); } html.focus(); } display() { this.menu.registerWidget(this); this.contentDiv.innerHTML = this.content(); const html = this.menu.html; if (html.parentNode) { html.parentNode.removeChild(html); } this.menu.frame.appendChild(this.html); } click(_event) { } keydown(event) { this.bubbleKey(); super.keydown(event); } escape(_event) { this.unpost(); } unpost() { super.unpost(); this.html.classList.remove(HtmlClasses['MOUSEPOST']); this.menu.unregisterWidget(this); } generateClose() { const close = new CloseButton(this); const html = close.html; html.classList.add(HtmlClasses['INFOCLOSE']); html.setAttribute('aria-label', 'Close Dialog Box'); return close; } generateTitle() { const span = document.createElement('span'); span.innerHTML = this.title; span.classList.add(HtmlClasses['INFOTITLE']); return span; } generateContent() { const div = document.createElement('div'); div.classList.add(HtmlClasses['INFOCONTENT']); div.setAttribute('tabindex', '0'); return div; } generateSignature() { const span = document.createElement('span'); span.innerHTML = this.signature; span.classList.add(HtmlClasses['INFOSIGNATURE']); return span; } toJson() { return { type: '' }; } } //# sourceMappingURL=info.js.map