Make charts vertically responsive (#3105) (#3326)

Ensure that the hidden iframe is stretched vertically in order to detect height changes. Remove the classlist check/call since it was incorrectly spelled (should be classList), but also useless since the iframe has just been generated. Also remove the callback check: addResizeListener should never be called w/o a valid callback.
This commit is contained in:
Simon Brunel 2016-09-23 17:46:17 +02:00 committed by GitHub
parent 88c69f5f8c
commit 84da2e0a10

View File

@ -958,38 +958,32 @@ module.exports = function(Chart) {
};
helpers.addResizeListener = function(node, callback) {
// Hide an iframe before the node
var hiddenIframe = document.createElement('iframe');
var hiddenIframeClass = 'chartjs-hidden-iframe';
var iframe = document.createElement('iframe');
if (hiddenIframe.classlist) {
// can use classlist
hiddenIframe.classlist.add(hiddenIframeClass);
} else {
hiddenIframe.setAttribute('class', hiddenIframeClass);
}
iframe.className = 'chartjs-hidden-iframe';
iframe.style.cssText =
'display:block;'+
'overflow:hidden;'+
'border:0;'+
'margin:0;'+
'top:0;'+
'left:0;'+
'bottom:0;'+
'right:0;'+
'height:100%;'+
'width:100%;'+
'position:absolute;'+
'pointer-events:none;'+
'z-index:-1;';
// Set the style
hiddenIframe.tabIndex = -1;
var style = hiddenIframe.style;
style.width = '100%';
style.display = 'block';
style.border = 0;
style.height = 0;
style.margin = 0;
style.position = 'absolute';
style.left = 0;
style.right = 0;
style.top = 0;
style.bottom = 0;
// Prevent the iframe to gain focus on tab.
// https://github.com/chartjs/Chart.js/issues/3090
iframe.tabIndex = -1;
// Insert the iframe so that contentWindow is available
node.insertBefore(hiddenIframe, node.firstChild);
node.insertBefore(iframe, node.firstChild);
(hiddenIframe.contentWindow || hiddenIframe).onresize = function() {
if (callback) {
return callback();
}
};
this.addEvent(iframe.contentWindow || iframe, 'resize', callback);
};
helpers.removeResizeListener = function(node) {
var hiddenIframe = node.querySelector('.chartjs-hidden-iframe');