added a non-lagging (almost) autosave logic...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2012-08-30 04:26:59 +04:00
parent 193086a4e4
commit 7db1d32570
3 changed files with 38 additions and 15 deletions

View File

@ -116,10 +116,8 @@ function setup(){
// load images... // load images...
// XXX not allowed... // XXX not allowed...
//$.getJSON('images.js', loadImages}) //$.getJSON('images.js', loadImages})
// XXX STUB
//loadJSON(image_list)
ImageGrid.load() ImageGrid.load(null, image_list)
// set the default position and init... // set the default position and init...
$('.current.image').click() $('.current.image').click()

View File

@ -161,17 +161,23 @@ ImageGrid.GROUP('State',
group: 'API', group: 'API',
display: false, display: false,
}, },
function load(name){ function load(name, dfl_state, dfl_config){
if(name == null){ if(name == null){
name = '' name = ''
} else { } else {
name = '-' + name name = '-' + name
} }
loadJSON($.jStorage.get(this.option.KEY_NAME_STATE+name, {})) if(dfl_state == null){
dfl_state = {}
}
if(dfl_config == null){
dfl_config = {}
}
loadJSON($.jStorage.get(this.option.KEY_NAME_STATE+name, dfl_state))
// NOTE: we need to load the config ACTER the state as to be // NOTE: we need to load the config ACTER the state as to be
// able to set correct state-related data like current // able to set correct state-related data like current
// image ID... // image ID...
this.set($.jStorage.get(this.option.KEY_NAME_CONFIG+name, {})) this.set($.jStorage.get(this.option.KEY_NAME_CONFIG+name, dfl_config))
}), }),
ImageGrid.ACTION({ ImageGrid.ACTION({
doc: 'Revert to last verison. if n is given then revert n versions back.\n\n'+ doc: 'Revert to last verison. if n is given then revert n versions back.\n\n'+
@ -289,6 +295,7 @@ ImageGrid.GROUP('State',
value: 10, value: 10,
}), }),
/* /*
// XXX is this the correct way to go...
ImageGrid.OPTION({ ImageGrid.OPTION({
name: 'CURRENT_IMAGE_ID', name: 'CURRENT_IMAGE_ID',
doc: '', doc: '',
@ -1016,18 +1023,31 @@ function setDefaultInitialState(){
function setupEvents(){ function setupEvents(){
var updated = false
// persistence... // persistence...
$(document) $(document)
// main modifier events... // main modifier events...
.bind('shiftImageUp shiftImageDown reverseImageOrder '+ .bind('shiftImageUp shiftImageDown reverseImageOrder '+
'reverseRibbons shiftImageUpNewRibbon shiftImageDownNewRibbon', 'reverseRibbons shiftImageUpNewRibbon shiftImageDownNewRibbon',
ImageGrid.saveState) function(){
updated = true
})
/* /*
// XXX should this be here? // navigation events...
.bind('nextImage prevImage nextScreenImages prevScreenImages '+ .bind('nextImage prevImage nextScreenImages prevScreenImages '+
'focusAboveRibbon focusBelowRibbon', 'focusAboveRibbon focusBelowRibbon',
ImageGrid.saveState) function(){
updated = true
})
*/ */
// save things if updated within a minute...
setInterval(function(){
if(updated){
ImageGrid.saveState()
updated = false
}}, 60000)
// autosave every ten minutes...
setInterval(ImageGrid.saveState, 600000)
// resize... // resize...
$(window).resize(function() { $(window).resize(function() {
@ -1179,11 +1199,17 @@ function buildJSON(get_order){
// XXX might be good to add images in packs here, not one by one... // XXX might be good to add images in packs here, not one by one...
function loadJSON(data, set_order){ function loadJSON(data, position, set_order){
if(position == null){
position = data.position
}
if(set_order == null){ if(set_order == null){
set_order = setImageOrder set_order = setImageOrder
} }
var ribbons = data.ribbons var ribbons = data.ribbons
if(ribbons == null){
return
}
var field = $('.field') var field = $('.field')
// drop all old content... // drop all old content...
@ -1201,8 +1227,8 @@ function loadJSON(data, set_order){
.appendTo(ribbon) .appendTo(ribbon)
} }
} }
if(data.position != null){ if(position != null && $('#' + position).length != 0){
$('#' + data.position).click() $('#' + position).click()
} else { } else {
$('.image').first().click() $('.image').first().click()
} }

View File

@ -64,9 +64,8 @@ function setup(){
// load images... // load images...
// XXX not allowed... // XXX not allowed...
//$.getJSON('images.js', loadImages}) //$.getJSON('images.js', loadImages})
// XXX STUB
//loadImages(image_list) ImageGrid.load(null, image_list)
loadJSON(image_list)
// set the default position and init... // set the default position and init...
$('.current.image').click() $('.current.image').click()