diff --git a/plugins/CoreHome/javascripts/dataTable.js b/plugins/CoreHome/javascripts/dataTable.js index 45766feedb19eca8e571d05bae2686f7fb862f06..433d5b52cc2ffa26f9a233eded8ed2516f621aa6 100644 --- a/plugins/CoreHome/javascripts/dataTable.js +++ b/plugins/CoreHome/javascripts/dataTable.js @@ -89,6 +89,17 @@ $.extend(DataTable.prototype, UIControl.prototype, { // initialize your dataTable in your plugin }, + _destroy: function() { + UIControl.prototype._destroy.call(this); + // remove handlers to avoid memory leaks + if (this.windowResizeTableAttached) { + $(window).off('resize', this._resizeDataTable); + } + if (this._bodyMouseUp) { + $('body').off('mouseup', this._bodyMouseUp); + } + }, + //initialisation function init: function () { var domElem = this.$element; @@ -577,6 +588,7 @@ $.extend(DataTable.prototype, UIControl.prototype, { } $(window).on('resize', resizeDataTable); + self._resizeDataTable = resizeDataTable; } }, @@ -1179,11 +1191,12 @@ $.extend(DataTable.prototype, UIControl.prototype, { }); //close exportToFormat onClickOutside - $('body').on('mouseup', function (e) { + self._bodyMouseUp = function (e) { if (self.exportToFormat) { self.exportToFormatHide(domElem); } - }); + }; + $('body').on('mouseup', self._bodyMouseUp); $('.exportToFormatItems a', domElem) // prevent click jacking attacks by dynamically adding the token auth when the link is clicked diff --git a/plugins/CoreVisualizations/javascripts/jqplot.js b/plugins/CoreVisualizations/javascripts/jqplot.js index e840a71537a68ccccee264e98358e586f6998fd8..13c91a568c1d1ec24a907fd8794181e431983394 100644 --- a/plugins/CoreVisualizations/javascripts/jqplot.js +++ b/plugins/CoreVisualizations/javascripts/jqplot.js @@ -178,12 +178,12 @@ // manage resources target.on('piwikDestroyPlot', function () { - if (this._resizeListener) { - $(window).off('resize', this._resizeListener); + if (self._resizeListener) { + $(window).off('resize', self._resizeListener); } self._plot.destroy(); for (var i = 0; i < $.jqplot.visiblePlots.length; i++) { - if ($.jqplot.visiblePlots[i] == self._plot) { + if ($.jqplot.visiblePlots[i] === self) { $.jqplot.visiblePlots[i] = null; } } @@ -394,14 +394,14 @@ if ($.jqplot.visiblePlots[i] == null) { continue; } - $.jqplot.visiblePlots[i].destroy(); + $.jqplot.visiblePlots[i].destroyPlot(); } $.jqplot.visiblePlots = []; }); } if (typeof plot != 'undefined') { - $.jqplot.visiblePlots.push(plot); + $.jqplot.visiblePlots.push(self); } }, @@ -1196,4 +1196,4 @@ RowEvolutionSeriesToggle.prototype.beforeReplot = function () { $.jqplot.preInitHooks.push($.jqplot.PieLegend.init); $.jqplot.postDrawHooks.push($.jqplot.PieLegend.postDraw); -})(jQuery, require); \ No newline at end of file +})(jQuery, require);