Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove innerHTML usage from our DOM platform #5909

Merged
merged 1 commit into from Dec 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 30 additions & 25 deletions src/platforms/platform.dom.js
Expand Up @@ -166,9 +166,15 @@ function throttled(fn, thisArg) {
};
}

function createDiv(cls, style) {
var el = document.createElement('div');
el.style.cssText = style || '';
el.className = cls || '';
return el;
}

// Implementation based on https://github.com/marcj/css-element-queries
function createResizer(handler) {
var resizer = document.createElement('div');
var cls = CSS_PREFIX + 'size-monitor';
var maxSize = 1000000;
var style =
Expand All @@ -182,37 +188,36 @@ function createResizer(handler) {
'visibility:hidden;' +
'z-index:-1;';

resizer.style.cssText = style;
resizer.className = cls;
resizer.innerHTML =
'<div class="' + cls + '-expand" style="' + style + '">' +
'<div style="' +
'position:absolute;' +
'width:' + maxSize + 'px;' +
'height:' + maxSize + 'px;' +
'left:0;' +
'top:0">' +
'</div>' +
'</div>' +
'<div class="' + cls + '-shrink" style="' + style + '">' +
'<div style="' +
'position:absolute;' +
'width:200%;' +
'height:200%;' +
'left:0; ' +
'top:0">' +
'</div>' +
'</div>';

var expand = resizer.childNodes[0];
var shrink = resizer.childNodes[1];
// NOTE(SB) Don't use innerHTML because it could be considered unsafe.
// https://github.com/chartjs/Chart.js/issues/5902
var resizer = createDiv(cls, style);
var expand = createDiv(cls + '-expand', style);
var shrink = createDiv(cls + '-shrink', style);

expand.appendChild(createDiv('',
'position:absolute;' +
'height:' + maxSize + 'px;' +
'width:' + maxSize + 'px;' +
'left:0;' +
'top:0;'
));
shrink.appendChild(createDiv('',
'position:absolute;' +
'height:200%;' +
'width:200%;' +
'left:0;' +
'top:0;'
));

resizer.appendChild(expand);
resizer.appendChild(shrink);
resizer._reset = function() {
expand.scrollLeft = maxSize;
expand.scrollTop = maxSize;
shrink.scrollLeft = maxSize;
shrink.scrollTop = maxSize;
};

var onScroll = function() {
resizer._reset();
handler();
Expand Down