dataarts / dat.gui

Lightweight controller library for JavaScript.
Apache License 2.0
7.42k stars 1.08k forks source link

Allow programatic save #39

Open pehrlich opened 10 years ago

pehrlich commented 10 years ago

For example, I would like to have it save before unload the page every time, so that I can rapidly debug changes without having to save and resume settings manually.

Unfortunately, the following code doesn't work:

window.onbeforeunload = ->
  gui.save()

It gives the error:

Uncaught TypeError: Cannot read property 'selectedIndex' of undefined dat.gui.js:2854 markPresetModified dat.gui.js:2854 dat.GUI.dat.gui.GUI.common.extend.save dat.gui.js:2261 window.onbeforeunload

stellatigre commented 9 years ago

This issue still occurs in the latest build - this functionality can be invoked by firing the fake click event on the save button:

function saveDatGUI() {
    dat.dom.dom.fakeEvent($('.cr .button')[0], 'click');
}

but that feels hacky. This functionality would be useful in writing tests which involve a datgui component.
If it's deemed not an issue, perhaps close this ?