made generic next/prev image from list action generators...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-12-15 03:58:54 +04:00
parent cbc22e98ad
commit 1645b03b98
3 changed files with 89 additions and 52 deletions

View File

@ -98,63 +98,24 @@ var toggleBookmark = makeMarkToggler(
'togglingBookmark') 'togglingBookmark')
// focus previous bookmark... // focus next bookmark...
// //
function nextBookmark(){ // NOTE: this will not jump to bookmarks on other ribbons...
if(BOOKMARKS.length == 0){ //
flashIndicator('end') // XXX make a generic next/prev marked function...
return getImage() var nextBookmark = makeNextFromListAction(
} getBookmarkedGIDBefore,
var cur = getImageGID() function(){ return BOOKMARKS })
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)
}
// focus previous bookmark... // focus previous bookmark...
// //
function prevBookmark(){ // NOTE: this will not jump to bookmarks on other ribbons...
if(BOOKMARKS.length == 0){ //
flashIndicator('start') // XXX make a generic next/prev marked function...
return getImage(cur) var prevBookmark = makePrevFromListAction(
} getBookmarkedGIDBefore,
var cur = getImageGID() function(){ return BOOKMARKS })
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)
}

View File

@ -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... // Same as getImageBefore(...), but uses gids and searches in DATA...
// //
// Return: // Return:

View File

@ -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... * Basic marks...
*/ */