This commit is contained in:
Don McCurdy 2018-02-16 20:03:17 -08:00
parent b9796a95ec
commit abcf34d370
7 changed files with 41 additions and 13 deletions

View File

@ -1958,14 +1958,18 @@ Common.extend(GUI.prototype,
}); });
}, },
destroy: function destroy() { destroy: function destroy() {
if (this.parent) {
throw new Error('Only the root GUI should be removed with .destroy(). ' + 'For subfolders, use gui.removeFolder(folder) instead.');
}
if (this.autoPlace) { if (this.autoPlace) {
autoPlaceContainer.removeChild(this.domElement); autoPlaceContainer.removeChild(this.domElement);
} }
var _this = this;
Common.each(this.__folders, function (subfolder) {
_this.removeFolder(subfolder);
});
dom.unbind(window, 'keydown', GUI._keydownHandler, false); dom.unbind(window, 'keydown', GUI._keydownHandler, false);
dom.unbind(window, 'resize', this.__resizeHandler); removeListeners(this);
if (this.saveToLocalStorageIfPossible) {
dom.unbind(window, 'unload', this.saveToLocalStorageIfPossible);
}
}, },
addFolder: function addFolder(name) { addFolder: function addFolder(name) {
if (this.__folders[name] !== undefined) { if (this.__folders[name] !== undefined) {
@ -1993,7 +1997,11 @@ Common.extend(GUI.prototype,
this.load.folders[folder.name]) { this.load.folders[folder.name]) {
delete this.load.folders[folder.name]; delete this.load.folders[folder.name];
} }
removeListeners(folder);
var _this = this; var _this = this;
Common.each(folder.__folders, function (subfolder) {
folder.removeFolder(subfolder);
});
Common.defer(function () { Common.defer(function () {
_this.onResize(); _this.onResize();
}); });
@ -2143,6 +2151,12 @@ function addRow(gui, newDom, liBefore) {
gui.onResize(); gui.onResize();
return li; return li;
} }
function removeListeners(gui) {
dom.unbind(window, 'resize', gui.__resizeHandler);
if (gui.saveToLocalStorageIfPossible) {
dom.unbind(window, 'unload', gui.saveToLocalStorageIfPossible);
}
}
function markPresetModified(gui, modified) { function markPresetModified(gui, modified) {
var opt = gui.__preset_select[gui.__preset_select.selectedIndex]; var opt = gui.__preset_select[gui.__preset_select.selectedIndex];
if (modified) { if (modified) {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1952,14 +1952,18 @@ Common.extend(GUI.prototype,
}); });
}, },
destroy: function destroy() { destroy: function destroy() {
if (this.parent) {
throw new Error('Only the root GUI should be removed with .destroy(). ' + 'For subfolders, use gui.removeFolder(folder) instead.');
}
if (this.autoPlace) { if (this.autoPlace) {
autoPlaceContainer.removeChild(this.domElement); autoPlaceContainer.removeChild(this.domElement);
} }
var _this = this;
Common.each(this.__folders, function (subfolder) {
_this.removeFolder(subfolder);
});
dom.unbind(window, 'keydown', GUI._keydownHandler, false); dom.unbind(window, 'keydown', GUI._keydownHandler, false);
dom.unbind(window, 'resize', this.__resizeHandler); removeListeners(this);
if (this.saveToLocalStorageIfPossible) {
dom.unbind(window, 'unload', this.saveToLocalStorageIfPossible);
}
}, },
addFolder: function addFolder(name) { addFolder: function addFolder(name) {
if (this.__folders[name] !== undefined) { if (this.__folders[name] !== undefined) {
@ -1987,7 +1991,11 @@ Common.extend(GUI.prototype,
this.load.folders[folder.name]) { this.load.folders[folder.name]) {
delete this.load.folders[folder.name]; delete this.load.folders[folder.name];
} }
removeListeners(folder);
var _this = this; var _this = this;
Common.each(folder.__folders, function (subfolder) {
folder.removeFolder(subfolder);
});
Common.defer(function () { Common.defer(function () {
_this.onResize(); _this.onResize();
}); });
@ -2137,6 +2145,12 @@ function addRow(gui, newDom, liBefore) {
gui.onResize(); gui.onResize();
return li; return li;
} }
function removeListeners(gui) {
dom.unbind(window, 'resize', gui.__resizeHandler);
if (gui.saveToLocalStorageIfPossible) {
dom.unbind(window, 'unload', gui.saveToLocalStorageIfPossible);
}
}
function markPresetModified(gui, modified) { function markPresetModified(gui, modified) {
var opt = gui.__preset_select[gui.__preset_select.selectedIndex]; var opt = gui.__preset_select[gui.__preset_select.selectedIndex];
if (modified) { if (modified) {

File diff suppressed because one or more lines are too long

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "dat.gui", "name": "dat.gui",
"version": "0.7.0", "version": "0.7.1",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "dat.gui", "name": "dat.gui",
"version": "0.7.0", "version": "0.7.1",
"description": "A lightweight graphical user interface for changing variables in JavaScript.", "description": "A lightweight graphical user interface for changing variables in JavaScript.",
"main": "build/dat.gui.js", "main": "build/dat.gui.js",
"module": "build/dat.gui.module.js", "module": "build/dat.gui.module.js",