fixed a corner-case scope bug in loadImages(...)...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-05-16 21:46:56 +04:00
parent 74efe28d26
commit c039842f8c
2 changed files with 35 additions and 11 deletions

View File

@ -295,13 +295,14 @@ function loadImages(ref_gid, count, ribbon){
var l = DATA.ribbons[ribbon_i].length
if(l <= count){
var from_i = 0
} else {
var from_i = DATA.ribbons[ribbon_i].indexOf(gid) - Math.floor(count/2)
// special case: head...
from_i = from_i < 0 ? 0 : from_i
// special case: tail...
from_i = l - from_i < count ? l - count : from_i
}
// special case: head...
from_i = from_i < 0 ? 0 : from_i
// special case: tail...
from_i = l - from_i < count ? l - count : from_i
var from_gid = DATA.ribbons[ribbon_i][from_i]
var old_gids = getImageGIDs(getImageGID(images.first()), images.length, ribbon_i, true)
@ -328,7 +329,7 @@ function loadImages(ref_gid, count, ribbon){
// check if we have a common section at all / full reload...
if(head == 0 && tail == 0){
if(gids.indexOf(old_gids[0]) == -1){
console.log('>>> FULL RELOAD...')
console.log('>>> (ribbon:', ribbon_i, ') FULL RELOAD --', gids.length)
// XXX do we need to think about alining here???
extendRibbon(0, gids.length - old_gids.length, ribbon)
return ribbon
@ -340,13 +341,13 @@ function loadImages(ref_gid, count, ribbon){
// do nothing...
// ...the requested section is the same as the one already loaded...
} else {
console.log('>>> NOTHING TO DO...')
console.log('>>> (ribbon:', ribbon_i, ') NOTHING TO DO.')
return images
}
// do a partial reload...
} else {
console.log('>>>', head, '+-('+ (old_gids.length) +')-+', tail)
console.log('>>> (ribbon:', ribbon_i, ')', head, '+-('+ (old_gids.length) +')-+', tail)
// NOTE: we do not need to do anything about alignment as
// extendRibbon will get the correct head and tail so as to
// align everything by itself...
@ -481,6 +482,26 @@ function convertDataGen1(data){
/**********************************************************************
* localStorage
*
* XXX should we use jStorage here?
*/
function loadLocalStorage(attr){
attr = attr == null ? 'DATA' : attr
DATA = JSON.parse(localStorage[attr])
return loadData(DATA)
}
function saveLocalStorage(attr){
attr = attr == null ? 'DATA' : attr
localStorage[attr] = JSON.stringify(DATA)
}
/**********************************************************************
* Setup
*/

View File

@ -264,9 +264,12 @@ $(function(){
//setElementOrigin($('.ribbon-set'), 'top', 'left')
DATA = convertDataGen1(image_list)
loadData(DATA)
if('DATA' in localStorage){
loadLocalStorage()
} else {
DATA = convertDataGen1(image_list)
loadData(DATA)
}
// NOTE: this is global so as to not to add any extra complexity to
// the internal workings...
@ -283,7 +286,7 @@ $(function(){
setupDataBindings()
// XXX stub...
centerView(focusImage($('.image').first()), 'css')
//centerView(focusImage($('.image').first()), 'css')
updateImages()
})