From 2bc9329d3cfc5c2bdd83790b178cebd66f1f1b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Carlos=20Barber=C3=A1=20D=C3=ADaz?= Date: Thu, 24 May 2018 16:16:52 +0200 Subject: [PATCH] Event listeners added to window removed on destroy --- src/jsgrid.core.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/jsgrid.core.js b/src/jsgrid.core.js index 1138881f..e2cd12fc 100755 --- a/src/jsgrid.core.js +++ b/src/jsgrid.core.js @@ -5,6 +5,8 @@ JSGRID_ROW_DATA_KEY = "JSGridItem", JSGRID_EDIT_ROW_DATA_KEY = "JSGridEditRow", + JSGRID_RECYCLED_IDS = [], + JSGRID_LAST_ID = 0, SORT_ORDER_ASC = "asc", SORT_ORDER_DESC = "desc", @@ -53,6 +55,13 @@ function Grid(element, config) { var $element = $(element); + if (JSGRID_RECYCLED_IDS.length==0) { + this._id=JSGRID_LAST_ID; + JSGRID_LAST_ID++; + } else { + this._id=JSGRID_RECYCLED_IDS.pop(); + } + $element.data(JSGRID_DATA_KEY, this); this._container = $element; @@ -243,17 +252,21 @@ }, _attachWindowLoadResize: function() { - $(window).on("load", $.proxy(this._refreshSize, this)); + $(window).on("load.table-"+this._id, $.proxy(this._refreshSize, this)); }, _attachWindowResizeCallback: function() { if(this.updateOnResize) { - $(window).on("resize", $.proxy(this._refreshSize, this)); + $(window).on("resize.table-"+this._id, $.proxy(this._refreshSize, this)); } }, + _detachWindowLoadResize: function() { + $(window).off("load.table-"+this._id); + }, + _detachWindowResizeCallback: function() { - $(window).off("resize", this._refreshSize); + $(window).off("resize.table-"+this._id); }, option: function(key, value) { @@ -367,6 +380,8 @@ destroy: function() { this._detachWindowResizeCallback(); + this._detachWindowLoadResize(); + JSGRID_RECYCLED_IDS.push(this._id); this._clear(); this._container.removeData(JSGRID_DATA_KEY); },