fixed bug in load/reload...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-11-08 16:18:20 +03:00
parent e20f337978
commit b420c007bc
5 changed files with 52 additions and 37 deletions

View File

@ -1071,8 +1071,6 @@ module.DataPrototype = {
// -> data // -> data
// //
// NOTE: if mode is 'vertical' then place is ignored... // NOTE: if mode is 'vertical' then place is ignored...
//
// XXX needs testing...
gatherImages: function(gids, reference, place, mode){ gatherImages: function(gids, reference, place, mode){
gids = this.makeSparseImages(gids) gids = this.makeSparseImages(gids)
@ -1197,6 +1195,7 @@ module.DataPrototype = {
// NOTE: .getImage(..) defaults to 'before' thus this to defaults // NOTE: .getImage(..) defaults to 'before' thus this to defaults
// to 'after' // to 'after'
// //
// XXX needs better docs...
shiftImage: function(from, target, mode, direction){ shiftImage: function(from, target, mode, direction){
from = from == null || from == 'current' ? this.current : from from = from == null || from == 'current' ? this.current : from
from = from.constructor !== Array ? [from] : from from = from.constructor !== Array ? [from] : from

View File

@ -989,11 +989,14 @@ module.RibbonsPrototype = {
// //
// ribbons must be .getRibbon(..) compatible. // ribbons must be .getRibbon(..) compatible.
// //
// reference must be .getImage(..) compatible. // reference must be .getImage(..) compatible or null to disable
// offset compensation.
// //
// XXX should this compensate for load offset??? // NOTE: this will change ribbon size and compensate for it, but this
// XXX need to make this animation-neutral... // will not disable transitions, which at this point is the
updateRibbon: function(gids, ribbon, reference){ // responsibility of the caller...
// NOTE: offset calculation depends on image blocks being square...
updateRibbon: function(gids, ribbon, reference, count){
var that = this var that = this
// get/create the ribbon... // get/create the ribbon...
var r = this.getRibbon(ribbon) var r = this.getRibbon(ribbon)
@ -1006,12 +1009,10 @@ module.RibbonsPrototype = {
var unload = $() var unload = $()
// compensate for new/removed images... // compensate for new/removed images...
// XXX need to make this animation-neutral...
if(reference != null){ if(reference != null){
var ref = this.getImage(reference) var ref = this.getImage(reference)
// align only if ref is loaded... // align only if ref is loaded...
// XXX
if(ref.length > 0){ if(ref.length > 0){
var gid = this.getElemGID(ref) var gid = this.getElemGID(ref)
var w = ref.outerWidth() var w = ref.outerWidth()
@ -1074,13 +1075,6 @@ module.RibbonsPrototype = {
that.updateImage(img) that.updateImage(img)
}) })
/*
// remove the rest of the stuff in ribbon...
if(loaded.length > gids.length){
loaded.eq(gids.length-1).nextAll().remove()
}
*/
return this return this
}, },
@ -1134,10 +1128,13 @@ module.RibbonsPrototype = {
// load the data... // load the data...
var that = this var that = this
// place images... // update ribbons -- place images...
if(data.ribbons != null){ if(data.ribbons != null){
// see if we've got a custom ribbon updater...
var updateRibbon = settings.updateRibbon || this.updateRibbon.bind(this)
Object.keys(data.ribbons).forEach(function(gid){ Object.keys(data.ribbons).forEach(function(gid){
that.updateRibbon(data.ribbons[gid], gid) updateRibbon(data.ribbons[gid], gid)
}) })
} }

View File

@ -85,12 +85,6 @@ module.setupActions = function(viewer){
var vv = Object.create(v.Viewer) var vv = Object.create(v.Viewer)
vv.load({
data: data.Data(module.mock_data),
viewer: viewer,
images: makeTestImages(),
})
return vv return vv
} }

View File

@ -197,6 +197,15 @@ $(function(){
//module.GLOBAL_KEYBOARD.__proto__ = a //module.GLOBAL_KEYBOARD.__proto__ = a
// load some testing data...
a.load({
data: data.Data(testing.mock_data),
viewer: $('.viewer'),
images: testing.makeTestImages(),
})
// setup base keyboard for devel, in case something breaks... // setup base keyboard for devel, in case something breaks...
$(document) $(document)
.keydown( .keydown(

View File

@ -538,18 +538,24 @@ actions.Actions(Client, {
this.reload() this.reload()
} }
}], }],
// XXX make this better support partial data view... // NOTE: this will pass the .ribbons.updateData(..) a custom ribbon
// ...at this point this first loads the full data and then // updater if one is defined here as .updateRibbon(target)
// .focusImage(..) triggers a reload... // XXX actions.updateRibbon(..) and ribbons.updateRibbon(..) are NOT
// signature compatible...
reload: ['Reload viewer', reload: ['Reload viewer',
function(){ function(){
this.ribbons.preventTransitions() this.ribbons.preventTransitions()
return function(){ return function(){
this.ribbons.updateData(this.data) // see if we've got a custom ribbon updater...
var that = this
var settings = this.updateRibbon != null
? { updateRibbon: function(_, ribbon){ that.updateRibbon(ribbon) } }
: null
this.ribbons.updateData(this.data, settings)
this.focusImage() this.focusImage()
//this.ribbons.restoreTransitions(true)
this.ribbons.restoreTransitions() this.ribbons.restoreTransitions()
} }
}], }],
@ -560,7 +566,6 @@ actions.Actions(Client, {
delete this.ribbons delete this.ribbons
}], }],
// XXX move this to a viewer window action set // XXX move this to a viewer window action set
close: ['Cloase viewer', close: ['Cloase viewer',
function(){ function(){
@ -925,7 +930,16 @@ function Feature(obj){
var PartialRibbonsActions = var PartialRibbonsActions =
module.PartialRibbonsActions = module.PartialRibbonsActions =
actions.Actions({ actions.Actions({
updateRibbonSize: ['Update partial ribbon size', /*
// NOTE: this is here for documentation only, mixing-this into an
// action set will overload the original config...
config: {
'ribbon-size-screens': 5,
'ribbon-resize-threshold': 1,
},
*/
updateRibbon: ['Update partial ribbon size',
function(target, w, size, threshold){ function(target, w, size, threshold){
target = target instanceof jQuery target = target instanceof jQuery
? this.ribbons.getElemGID(target) ? this.ribbons.getElemGID(target)
@ -953,6 +967,8 @@ actions.Actions({
var na = this.data.getImages(target, s/2, 'after').length - 1 var na = this.data.getImages(target, s/2, 'after').length - 1
var pa = this.data.getImages(target, s/2, 'before').length - 1 var pa = this.data.getImages(target, s/2, 'before').length - 1
// do the update...
// the target is not loaded... // the target is not loaded...
if(this.ribbons.getImage(target).length == 0 if(this.ribbons.getImage(target).length == 0
// passed threshold on the right... // passed threshold on the right...
@ -1008,17 +1024,17 @@ module.PartialRibbons = Feature({
return actions return actions
.on('focusImage.pre centerImage.pre', this.tag, function(target){ .on('focusImage.pre centerImage.pre', this.tag, function(target){
this.updateRibbonSize(target) this.updateRibbon(target)
}) })
.on('fitImage.pre', this.tag, function(n){ .on('fitImage.pre', this.tag, function(n){
this.updateRibbonSize('current', n || 1) this.updateRibbon('current', n || 1)
}) })
.on('fitRibbon.pre', this.tag, function(n){ .on('fitRibbon.pre', this.tag, function(n){
n = n || 1 n = n || 1
// convert target height in ribbons to width in images... // convert target height in ribbons to width in images...
// NOTE: this does not account for compensation that // NOTE: this does not account for compensation that
// .updateRibbonSize(..) makes for fitting whole image // .updateRibbon(..) makes for fitting whole image
// counts, this is a small enough error so as not // counts, this is a small enough error so as not
// to waste time on... // to waste time on...
var s = this.ribbons.getScale() var s = this.ribbons.getScale()
@ -1026,7 +1042,7 @@ module.PartialRibbons = Feature({
var w = this.ribbons.getScreenWidthImages() var w = this.ribbons.getScreenWidthImages()
var nw = w / (h/n) var nw = w / (h/n)
this.updateRibbonSize('current', nw) this.updateRibbon('current', nw)
}) })
}, },
remove: function(actions){ remove: function(actions){
@ -1051,7 +1067,7 @@ module.AlignRibbonsToImageOrder = Feature({
this.alignByOrder(target) this.alignByOrder(target)
}) })
// normalize the initial state... // normalize the initial state...
.focusImage() //.focusImage()
}, },
}) })
@ -1069,7 +1085,7 @@ module.AlignRibbonsToFirstImage = Feature({
this.alignByFirst(target) this.alignByFirst(target)
}) })
// normalize the initial state... // normalize the initial state...
.focusImage() //.focusImage()
}, },
}) })
@ -1345,7 +1361,7 @@ module.CurrentImageIndicator = Feature({
}) })
// turn the marker on... // turn the marker on...
// XXX not sure about this... // XXX not sure about this...
.focusImage() //.focusImage()
}, },
remove: function(actions){ remove: function(actions){
actions.viewer.find('.' + this.tag).remove() actions.viewer.find('.' + this.tag).remove()