OHIF-127: Resizing viewport when window gets resized

This commit is contained in:
Eloízio Salgado 2016-11-04 18:32:50 -02:00
parent 553eb9e24e
commit 12862aec51
2 changed files with 14 additions and 4 deletions

View File

@ -111,11 +111,16 @@ Template.cineDialog.onCreated(() => {
* ... jQuery's on('resize', func) version which, for some unkown reason
* ... is currently not working for this portion of code.
* ... Further investigation is necessary.
*
* This happens because when an event is attached using jQuery's
* you can't get it using vanilla JavaScript, it returns null.
* You need to use jQuery for that. So, either you use vanilla JS or jQuery
* to get an element's event handler. See viewerMain for more details.
*/
instance.setResizeHandler = (handler) => {
instance.setResizeHandler = handler => {
if (typeof handler === 'function') {
let origHandler = window.onresize;
const origHandler = window.onresize;
instance.origWindowResizeHandler = typeof origHandler === 'function' ? origHandler : null;
window.onresize = function (event) {
if (typeof origHandler === 'function') {

View File

@ -1,6 +1,11 @@
Template.viewerMain.onCreated(() => {
// Attach the Window resize listener
$(window).on('resize', handleResize);
// Don't use jQuery here. "window.onresize" will always be null
// If its necessary, check all the code for window.onresize getter
// and change it to jQuery._data(window, 'events')['resize'].
// Otherwise this function will be probably overrided.
// See cineDialog instance.setResizeHandler function
window.addEventListener('resize', handleResize);
// Create the synchronizer used to update reference lines
OHIF.viewer.updateImageSynchronizer = new cornerstoneTools.Synchronizer('CornerstoneNewImage', cornerstoneTools.updateImageSynchronizer);
@ -24,7 +29,7 @@ Template.viewerMain.onDestroyed(() => {
log.info('viewerMain onDestroyed');
// Remove the Window resize listener
$(window).off('resize', handleResize);
window.removeEventListener('resize', handleResize);
// Destroy the synchronizer used to update reference lines
OHIF.viewer.updateImageSynchronizer.destroy();