mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-11-01 11:50:07 +00:00
made generic next/prev image from list action generators...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
cbc22e98ad
commit
1645b03b98
@ -98,63 +98,24 @@ var toggleBookmark = makeMarkToggler(
|
||||
'togglingBookmark')
|
||||
|
||||
|
||||
// focus previous bookmark...
|
||||
// focus next bookmark...
|
||||
//
|
||||
function nextBookmark(){
|
||||
if(BOOKMARKS.length == 0){
|
||||
flashIndicator('end')
|
||||
return getImage()
|
||||
}
|
||||
var cur = getImageGID()
|
||||
var next = getBookmarkedGIDBefore(cur)
|
||||
var i = BOOKMARKS.indexOf(next)+1
|
||||
|
||||
// we are before the first loaded bookmark, find the first...
|
||||
while((next == cur || next == null) && i < BOOKMARKS.length){
|
||||
next = BOOKMARKS[i]
|
||||
next = getBookmarkedGIDBefore(next)
|
||||
i++
|
||||
}
|
||||
|
||||
// did not find any loaded bookmarks after...
|
||||
if(i >= BOOKMARKS.length && (next == null || next == cur)){
|
||||
flashIndicator('end')
|
||||
return getImage(cur)
|
||||
}
|
||||
|
||||
return showImage(next)
|
||||
}
|
||||
// NOTE: this will not jump to bookmarks on other ribbons...
|
||||
//
|
||||
// XXX make a generic next/prev marked function...
|
||||
var nextBookmark = makeNextFromListAction(
|
||||
getBookmarkedGIDBefore,
|
||||
function(){ return BOOKMARKS })
|
||||
|
||||
|
||||
// focus previous bookmark...
|
||||
//
|
||||
function prevBookmark(){
|
||||
if(BOOKMARKS.length == 0){
|
||||
flashIndicator('start')
|
||||
return getImage(cur)
|
||||
}
|
||||
var cur = getImageGID()
|
||||
var prev = getBookmarkedGIDBefore(cur)
|
||||
|
||||
// nothing bookmarked before us...
|
||||
if(prev == null){
|
||||
flashIndicator('start')
|
||||
return getImage(cur)
|
||||
}
|
||||
|
||||
// current image is bookmarked, get the bookmark before it...
|
||||
if(prev == cur){
|
||||
prev = BOOKMARKS[BOOKMARKS.indexOf(prev)-1]
|
||||
prev = prev != null ? getBookmarkedGIDBefore(prev) : prev
|
||||
// no loaded (crop mode?) bookmark before us...
|
||||
if(prev == null){
|
||||
flashIndicator('start')
|
||||
return getImage(cur)
|
||||
}
|
||||
}
|
||||
|
||||
return showImage(prev)
|
||||
}
|
||||
// NOTE: this will not jump to bookmarks on other ribbons...
|
||||
//
|
||||
// XXX make a generic next/prev marked function...
|
||||
var prevBookmark = makePrevFromListAction(
|
||||
getBookmarkedGIDBefore,
|
||||
function(){ return BOOKMARKS })
|
||||
|
||||
|
||||
|
||||
|
||||
@ -498,6 +498,14 @@ function getGIDRibbonIndex(gid, data){
|
||||
}
|
||||
|
||||
|
||||
// like getImageOrder(..) but use DATA...
|
||||
function getGIDOrder(gid){
|
||||
gid = gid == null ? getImageGID() : gid
|
||||
gid = typeof(gid) == typeof('str') ? gid : getImageGID(gid)
|
||||
return DATA.order.indexOf(gid)
|
||||
}
|
||||
|
||||
|
||||
// Same as getImageBefore(...), but uses gids and searches in DATA...
|
||||
//
|
||||
// Return:
|
||||
|
||||
68
ui/marks.js
68
ui/marks.js
@ -128,6 +128,74 @@ function makeMarkUpdater(img_class, mark_class, test){
|
||||
}
|
||||
|
||||
|
||||
function makeNextFromListAction(get_closest, get_list){
|
||||
return function(){
|
||||
var list = get_list()
|
||||
if(list.length == 0){
|
||||
flashIndicator('end')
|
||||
return getImage()
|
||||
}
|
||||
var cur = getImageGID()
|
||||
var o = getGIDOrder(cur)
|
||||
var next = get_closest(cur)
|
||||
var i = list.indexOf(next)+1
|
||||
|
||||
// we are before the first loaded bookmark, find the first...
|
||||
while((next == cur
|
||||
|| next == null
|
||||
|| getGIDOrder(next) < o)
|
||||
&& i < list.length){
|
||||
next = list[i]
|
||||
next = get_closest(next)
|
||||
i++
|
||||
}
|
||||
|
||||
// did not find any loaded bookmarks after...
|
||||
if(i >= list.length
|
||||
&& (next == null
|
||||
|| next == cur
|
||||
|| getGIDOrder(next) < o)){
|
||||
flashIndicator('end')
|
||||
return getImage(cur)
|
||||
}
|
||||
|
||||
return showImage(next)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function makePrevFromListAction(get_closest, get_list){
|
||||
return function(){
|
||||
var list = get_list()
|
||||
if(list.length == 0){
|
||||
flashIndicator('start')
|
||||
return getImage(cur)
|
||||
}
|
||||
var cur = getImageGID()
|
||||
var prev = get_closest(cur)
|
||||
|
||||
// nothing bookmarked before us...
|
||||
if(prev == null){
|
||||
flashIndicator('start')
|
||||
return getImage(cur)
|
||||
}
|
||||
|
||||
// current image is bookmarked, get the bookmark before it...
|
||||
if(prev == cur){
|
||||
prev = list[list.indexOf(prev)-1]
|
||||
prev = prev != null ? get_closest(prev) : prev
|
||||
// no loaded (crop mode?) bookmark before us...
|
||||
if(prev == null){
|
||||
flashIndicator('start')
|
||||
return getImage(cur)
|
||||
}
|
||||
}
|
||||
|
||||
return showImage(prev)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
* Basic marks...
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user