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>
|
<a name="GUI+destroy"></a>
|
||||||
|
|
||||||
### gui.destroy()
|
### 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)
|
**Kind**: instance method of [<code>GUI</code>](#GUI)
|
||||||
<a name="GUI+addFolder"></a>
|
<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
|
* @instance
|
||||||
*/
|
*/
|
||||||
destroy: function() {
|
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) {
|
if (this.autoPlace) {
|
||||||
autoPlaceContainer.removeChild(this.domElement);
|
autoPlaceContainer.removeChild(this.domElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
dom.unbind(window, 'keydown', GUI._keydownHandler, false);
|
const _this = this;
|
||||||
dom.unbind(window, 'resize', this.__resizeHandler);
|
common.each(this.__folders, function(subfolder) {
|
||||||
|
_this.removeFolder(subfolder);
|
||||||
|
});
|
||||||
|
|
||||||
if (this.saveToLocalStorageIfPossible) {
|
dom.unbind(window, 'keydown', GUI._keydownHandler, false);
|
||||||
dom.unbind(window, 'unload', this.saveToLocalStorageIfPossible);
|
|
||||||
}
|
removeListeners(this);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -645,7 +655,14 @@ common.extend(
|
|||||||
delete this.load.folders[folder.name];
|
delete this.load.folders[folder.name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
removeListeners(folder);
|
||||||
|
|
||||||
const _this = this;
|
const _this = this;
|
||||||
|
|
||||||
|
common.each(folder.__folders, function(subfolder) {
|
||||||
|
folder.removeFolder(subfolder);
|
||||||
|
});
|
||||||
|
|
||||||
common.defer(function() {
|
common.defer(function() {
|
||||||
_this.onResize();
|
_this.onResize();
|
||||||
});
|
});
|
||||||
@ -868,10 +885,17 @@ function addRow(gui, newDom, liBefore) {
|
|||||||
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) {
|
||||||
const opt = gui.__preset_select[gui.__preset_select.selectedIndex];
|
const opt = gui.__preset_select[gui.__preset_select.selectedIndex];
|
||||||
|
|
||||||
// console.log('mark', modified, opt);
|
|
||||||
if (modified) {
|
if (modified) {
|
||||||
opt.innerHTML = opt.value + '*';
|
opt.innerHTML = opt.value + '*';
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user