mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-30 19:00:09 +00:00
smarter loadImages(...) done...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
cd287a715c
commit
1ec78e80f8
75
ui/data.js
75
ui/data.js
@ -338,35 +338,62 @@ function loadImages(ref_gid, count, ribbon){
|
|||||||
var old_gids = getImageGIDs(getImageGID(images.first()), images.length, ribbon_i, true)
|
var old_gids = getImageGIDs(getImageGID(images.first()), images.length, ribbon_i, true)
|
||||||
var gids = getImageGIDs(from_gid, count, ribbon_i, true)
|
var gids = getImageGIDs(from_gid, count, ribbon_i, true)
|
||||||
|
|
||||||
// XXX need to check if there actually is any intersection at all...
|
// check if heads have common gid and get the diff length...
|
||||||
|
|
||||||
var head = gids.indexOf(old_gids[0]) != -1 ?
|
var head = gids.indexOf(old_gids[0]) != -1 ?
|
||||||
gids.slice(0, gids.indexOf(old_gids[0]))
|
gids.indexOf(old_gids[0])
|
||||||
: []
|
// check if we need to truncate...
|
||||||
|
// XXX needs testing...
|
||||||
|
: old_gids.indexOf(gids[0]) != -1 ?
|
||||||
|
-old_gids.indexOf(gids[0])
|
||||||
|
: 0
|
||||||
|
// check if tails have common gid and get the diff length...
|
||||||
var tail = gids.indexOf(old_gids[old_gids.length-1]) > 0 ?
|
var tail = gids.indexOf(old_gids[old_gids.length-1]) > 0 ?
|
||||||
gids.slice(gids.indexOf(old_gids[old_gids.length-1]))
|
gids.length - gids.indexOf(old_gids[old_gids.length-1]) - 1
|
||||||
: []
|
// check if we need to truncate...
|
||||||
console.log('>>>', head.length, '+-('+ (gids.length - head.length - tail.length) +')-+', tail.length)
|
// XXX needs testing...
|
||||||
|
: old_gids.indexOf(gids[gids.length-1]) > 0 ?
|
||||||
|
-(old_gids.length - old_gids.indexOf(gids[gids.length-1]) - 1)
|
||||||
|
: 0
|
||||||
|
|
||||||
|
// XXX the next section might need some simplification -- fells bulky...
|
||||||
// do nothing...
|
// check if we have a common section at all / full reload...
|
||||||
// XXX this is still wrong, need to check what's loaded...
|
if(head == 0 && tail == 0){
|
||||||
if(count > gids.length){
|
if(gids.indexOf(old_gids[0]) == -1){
|
||||||
return images
|
console.log('>>> FULL RELOAD...')
|
||||||
|
// XXX do we need to think about alining here???
|
||||||
} else if(count != images.length){
|
extendRibbon(0, gids.length - old_gids.length, ribbon)
|
||||||
var l = images.length
|
return ribbon
|
||||||
var ext = count - l
|
.find('.image')
|
||||||
var ext_l = Math.floor(ext/2)
|
.each(function(i, e){
|
||||||
var ext_r = ext - ext_l
|
|
||||||
// NOTE: this avoids reattaching images that are already there...
|
|
||||||
extendRibbon(ext_l, ext_r, ribbon)
|
|
||||||
images = ribbon.find('.image')
|
|
||||||
}
|
|
||||||
|
|
||||||
return images.each(function(i, e){
|
|
||||||
updateImage(e, gids[i], size)
|
updateImage(e, gids[i], size)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// do nothing...
|
||||||
|
// ...the requested section is the same as the one already loaded...
|
||||||
|
} else {
|
||||||
|
console.log('>>> NOTHING TO DO...')
|
||||||
|
return images
|
||||||
|
}
|
||||||
|
|
||||||
|
// do a partial reload...
|
||||||
|
} else {
|
||||||
|
console.log('>>>', 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...
|
||||||
|
var res = extendRibbon(head, tail, ribbon)
|
||||||
|
|
||||||
|
// NOTE: if there was no extension (i.e. head/tail <= 0) then
|
||||||
|
// these will do nothing...
|
||||||
|
res.left.each(function(i, e){
|
||||||
|
updateImage(e, gids[i], size)
|
||||||
|
})
|
||||||
|
res.right.each(function(i, e){
|
||||||
|
updateImage(e, gids[i + gids.length - tail], size)
|
||||||
|
})
|
||||||
|
|
||||||
|
return ribbon.find('.image')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user