From d61473e989c24637dbd22cd5f759c40b01111242 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Sat, 17 Apr 2010 06:58:30 +0000 Subject: [PATCH] Added dispose method to facets so they can clean up themselves. git-svn-id: http://google-refine.googlecode.com/svn/trunk@495 7d457c2a-affb-35e4-300a-418c747d4874 --- src/main/webapp/scripts/facets/list-facet.js | 3 +++ src/main/webapp/scripts/facets/range-facet.js | 4 +++- .../webapp/scripts/facets/scatterplot-facet.js | 4 ++++ .../webapp/scripts/facets/text-search-facet.js | 3 +++ src/main/webapp/scripts/project/browsing-engine.js | 14 +++++++++----- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/webapp/scripts/facets/list-facet.js b/src/main/webapp/scripts/facets/list-facet.js index 8345a1242..cb1219365 100644 --- a/src/main/webapp/scripts/facets/list-facet.js +++ b/src/main/webapp/scripts/facets/list-facet.js @@ -20,6 +20,9 @@ ListFacet.reconstruct = function(div, uiState) { return new ListFacet(div, uiState.c, uiState.o, uiState.s); }; +ListFacet.prototype.dispose = function() { +}; + ListFacet.prototype.reset = function() { this._selection = []; this._blankChoice = null; diff --git a/src/main/webapp/scripts/facets/range-facet.js b/src/main/webapp/scripts/facets/range-facet.js index 516da1bc2..b5f24ecd1 100644 --- a/src/main/webapp/scripts/facets/range-facet.js +++ b/src/main/webapp/scripts/facets/range-facet.js @@ -53,6 +53,9 @@ RangeFacet.reconstruct = function(div, uiState) { return new RangeFacet(div, uiState.c, uiState.o); }; +RangeFacet.prototype.dispose = function() { +}; + RangeFacet.prototype.getUIState = function() { var json = { c: this.getJSON(), @@ -62,7 +65,6 @@ RangeFacet.prototype.getUIState = function() { return json; }; - RangeFacet.prototype.getJSON = function() { var o = { type: "range", diff --git a/src/main/webapp/scripts/facets/scatterplot-facet.js b/src/main/webapp/scripts/facets/scatterplot-facet.js index 524038517..dcba44946 100644 --- a/src/main/webapp/scripts/facets/scatterplot-facet.js +++ b/src/main/webapp/scripts/facets/scatterplot-facet.js @@ -19,6 +19,10 @@ ScatterplotFacet.reconstruct = function(div, uiState) { return new ScatterplotFacet(div, uiState.c, uiState.o); }; +ScatterplotFacet.prototype.dispose = function() { + this._plotImg.imgAreaSelect({ hide : true }); +}; + ScatterplotFacet.prototype.getUIState = function() { var json = { c: this.getJSON(), diff --git a/src/main/webapp/scripts/facets/text-search-facet.js b/src/main/webapp/scripts/facets/text-search-facet.js index 3a190bcfe..1b0185e99 100644 --- a/src/main/webapp/scripts/facets/text-search-facet.js +++ b/src/main/webapp/scripts/facets/text-search-facet.js @@ -13,6 +13,9 @@ TextSearchFacet.reconstruct = function(div, uiState) { return new TextSearchFacet(div, uiState.c, uiState.o); }; +TextSearchFacet.prototype.dispose = function() { +}; + TextSearchFacet.prototype.reset = function() { this._query = null; this._div.find(".input-container input").each(function() { this.value = ""; }); diff --git a/src/main/webapp/scripts/project/browsing-engine.js b/src/main/webapp/scripts/project/browsing-engine.js index 8ec40b5bf..0dde94562 100644 --- a/src/main/webapp/scripts/project/browsing-engine.js +++ b/src/main/webapp/scripts/project/browsing-engine.js @@ -140,16 +140,18 @@ BrowsingEngine.prototype._createFacetContainer = function() { BrowsingEngine.prototype.removeFacet = function(facet) { var update = facet.hasSelection(); for (var i = this._facets.length - 1;i >= 0; i--) { - if (this._facets[i].facet === facet) { - var elmt = this._facets[i].elmt; + var facetRecord = this._facets[i]; + if (facetRecord.facet === facet) { this._facets.splice(i, 1); + facetRecord.facet.dispose(); + // This makes really big facet disappear right away. If you just call remove() // then it takes a while for all the event handlers to get unwired, and the UI // appear frozen. - elmt.hide(); + facetRecord.elmt.hide(); window.setTimeout(function() { - elmt.remove(); + facetRecord.elmt.remove(); }, 300); break; @@ -207,7 +209,9 @@ BrowsingEngine.prototype.remove = function() { this._facets = []; for (var i = 0; i < oldFacets.length; i++) { - oldFacets[i].elmt.hide(); + var facet = oldFacets[i]; + facet.facet.dispose(); + facet.elmt.hide(); } window.setTimeout(function() { for (var i = 0; i < oldFacets.length; i++) {