uil icon indicating copy to clipboard operation
uil copied to clipboard

Option to persist value to localStorage

Open positlabs opened this issue 9 years ago • 2 comments

For convenience, it would be nice to have persistent values on controls. When the user reloads the page, the values can be loaded back in from localStorage.

ui.add('title', { name:'Title', persist: true});

positlabs avatar Feb 12 '16 19:02 positlabs

yes sound like saving systeme, have to make some research about

lo-th avatar Feb 12 '16 20:02 lo-th

I'm not sure whether datastorage needs to be part of an ui-library. Why not just use the callbacks. For example, something like this:

var data = {}

function load(){
  var d = window.localStorage.getItem('data')
  if( d ) data = JSON.parse(d)
}

function save(key,value){ // key will be preloaded by bind(..) later
  data[key] = value
  window.localStorage.setItem('data', JSON.stringify(data) )
}


// init UIL
load()
for( var key in data )
  ui.add(i,{name:key, value: data[key], callback: save.bind(null,key) })

coderofsalvation avatar Jul 14 '19 14:07 coderofsalvation