fixed keyboard issue with default behaviour, still fighting a bug in binSearch that makes it loop forever...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2013-05-07 02:16:57 +04:00
parent f619e62658
commit 53f06951f7
3 changed files with 20 additions and 5 deletions

View File

@ -160,6 +160,7 @@ function getImageBefore(image, ribbon, mode){
// //
// NOTE: this is here mostly to make debuging easy... // NOTE: this is here mostly to make debuging easy...
function isBetween(a, i, lst){ function isBetween(a, i, lst){
console.log('>>>', a, i, lst)
var b = lst[i] var b = lst[i]
var c = lst[i+1] var c = lst[i+1]
// hit... // hit...
@ -182,6 +183,7 @@ function isBetween(a, i, lst){
// NOTE: by default this will use isBetween as a predicate. // NOTE: by default this will use isBetween as a predicate.
// NOTE: this still depends on .indexOf(...), to disable set // NOTE: this still depends on .indexOf(...), to disable set
// disable_direct_indexing to true // disable_direct_indexing to true
// XXX BUG this tends to fall into infinite loops...
function binSearch(target, lst, check, return_position, disable_direct_indexing){ function binSearch(target, lst, check, return_position, disable_direct_indexing){
// XXX is this the correct default? // XXX is this the correct default?
check = check == null ? isBetween : check check = check == null ? isBetween : check
@ -195,13 +197,16 @@ function binSearch(target, lst, check, return_position, disable_direct_indexing)
return lst[lst.length-1] return lst[lst.length-1]
} }
// special case: head... // special case: head...
if(check(target, 0, lst) == 0){ var res = check(target, 0, lst)
if(res == 0){
return lst[0] return lst[0]
} else if(res < 0){
// no hit...
return return_position ? -1 : null
} }
var l = Math.ceil(lst.length/2) var l = Math.ceil(lst.length/2)
var i = l var i = l
var res
while(l > 0){ while(l > 0){
l = Math.ceil(l/2) l = Math.ceil(l/2)

View File

@ -234,6 +234,7 @@ $(function(){
//var rr = r.clone() //var rr = r.clone()
//var rrr = r.clone() //var rrr = r.clone()
// XXX use something like loadImages()...
$('.ribbon-set') $('.ribbon-set')
.append(r) .append(r)
//.append(rr) //.append(rr)
@ -250,8 +251,11 @@ $(function(){
function(k){console.log(k)})) function(k){console.log(k)}))
// dynamic loading... // dynamic loading...
if(true){ DYNAMIC_LOADING = true
if(DYNAMIC_LOADING){
// XXX move to a setup function in the lib... // XXX move to a setup function in the lib...
// XXX update this depending on zoom and navigation speed... // XXX update this depending on zoom and navigation speed...
var LOADER_THRESHOLD = 2 var LOADER_THRESHOLD = 2

View File

@ -76,42 +76,48 @@ var KEYBOARD_CONFIG = {
}, },
*/ */
Home: function(){ Home: function(){
event.preventDefault()
firstImage() firstImage()
centerRibbons() centerRibbons()
return false
}, },
End: function(){ End: function(){
event.preventDefault()
lastImage() lastImage()
centerRibbons() centerRibbons()
return false
}, },
// combined navigation and editor actions... // combined navigation and editor actions...
Up: { Up: {
default: function(){ default: function(){
event.preventDefault()
prevRibbon(DIRECTION) prevRibbon(DIRECTION)
centerRibbons() centerRibbons()
}, },
shift: function(){ shift: function(){
event.preventDefault()
shiftImageUp(null, DIRECTION) shiftImageUp(null, DIRECTION)
centerRibbons() centerRibbons()
}, },
'ctrl+shift': function(){ 'ctrl+shift': function(){
event.preventDefault()
shiftImageUpNewRibbon(null, DIRECTION) shiftImageUpNewRibbon(null, DIRECTION)
centerRibbons() centerRibbons()
}, },
}, },
Down: { Down: {
default: function(){ default: function(){
event.preventDefault()
nextRibbon(DIRECTION) nextRibbon(DIRECTION)
centerRibbons() centerRibbons()
}, },
shift: function(){ shift: function(){
event.preventDefault()
shiftImageDown(null, DIRECTION) shiftImageDown(null, DIRECTION)
centerRibbons() centerRibbons()
}, },
'ctrl+shift': function(){ 'ctrl+shift': function(){
event.preventDefault()
shiftImageDownNewRibbon(null, DIRECTION) shiftImageDownNewRibbon(null, DIRECTION)
centerRibbons() centerRibbons()
}, },