OHIF-125: Fix Exception caused by Cornerstone Tools when sending empty viewports and/or not DOM elements to its functions

This commit is contained in:
Eloízio Salgado committed 2016-11-04 10:31:54 -02:00
1 parent 7d199ab462
commit dfcc64d2ca
4 files changed
+35 -25

No files matched your search

+14 -7
View File
@@ -1,9 +1,10 @@
setActiveViewport = function(element) {
setActiveViewport = element => {
if (!element) {
return;
}
var viewportIndex = $('.imageViewerViewport').index(element);
const viewportIndex = $('.imageViewerViewport').index(element);
const jQueryElement = $(element);
// When an ActivateViewport event is fired, update the Meteor Session
// with the viewport index that it was fired from.
@@ -14,15 +15,21 @@ setActiveViewport = function(element) {
// Add the 'active' class to the parent container to highlight the active viewport
$('#imageViewerViewports .viewportContainer').removeClass('active');
$(element).parents('.viewportContainer').addClass('active');
jQueryElement.parents('.viewportContainer').addClass('active');
// Finally, enable stack prefetching and hide the reference lines from
// the newly activated viewport
enablePrefetchOnElement(element);
displayReferenceLines(element);
// the newly activated viewport that has a canvas
if (jQueryElement.find('canvas').length) {
// Cornerstone Tools compare DOM elements (check getEnabledElement cornerstone function)
// so we can't pass a jQuery object as an argument, otherwise it throws an excepetion
const domElement = jQueryElement.get(0);
enablePrefetchOnElement(domElement);
displayReferenceLines(domElement);
}
// Set the div to focused, so keypress events are handled
//$(element).focus();
//.focus() event breaks in FF&IE
$(element).triggerHandler('focus');
jQueryElement.triggerHandler('focus');
};