merged most of the duplicate code, some cordenr cases still left, mostly due to animation...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2012-06-16 21:40:36 +04:00
parent d440355b9f
commit 429ad0730b

View File

@ -149,20 +149,20 @@ function handleKeys(event){
: (fn(code, keys.lastKeys) >= 0) ? lastImage() : (fn(code, keys.lastKeys) >= 0) ? lastImage()
: (fn(code, keys.promoteKeys) >= 0) ? function(){ : (fn(code, keys.promoteKeys) >= 0) ? function(){
if(event.ctrlKey){ if(event.ctrlKey){
createRibbonBelow() createRibbon('next')
} }
promoteImage() promoteImage()
}() }()
: (fn(code, keys.demoteKeys) >= 0) ? function(){ : (fn(code, keys.demoteKeys) >= 0) ? function(){
if(event.ctrlKey){ if(event.ctrlKey){
createRibbonAbove() createRibbon('prev')
} }
demoteImage() demoteImage()
}() }()
: (fn(code, keys.downKeys) >= 0) ? function(){ : (fn(code, keys.downKeys) >= 0) ? function(){
if(event.shiftKey){ if(event.shiftKey){
if(event.ctrlKey){ if(event.ctrlKey){
createRibbonBelow() createRibbon('next')
} }
promoteImage() promoteImage()
} else { } else {
@ -172,7 +172,7 @@ function handleKeys(event){
: (fn(code, keys.upKeys) >= 0) ? function(){ : (fn(code, keys.upKeys) >= 0) ? function(){
if(event.shiftKey){ if(event.shiftKey){
if(event.ctrlKey){ if(event.ctrlKey){
createRibbonAbove() createRibbon('prev')
} }
demoteImage() demoteImage()
} else { } else {
@ -265,29 +265,31 @@ function focusBelowRibbon(){
// create ribbon above/below helpers... // create ribbon above/below helpers...
// XXX NOTE: this will shift the content downwards... function createRibbon(direction){
function createRibbonAbove(){ if(direction == 'next'){
var res = $('<div class="new-ribbon"></div>') var insert = 'insertAfter'
.insertBefore('.current-ribbon') } else if(direction == 'prev') {
var insert = 'insertBefore'
} else {
return false
}
var res = $('<div class="new-ribbon"></div>')[insert]('.current-ribbon')
// HACK: without this, the class change below will not animate... // HACK: without this, the class change below will not animate...
.show() .show()
.addClass('ribbon') .addClass('ribbon')
.removeClass('new-ribbon') .removeClass('new-ribbon')
// XXX find a better way to do this... // XXX need to account for increased top when creating a ribbon above...
$('.field').css({ // i.e. shift the content upward...
top: $('.field').position().top - $('.current-ribbon').outerHeight() /*
}) if(direction == 'prev'){
$('.field').css({
top: $('.field').position().top - $('.current-ribbon').outerHeight()
})
}*/
return res return res
} }
function createRibbonBelow(){
return $('<div class="new-ribbon"></div>')
.insertAfter('.current-ribbon')
// HACK: without this, the class change below will not animate...
.show()
.addClass('ribbon')
.removeClass('new-ribbon')
}
// Modifiers... // Modifiers...
@ -307,17 +309,8 @@ function mergeRibbons(direction){
// now the actual modifiers... // now the actual modifiers...
function shiftImage(direction){ function shiftImage(direction){
// XXX simplify this...
if(direction == 'prev'){
var createRibbon = createRibbonAbove
} else if (direction == 'next'){
var createRibbon = createRibbonBelow
} else {
return false
}
if($('.current-ribbon')[direction]('.ribbon').length == 0){ if($('.current-ribbon')[direction]('.ribbon').length == 0){
createRibbon() createRibbon(direction)
} }
// XXX sort elements correctly... // XXX sort elements correctly...
if($('.current-ribbon').children('.image').length == 1){ if($('.current-ribbon').children('.image').length == 1){