UNPKG

@deephaven/golden-layout

Version:

A multi-screen javascript Layout manager

108 lines (101 loc) 3.91 kB
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } import $ from 'jquery'; import EventEmitter from "./EventEmitter.js"; /** * An EventEmitter singleton that propagates events * across multiple windows. This is a little bit trickier since * windows are allowed to open childWindows in their own right * * This means that we deal with a tree of windows. Hence the rules for event propagation are: * * - Propagate events from this layout to both parents and children * - Propagate events from parent to this and children * - Propagate events from children to the other children (but not the emitting one) and the parent */ class EventHub extends EventEmitter { constructor(layoutManager) { super(); _defineProperty(this, "_layoutManager", void 0); _defineProperty(this, "_dontPropagateToParent", void 0); _defineProperty(this, "_childEventSource", void 0); _defineProperty(this, "_boundOnEventFromChild", void 0); this._layoutManager = layoutManager; this._dontPropagateToParent = null; this._childEventSource = null; this.on(EventEmitter.ALL_EVENT, this._onEventFromThis.bind(this)); this._boundOnEventFromChild = this._onEventFromChild.bind(this); $(window).on('gl_child_event', this._boundOnEventFromChild); } /** * Called on every event emitted on this eventHub, regardles of origin. */ _onEventFromThis() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } if (this._layoutManager.isSubWindow && args[0] !== this._dontPropagateToParent) { this._propagateToParent(args); } this._propagateToChildren(args); //Reset this._dontPropagateToParent = null; this._childEventSource = null; } /** * Called by the parent layout. * * @param args Event name + arguments */ _$onEventFromParent(args) { this._dontPropagateToParent = args[0]; this.emit.apply(this, args); } /** * Callback for child events raised on the window * * @param event */ _onEventFromChild(event) { this._childEventSource = event.originalEvent.__gl; this.emit.apply(this, event.originalEvent.__glArgs); } /** * Propagates the event to the parent by emitting * it on the parent's DOM window * * @param args Event name + arguments */ _propagateToParent(args) { var _window$opener; var eventName = 'gl_child_event'; var event = (_window$opener = window.opener) === null || _window$opener === void 0 ? void 0 : _window$opener.document.createEvent('HTMLEvents'); event.initEvent(eventName, true, true); event.eventName = eventName; event.__glArgs = args; event.__gl = this._layoutManager; window.opener.dispatchEvent(event); } /** * Propagate events to children * * @param args Event name + arguments */ _propagateToChildren(args) { for (var i = 0; i < this._layoutManager.openPopouts.length; i++) { var childGl = this._layoutManager.openPopouts[i].getGlInstance(); if (childGl && childGl !== this._childEventSource) { childGl.eventHub._$onEventFromParent(args); } } } /** * Destroys the EventHub */ destroy() { $(window).off('gl_child_event', this._boundOnEventFromChild); } } export default EventHub; //# sourceMappingURL=EventHub.js.map