Files
ohif-viewer/Packages/ohif-core/client/ui/dimensional/dimensional.js
T

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-11-23 18:59:37 -02:00
import { $ } from 'meteor/jquery';
// Temporarily show and hide the element to enable dimension calculations
$.fn.tempShow = function(callback) {
const elementsToHide = [];
let current = this;
// Temporarily show all parent invisible elements until body
2017-11-08 08:38:36 -02:00
while (this.is(':hidden')) {
const $element = $(current);
if (!$element.length || $element.is(':visible')) {
2016-11-23 18:59:37 -02:00
break;
}
$element.addClass('visible');
elementsToHide.push(current);
2017-11-08 08:38:36 -02:00
current = $element[0].parentElement;
2016-11-23 18:59:37 -02:00
}
if (typeof callback === 'function') {
callback(this);
}
$(elementsToHide).removeClass('visible');
return this;
};
// Adjust the max width/height to enable CSS3 transitions
2017-10-16 07:20:37 -02:00
$.fn.adjustMax = function(dimension, modifierFn) {
2016-11-23 18:59:37 -02:00
const $element = $(this);
2017-10-16 07:20:37 -02:00
// Temporarily make the element visible to allow getting its dimensions
2016-11-23 18:59:37 -02:00
$element.tempShow(() => {
const maxProperty = `max-${dimension}`;
// Remove the current max restriction
$element.each((i, e) => e.style.setProperty(maxProperty, 'none', 'important'));
2016-11-23 18:59:37 -02:00
// Get the dimension function to obtain the outer dimension
const dimensionFn = 'outer' + dimension.charAt(0).toUpperCase() + dimension.slice(1);
const value = $element[dimensionFn]();
// Remove the property (needed for IE)
$element.each((i, e) => e.style.removeProperty(maxProperty));
// Set the new max restriction
$element.css(maxProperty, value);
2016-11-23 18:59:37 -02:00
});
};