From c039842f8cdd50d17dd383770a6fd6c781d1d07c Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 16 May 2013 21:46:56 +0400 Subject: [PATCH] fixed a corner-case scope bug in loadImages(...)... Signed-off-by: Alex A. Naanou --- ui/data.js | 35 ++++++++++++++++++++++++++++------- ui/index.html | 11 +++++++---- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/ui/data.js b/ui/data.js index ef170209..5c6d230d 100755 --- a/ui/data.js +++ b/ui/data.js @@ -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 */ diff --git a/ui/index.html b/ui/index.html index 09219842..28daa98d 100755 --- a/ui/index.html +++ b/ui/index.html @@ -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() })