mirror of
https://github.com/dataarts/dat.gui.git
synced 2024-12-12 04:08:27 +00:00
Fix cleanup of event listeners in .destroy() and .removeFolder().
This commit is contained in:
parent
73c4add256
commit
7bb7f8e746
3
API.md
3
API.md
@ -208,7 +208,8 @@ Removes the given controller from the GUI.
|
||||
<a name="GUI+destroy"></a>
|
||||
|
||||
### gui.destroy()
|
||||
Removes the GUI from the document and unbinds all event listeners.
|
||||
Removes the root GUI from the document and unbinds all event listeners.
|
||||
For subfolders, use `gui.removeFolder(folder)` instead.
|
||||
|
||||
**Kind**: instance method of [<code>GUI</code>](#GUI)
|
||||
<a name="GUI+addFolder"></a>
|
||||
|
@ -570,20 +570,30 @@ common.extend(
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes the GUI from the document and unbinds all event listeners.
|
||||
* Removes the root GUI from the document and unbinds all event listeners.
|
||||
* For subfolders, use `gui.removeFolder(folder)` instead.
|
||||
* @instance
|
||||
*/
|
||||
destroy: function() {
|
||||
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) {
|
||||
autoPlaceContainer.removeChild(this.domElement);
|
||||
}
|
||||
|
||||
dom.unbind(window, 'keydown', GUI._keydownHandler, false);
|
||||
dom.unbind(window, 'resize', this.__resizeHandler);
|
||||
const _this = this;
|
||||
common.each(this.__folders, function(subfolder) {
|
||||
_this.removeFolder(subfolder);
|
||||
});
|
||||
|
||||
if (this.saveToLocalStorageIfPossible) {
|
||||
dom.unbind(window, 'unload', this.saveToLocalStorageIfPossible);
|
||||
}
|
||||
dom.unbind(window, 'keydown', GUI._keydownHandler, false);
|
||||
|
||||
removeListeners(this);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -645,7 +655,14 @@ common.extend(
|
||||
delete this.load.folders[folder.name];
|
||||
}
|
||||
|
||||
removeListeners(folder);
|
||||
|
||||
const _this = this;
|
||||
|
||||
common.each(folder.__folders, function(subfolder) {
|
||||
folder.removeFolder(subfolder);
|
||||
});
|
||||
|
||||
common.defer(function() {
|
||||
_this.onResize();
|
||||
});
|
||||
@ -868,10 +885,17 @@ function addRow(gui, newDom, liBefore) {
|
||||
return li;
|
||||
}
|
||||
|
||||
function removeListeners(gui) {
|
||||
dom.unbind(window, 'resize', gui.__resizeHandler);
|
||||
|
||||
if (gui.saveToLocalStorageIfPossible) {
|
||||
dom.unbind(window, 'unload', gui.saveToLocalStorageIfPossible);
|
||||
}
|
||||
}
|
||||
|
||||
function markPresetModified(gui, modified) {
|
||||
const opt = gui.__preset_select[gui.__preset_select.selectedIndex];
|
||||
|
||||
// console.log('mark', modified, opt);
|
||||
if (modified) {
|
||||
opt.innerHTML = opt.value + '*';
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user