UNPKG

mj-context-menu

Version:
62 lines 1.83 kB
import { AbstractMenu } from './abstract_menu.js'; export class SubMenu extends AbstractMenu { static fromJson(factory, { items: its }, anchor) { const submenu = new this(anchor); const itemList = factory.get('items')(factory, its, submenu); submenu.items = itemList; return submenu; } constructor(_anchor) { super(); this._anchor = _anchor; this.variablePool = this.anchor.menu.pool; this.setBaseMenu(); } get anchor() { return this._anchor; } post() { if (!this.anchor.menu.isPosted()) { return; } const mobileFlag = false; const rtlFlag = false; const margin = 5; let parent = this.anchor.html; const menu = this.html; const base = this.baseMenu.frame; const mw = parent.offsetWidth; let x = mobileFlag ? 30 : mw - 2; let y = 0; while (parent && parent !== base) { x += parent.offsetLeft; y += parent.offsetTop; parent = parent.parentNode; } if (!mobileFlag) { if ((rtlFlag && x - mw - menu.offsetWidth > margin) || (!rtlFlag && x + menu.offsetWidth > document.body.offsetWidth - margin)) { x = Math.max(margin, x - mw - menu.offsetWidth + 6); } } super.post(x, y); } display() { this.baseMenu.frame.appendChild(this.html); } setBaseMenu() { let menu = this; do { menu = menu.anchor.menu; } while (menu instanceof SubMenu); this.baseMenu = menu; } left(_event) { this.focused = null; this.anchor.focus(); } toJson() { return { type: '' }; } } //# sourceMappingURL=sub_menu.js.map