ohif-viewer/Packages/ohif-viewerbase/client/lib/setFocusToActiveViewport.js

25 lines
757 B
JavaScript
Raw Normal View History

import { Session } from 'meteor/session';
import $ from 'jquery';
/**
* Restores the browser focus to the currently specified active viewport
* as determined from Meteor's Session variable.
*
* This is allows keydown events to be captured on the focused element.
*/
const setFocusToActiveViewport = () => {
// Get the list of viewports
const viewports = $('.imageViewerViewport');
// Get the current active viewport index from Session
2018-12-03 18:11:39 +01:00
const activeViewportIndex = window.store.getState().viewports.activeViewport;
// Find the div from the list of viewports
const activeViewport = viewports.eq(activeViewportIndex);
// Set the browser focus to this div
activeViewport.focus();
};
2018-12-03 18:11:39 +01:00
export { setFocusToActiveViewport };