mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 18:30:09 +00:00
bugfix in shiftMarkedImages(..) + performance inmprovement in updateImage(..) -- makes things like updateImages(..) ~15-20% faster in case we did not zoom...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
80defe1cd6
commit
0ba445564e
87
ui/data.js
87
ui/data.js
@ -1137,6 +1137,8 @@ function getCommonSubArray(L1, L2){
|
|||||||
// - return relative paths as-is
|
// - return relative paths as-is
|
||||||
//
|
//
|
||||||
// NOTE: mode can be either 'absolute' (default) or 'relative'...
|
// NOTE: mode can be either 'absolute' (default) or 'relative'...
|
||||||
|
//
|
||||||
|
// XXX use encodeURI if it's available...
|
||||||
function normalizePath(url, base, mode, do_unescape){
|
function normalizePath(url, base, mode, do_unescape){
|
||||||
base = base == null ? getBaseURL() : base
|
base = base == null ? getBaseURL() : base
|
||||||
//mode = /^\./.test(base) && mode == null ? 'relative' : null
|
//mode = /^\./.test(base) && mode == null ? 'relative' : null
|
||||||
@ -1453,7 +1455,7 @@ function dataFromImages(images){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Clean out empty ribbons...
|
// Clean out empty ribbons from data...
|
||||||
//
|
//
|
||||||
function dropEmptyRibbons(data){
|
function dropEmptyRibbons(data){
|
||||||
data = data == null ? DATA : data
|
data = data == null ? DATA : data
|
||||||
@ -1862,24 +1864,27 @@ function updateImage(image, gid, size, sync){
|
|||||||
// preview...
|
// preview...
|
||||||
var p_url = getBestPreview(gid, size).url
|
var p_url = getBestPreview(gid, size).url
|
||||||
|
|
||||||
// sync load...
|
// update the preview only if it's different...
|
||||||
if(sync){
|
if(image.css('background-image').indexOf(encodeURI(p_url)) < 0){
|
||||||
_loadImagePreviewURL(image, p_url)
|
// sync load...
|
||||||
|
if(sync){
|
||||||
|
_loadImagePreviewURL(image, p_url)
|
||||||
|
|
||||||
// async load...
|
// async load...
|
||||||
} else {
|
} else {
|
||||||
// NOTE: storing the url in .data() makes the image load the
|
// NOTE: storing the url in .data() makes the image load the
|
||||||
// last requested preview and in a case when we manage to
|
// last requested preview and in a case when we manage to
|
||||||
// call updateImage(...) on the same element multiple times
|
// call updateImage(...) on the same element multiple times
|
||||||
// before the previews get loaded...
|
// before the previews get loaded...
|
||||||
// ...setting the data().loading is sync while loading an
|
// ...setting the data().loading is sync while loading an
|
||||||
// image is not, and if several loads are done in sequence
|
// image is not, and if several loads are done in sequence
|
||||||
// there is no guarantee that they will happen in the same
|
// there is no guarantee that they will happen in the same
|
||||||
// order as requested...
|
// order as requested...
|
||||||
image.data().loading = p_url
|
image.data().loading = p_url
|
||||||
setTimeout(function(){
|
setTimeout(function(){
|
||||||
_loadImagePreviewURL(image, image.data().loading)
|
_loadImagePreviewURL(image, image.data().loading)
|
||||||
}, 0)
|
}, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// main attrs...
|
// main attrs...
|
||||||
@ -1960,7 +1965,7 @@ function updateImages(list, size, cmp){
|
|||||||
//
|
//
|
||||||
// This is similar to getGIDsAround(..) but will load images into the
|
// This is similar to getGIDsAround(..) but will load images into the
|
||||||
// viewer...
|
// viewer...
|
||||||
function loadImagesAround(count, gid, ribbon, data, force_count){
|
function loadImagesAround(count, gid, ribbon, data, force_count, ignore_common_sections){
|
||||||
// default values...
|
// default values...
|
||||||
data = data == null ? DATA : data
|
data = data == null ? DATA : data
|
||||||
ribbon = ribbon == null ? getRibbonIndex() : ribbon
|
ribbon = ribbon == null ? getRibbonIndex() : ribbon
|
||||||
@ -1977,15 +1982,22 @@ function loadImagesAround(count, gid, ribbon, data, force_count){
|
|||||||
.toArray()
|
.toArray()
|
||||||
var new_ribbon = getGIDsAround(count, gid, ribbon, data, force_count)
|
var new_ribbon = getGIDsAround(count, gid, ribbon, data, force_count)
|
||||||
|
|
||||||
// get the common sub-ribbon...
|
// do a full reload...
|
||||||
// NOTE: we are only interested in continuous sub-ribbons...
|
if(ignore_common_sections){
|
||||||
var res = getCommonSubArrayOffsets(new_ribbon, old_ribbon)
|
var left = null
|
||||||
var left = res.left
|
var right = null
|
||||||
var right = res.right
|
|
||||||
|
|
||||||
// special case: nothing to do...
|
// get the common sub-ribbon...
|
||||||
if(left == 0 && right == 0){
|
} else {
|
||||||
return ribbon_elem.find('.image')
|
// NOTE: we are only interested in continuous sub-ribbons...
|
||||||
|
var res = getCommonSubArrayOffsets(new_ribbon, old_ribbon)
|
||||||
|
var left = res.left
|
||||||
|
var right = res.right
|
||||||
|
|
||||||
|
// special case: nothing to do...
|
||||||
|
if(left == 0 && right == 0){
|
||||||
|
return ribbon_elem.find('.image')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var size = getVisibleImageSize('max')
|
var size = getVisibleImageSize('max')
|
||||||
@ -2086,10 +2098,30 @@ function rollImages(n, ribbon, extend, no_compensate_shift){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Remove images that do not belong in the ribbons they are in...
|
||||||
|
//
|
||||||
|
function removeStrayImages(){
|
||||||
|
$('.ribbon').each(function(i){
|
||||||
|
var ribbon = DATA.ribbons[i]
|
||||||
|
$(this).find('.image').map(function(){
|
||||||
|
var gid = getImageGID(this)
|
||||||
|
if(ribbon.indexOf(gid) < 0){
|
||||||
|
getImageMarks(gid).remove()
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
}).remove()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Reload the viewer using the current DATA and IMAGES objects
|
// Reload the viewer using the current DATA and IMAGES objects
|
||||||
//
|
//
|
||||||
// NOTE: setting reuse_current_structure will not destroy ribbon
|
// NOTE: setting reuse_current_structure will not destroy ribbon
|
||||||
// structure and do a fast reload
|
// structure and do a fast reload
|
||||||
|
// NOTE: if the order of images has changed, reuse_current_structure must
|
||||||
|
// be null or false, otherwise this will not produce a correct result.
|
||||||
function reloadViewer(reuse_current_structure, images_per_screen){
|
function reloadViewer(reuse_current_structure, images_per_screen){
|
||||||
var ribbons_set = $('.ribbon-set')
|
var ribbons_set = $('.ribbon-set')
|
||||||
var current = DATA.current
|
var current = DATA.current
|
||||||
@ -2097,6 +2129,7 @@ function reloadViewer(reuse_current_structure, images_per_screen){
|
|||||||
var w = images_per_screen == null ? getScreenWidthInImages() : images_per_screen
|
var w = images_per_screen == null ? getScreenWidthInImages() : images_per_screen
|
||||||
w = w > CONFIG.max_screen_images ? CONFIG.default_screen_images : w
|
w = w > CONFIG.max_screen_images ? CONFIG.default_screen_images : w
|
||||||
|
|
||||||
|
// reset data structure...
|
||||||
if(!reuse_current_structure){
|
if(!reuse_current_structure){
|
||||||
// clear data...
|
// clear data...
|
||||||
$('.ribbon').remove()
|
$('.ribbon').remove()
|
||||||
|
|||||||
11
ui/marks.js
11
ui/marks.js
@ -399,7 +399,9 @@ function shiftMarkedImages(direction, mode, new_ribbon){
|
|||||||
// ribbon only...
|
// ribbon only...
|
||||||
if(mode == 'ribbon'){
|
if(mode == 'ribbon'){
|
||||||
var ribbon = DATA.ribbons[cur]
|
var ribbon = DATA.ribbons[cur]
|
||||||
// remove all the marked images form current ribbon...
|
// remove all the marked images form the current ribbon...
|
||||||
|
// NOTE: this builds a list of marked images ONLY in current
|
||||||
|
// ribbon...
|
||||||
var marked = $.map(MARKED, function(e){
|
var marked = $.map(MARKED, function(e){
|
||||||
var i = ribbon.indexOf(e)
|
var i = ribbon.indexOf(e)
|
||||||
if(i >= 0){
|
if(i >= 0){
|
||||||
@ -439,10 +441,9 @@ function shiftMarkedImages(direction, mode, new_ribbon){
|
|||||||
DATA.ribbons[cur] = fastSortGIDsByOrder(DATA.ribbons[cur].concat(marked))
|
DATA.ribbons[cur] = fastSortGIDsByOrder(DATA.ribbons[cur].concat(marked))
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove empty ribbons...
|
// remove empty ribbons and reload...
|
||||||
DATA.ribbons = DATA.ribbons.filter(function(e){ return e.length > 0 ? true : false })
|
dropEmptyRibbons()
|
||||||
|
reloadViewer()
|
||||||
updateRibbonOrder()
|
|
||||||
|
|
||||||
$('.viewer').trigger('shiftedImages', [marked, orig_ribbon, cur])
|
$('.viewer').trigger('shiftedImages', [marked, orig_ribbon, cur])
|
||||||
}
|
}
|
||||||
|
|||||||
@ -381,7 +381,7 @@ function createImages(need, have){
|
|||||||
|
|
||||||
|
|
||||||
// NOTE: if index is given, this will also attach the created ribbon to
|
// NOTE: if index is given, this will also attach the created ribbon to
|
||||||
// that position...
|
// that position and trigger the event...
|
||||||
function createRibbon(index){
|
function createRibbon(index){
|
||||||
var ribbon = $('<div class="ribbon"/>')
|
var ribbon = $('<div class="ribbon"/>')
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user