Auto-Save Settings
This example demonstrates how to create a function that automatically saves the settings for a given flake. The function detects differences between the settings form and the profile data; if a difference is found, it calls the save() method.
function demoFlake(id)
{
var _self=this;
var _instance = null;
this.autoSave=function ()
{
var savedDoAlert=false;
if( _instance.Profiles["DOALERT"] )
savedDoAlert = _instance.Profiles["DOALERT"];
var savedText="";
if( _instance.Profiles["TEXT"] )
savedText = _instance.Profiles["TEXT"];
if(document.getElementById(_id+"doAlert").checked!=savedDoAlert
||
document.getElementById(_id+"text").value!=savedText)
_self.saveProfile();
setTimeout(_self.autoSave, 8000);
}
this.load=function(instance)
{
_instance = instance;
_self.autoSave();
}
}
This example:
- Saves a reference to
thisduring initialization, called_self. - Executes the
_self.autoSave()function during load to start the auto-save process. - Within the
autoSave()function:
- Creates a local copy of the variables stored in the profile.
- Compares these to the data stored in the form.
- If there's a difference calls
_self.saveProfile() - Sets a new timeout to when the next auto-save check should occur.

