UNPKG

pdbe-molstar

Version:
56 lines (55 loc) 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomEvents = void 0; const operators_1 = require("rxjs/operators"); const loci_details_1 = require("./loci-details"); var CustomEvents; (function (CustomEvents) { function createEvent(eventType) { if (typeof MouseEvent === 'function') { // current standard return new MouseEvent(eventType, { 'view': window, 'bubbles': true, 'cancelable': true }); } else if (typeof document.createEvent === 'function') { // older standard const event = document.createEvent('MouseEvents'); event.initEvent(eventType, true /* bubbles */, true /* cancelable */); return event; } else { throw new Error('Cannot create event'); } } function dispatchCustomEvent(event, eventData, targetElement) { if (eventData !== undefined) { if (eventData.seq_id !== undefined) { eventData.residueNumber = eventData.seq_id; } event.eventData = eventData; targetElement.dispatchEvent(event); } } function add(plugin, targetElement) { const PDB_molstar_click = createEvent('PDB.molstar.click'); const PDB_molstar_mouseover = createEvent('PDB.molstar.mouseover'); const PDB_molstar_mouseout = createEvent('PDB.molstar.mouseout'); plugin.behaviors.interaction.click.subscribe((e) => { if (e.button === 1 && e.current && e.current.loci.kind !== 'empty-loci') { const evData = (0, loci_details_1.lociDetails)(e.current.loci); if (evData) dispatchCustomEvent(PDB_molstar_click, evData, targetElement); } }); plugin.behaviors.interaction.hover.pipe((0, operators_1.debounceTime)(100)).subscribe((e) => { if (e.current && e.current.loci && e.current.loci.kind !== 'empty-loci') { const evData = (0, loci_details_1.lociDetails)(e.current.loci); if (evData) dispatchCustomEvent(PDB_molstar_mouseover, evData, targetElement); } if (e.current && e.current.loci && e.current.loci.kind === 'empty-loci') { dispatchCustomEvent(PDB_molstar_mouseout, {}, targetElement); } }); } CustomEvents.add = add; })(CustomEvents || (exports.CustomEvents = CustomEvents = {}));