Commit 154bc4c7 authored by Evgeny's avatar Evgeny

Fix issue with wrong binding to window

Remove unnecessary usage of window variable
parent a87799de
......@@ -43,11 +43,22 @@
function ChartInternal(api) {
var $$ = this;
$$.d3 = window.d3 ? window.d3 : typeof require !== 'undefined' ? require("d3") : undefined;
var AsyncBuffer = window.AsyncBuffer ? window.AsyncBuffer : typeof require !== 'undefined' ? require("async-buffer").AsyncBuffer : undefined;
if(typeof d3 !== 'undefined'){
$$.d3 = d3;
} else if(typeof require !== 'undefined'){
$$.d3 = require("d3");
}
var _AsyncBuffer;
if(typeof AsyncBuffer !== 'undefined'){
_AsyncBuffer = AsyncBuffer;
} else if(typeof require !== 'undefined'){
_AsyncBuffer = require('async-buffer').AsyncBuffer;
}
$$.buffer = new AsyncBuffer();
$$.buffer = new _AsyncBuffer();
$$.api = api;
$$.config = $$.getDefaultConfig();
$$.data = {};
......@@ -388,20 +399,22 @@
});
}
// Bind resize event
if (window.onresize == null) {
window.onresize = $$.generateResize();
}
if (window.onresize.add) {
window.onresize.add(function () {
config.onresize.call($$);
});
window.onresize.add(function () {
$$.api.flush();
});
window.onresize.add(function () {
config.onresized.call($$);
});
if(window){
// Bind resize event
if (window.onresize == null) {
window.onresize = $$.generateResize();
}
if (window.onresize.add) {
window.onresize.add(function () {
config.onresize.call($$);
});
window.onresize.add(function () {
$$.api.flush();
});
window.onresize.add(function () {
config.onresized.call($$);
});
}
}
// export element of the chart
......@@ -987,10 +1000,10 @@
if (mutation.type === 'childList' && mutation.previousSibling) {
observer.disconnect();
// need to wait for completion of load because size calculation requires the actual sizes determined after that completion
$$.intervalForObserveInserted = window.setInterval(function () {
$$.intervalForObserveInserted = setInterval(function () {
// parentNode will NOT be null when completed
if (selection.node().parentNode) {
window.clearInterval($$.intervalForObserveInserted);
clearInterval($$.intervalForObserveInserted);
$$.updateDimension();
$$.config.oninit.call($$);
$$.redraw({
......@@ -1070,7 +1083,7 @@
parsedDate = $$.dataTimeFormat($$.config.data_xFormat).parse(date);
}
if (!parsedDate || isNaN(+parsedDate)) {
window.console.error("Failed to parse x '" + date + "' to Date object");
console.error("Failed to parse x '" + date + "' to Date object");
}
return parsedDate;
};
......@@ -4926,7 +4939,7 @@
// $$.getAxisData should be injected by ed3
// If it's not, it's either that c3 is running in test enviroment
// or some error accured
// or some error occurred
if($$.getAxisData){
if($$.config.is_xy){
sizesX = $$.getAbscissa($$.config.ed3Type, minmax.minX, minmax.maxX);
......@@ -5292,9 +5305,9 @@
// MEMO: avoid to cancel transition
if ($$.transiting) {
interval = window.setInterval(function () {
interval = setInterval(function () {
if (!$$.transiting) {
window.clearInterval(interval);
clearInterval(interval);
if ($$.legend.selectAll('.c3-legend-item-focused').size() > 0) {
$$.expandArc(targetIds);
}
......@@ -7895,8 +7908,11 @@
c3_chart_fn.destroy = function () {
var $$ = this.internal;
window.clearInterval($$.intervalForObserveInserted);
window.onresize = null;
clearInterval($$.intervalForObserveInserted);
if(window){
window.onresize = null;
}
$$.selectChart.classed('c3', false).html("");
......@@ -8328,4 +8344,4 @@
window.c3 = c3;
}
})(this);
})(window);
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -31,8 +31,11 @@ c3_chart_fn.flush = function () {
c3_chart_fn.destroy = function () {
var $$ = this.internal;
window.clearInterval($$.intervalForObserveInserted);
window.onresize = null;
clearInterval($$.intervalForObserveInserted);
if(window){
window.onresize = null;
}
$$.selectChart.classed('c3', false).html("");
......
......@@ -138,9 +138,9 @@ c3_chart_internal_fn.expandArc = function (targetIds) {
// MEMO: avoid to cancel transition
if ($$.transiting) {
interval = window.setInterval(function () {
interval = setInterval(function () {
if (!$$.transiting) {
window.clearInterval(interval);
clearInterval(interval);
if ($$.legend.selectAll('.c3-legend-item-focused').size() > 0) {
$$.expandArc(targetIds);
}
......
......@@ -38,11 +38,22 @@ function Chart(config) {
function ChartInternal(api) {
var $$ = this;
$$.d3 = window.d3 ? window.d3 : typeof require !== 'undefined' ? require("d3") : undefined;
var AsyncBuffer = window.AsyncBuffer ? window.AsyncBuffer : typeof require !== 'undefined' ? require("async-buffer").AsyncBuffer : undefined;
if(typeof d3 !== 'undefined'){
$$.d3 = d3;
} else if(typeof require !== 'undefined'){
$$.d3 = require("d3");
}
var _AsyncBuffer;
if(typeof AsyncBuffer !== 'undefined'){
_AsyncBuffer = AsyncBuffer;
} else if(typeof require !== 'undefined'){
_AsyncBuffer = require('async-buffer').AsyncBuffer;
}
$$.buffer = new AsyncBuffer();
$$.buffer = new _AsyncBuffer();
$$.api = api;
$$.config = $$.getDefaultConfig();
$$.data = {};
......@@ -383,20 +394,22 @@ c3_chart_internal_fn.initWithData = function (data) {
});
}
// Bind resize event
if (window.onresize == null) {
window.onresize = $$.generateResize();
}
if (window.onresize.add) {
window.onresize.add(function () {
config.onresize.call($$);
});
window.onresize.add(function () {
$$.api.flush();
});
window.onresize.add(function () {
config.onresized.call($$);
});
if(window){
// Bind resize event
if (window.onresize == null) {
window.onresize = $$.generateResize();
}
if (window.onresize.add) {
window.onresize.add(function () {
config.onresize.call($$);
});
window.onresize.add(function () {
$$.api.flush();
});
window.onresize.add(function () {
config.onresized.call($$);
});
}
}
// export element of the chart
......@@ -982,10 +995,10 @@ c3_chart_internal_fn.observeInserted = function (selection) {
if (mutation.type === 'childList' && mutation.previousSibling) {
observer.disconnect();
// need to wait for completion of load because size calculation requires the actual sizes determined after that completion
$$.intervalForObserveInserted = window.setInterval(function () {
$$.intervalForObserveInserted = setInterval(function () {
// parentNode will NOT be null when completed
if (selection.node().parentNode) {
window.clearInterval($$.intervalForObserveInserted);
clearInterval($$.intervalForObserveInserted);
$$.updateDimension();
$$.config.oninit.call($$);
$$.redraw({
......@@ -1065,7 +1078,7 @@ c3_chart_internal_fn.parseDate = function (date) {
parsedDate = $$.dataTimeFormat($$.config.data_xFormat).parse(date);
}
if (!parsedDate || isNaN(+parsedDate)) {
window.console.error("Failed to parse x '" + date + "' to Date object");
console.error("Failed to parse x '" + date + "' to Date object");
}
return parsedDate;
};
......
......@@ -6,4 +6,4 @@
window.c3 = c3;
}
})(this);
})(window);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment