2017-03-08 06:12:25 +03:00
|
|
|
/**********************************************************************
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
|
|
|
|
(function(require){ var module={} // make module AMD/node compatible...
|
|
|
|
|
/*********************************************************************/
|
|
|
|
|
|
|
|
|
|
var actions = require('lib/actions')
|
|
|
|
|
var features = require('lib/features')
|
|
|
|
|
|
|
|
|
|
var core = require('features/core')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************/
|
2017-03-17 11:55:59 +03:00
|
|
|
// XXX do we need to do most of the work here on in imagegrid/data.js???
|
2017-03-18 13:53:48 +03:00
|
|
|
// ...another question would be if we can do this using existing
|
|
|
|
|
// functionality?
|
2017-03-08 06:12:25 +03:00
|
|
|
|
2017-03-08 06:18:47 +03:00
|
|
|
var PartialRibbonsActions = actions.Actions({
|
2017-04-18 01:53:21 +03:00
|
|
|
config: {
|
|
|
|
|
'ribbon-size-screens': 7,
|
|
|
|
|
|
|
|
|
|
// the amount of screen widths to keep around the current image...
|
|
|
|
|
'ribbon-update-threshold': 1.2,
|
|
|
|
|
|
|
|
|
|
// the oversize multiplier limit when we resize the ribbon down...
|
|
|
|
|
'ribbon-resize-threshold': 2,
|
|
|
|
|
},
|
|
|
|
|
|
2017-03-08 06:18:47 +03:00
|
|
|
updateRibbon: ['- Interface/Update partial ribbon size',
|
|
|
|
|
function(target, w, size, threshold){
|
2017-04-17 19:27:25 +03:00
|
|
|
target = target instanceof jQuery
|
|
|
|
|
? this.ribbons.getElemGID(target)
|
|
|
|
|
// NOTE: data.getImage(..) can return null at start or end
|
|
|
|
|
// of ribbon, thus we need to account for this...
|
|
|
|
|
: (this.data.getImage(target)
|
|
|
|
|
|| this.data.getImage(target, 'after'))
|
|
|
|
|
w = w || this.screenwidth
|
|
|
|
|
// get config data and normalize...
|
|
|
|
|
size = (size
|
|
|
|
|
|| this.config['ribbon-size-screens']
|
2017-04-18 01:53:21 +03:00
|
|
|
|| 9) * w
|
2017-04-17 19:27:25 +03:00
|
|
|
threshold = threshold == 0 ? threshold
|
|
|
|
|
: (threshold
|
|
|
|
|
|| this.config['ribbon-resize-threshold']
|
2017-04-18 01:53:21 +03:00
|
|
|
|| 2)
|
|
|
|
|
var update_threshold = (this.config['ribbon-update-threshold'] || 2) * w
|
2017-04-17 19:27:25 +03:00
|
|
|
var data = this.data
|
|
|
|
|
var ribbons = this.ribbons
|
|
|
|
|
|
|
|
|
|
// localize transition prevention...
|
|
|
|
|
// NOTE: we can't get ribbon via target directly here as
|
|
|
|
|
// the target might not be loaded...
|
|
|
|
|
var r_gid = data.getRibbon(target)
|
|
|
|
|
if(r_gid == null){
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// NOTE: for the initial load this may be empty...
|
|
|
|
|
var r = ribbons.getRibbon(r_gid)
|
|
|
|
|
|
2017-04-18 01:53:21 +03:00
|
|
|
// next/prev loaded...
|
|
|
|
|
var img = this.ribbons.getImage(target)
|
|
|
|
|
var nl = img.nextAll('.image:not(.clone)').length
|
|
|
|
|
var pl = img.prevAll('.image:not(.clone)').length
|
|
|
|
|
var loaded = nl + pl + 1
|
|
|
|
|
|
|
|
|
|
// next/prev available...
|
|
|
|
|
// NOTE: we subtract 1 to remove the current and make these
|
|
|
|
|
// compatible with: nl, pl
|
|
|
|
|
var na = this.data.getImages(target, size, 'after').length - 1
|
|
|
|
|
var pa = this.data.getImages(target, size, 'before').length - 1
|
|
|
|
|
|
|
|
|
|
//console.log(`-- loaded: ${loaded} size: ${size}`)
|
|
|
|
|
|
|
|
|
|
// full resize...
|
|
|
|
|
// ribbon not loaded...
|
|
|
|
|
if(r.length == 0
|
|
|
|
|
// ribbon shorter than we expect...
|
|
|
|
|
|| (loaded < size && na + pa > loaded)
|
|
|
|
|
|| loaded > size * threshold){
|
|
|
|
|
//console.log(`RESIZE: ${loaded} -> ${size}`)
|
|
|
|
|
this.resizeRibbon(target, size)
|
|
|
|
|
|
|
|
|
|
// soft-update...
|
|
|
|
|
} else if(na + pa < nl + pl
|
|
|
|
|
// passed threshold on the right...
|
|
|
|
|
|| (nl < update_threshold && na > nl)
|
|
|
|
|
// passed threshold on the left...
|
|
|
|
|
|| (pl < update_threshold && pa > pl)
|
|
|
|
|
// loaded more than we need by threshold...
|
|
|
|
|
|| nl + pl + 1 > size + update_threshold){
|
|
|
|
|
//console.log('UPDATE')
|
2017-04-17 19:27:25 +03:00
|
|
|
r.length == 0 ?
|
|
|
|
|
// ribbon not loaded...
|
|
|
|
|
this.resizeRibbon(target, size)
|
|
|
|
|
// simply update...
|
|
|
|
|
: this.ribbons
|
|
|
|
|
.preventTransitions(r)
|
|
|
|
|
.updateRibbonInPlace(
|
2017-04-18 01:53:21 +03:00
|
|
|
this.data.getImages(target, loaded, 'total'),
|
2017-04-17 19:27:25 +03:00
|
|
|
r_gid,
|
|
|
|
|
target)
|
|
|
|
|
.restoreTransitions(r, true)
|
|
|
|
|
}
|
2017-03-08 06:18:47 +03:00
|
|
|
}],
|
|
|
|
|
resizeRibbon: ['- Interface/Resize ribbon to n images',
|
|
|
|
|
function(target, size){
|
2017-04-17 19:27:25 +03:00
|
|
|
size = size
|
|
|
|
|
|| (this.config['ribbon-size-screens'] * this.screenwidth)
|
|
|
|
|
|| (5 * this.screenwidth)
|
|
|
|
|
var data = this.data
|
|
|
|
|
var ribbons = this.ribbons
|
|
|
|
|
|
|
|
|
|
// localize transition prevention...
|
|
|
|
|
// NOTE: we can't get ribbon via target directly here as
|
|
|
|
|
// the target might not be loaded...
|
|
|
|
|
var r_gid = data.getRibbon(target)
|
|
|
|
|
if(r_gid == null){
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
// NOTE: for the initial load this may be empty...
|
|
|
|
|
var r = ribbons.getRibbon(r_gid)
|
|
|
|
|
|
|
|
|
|
// XXX do we need to for example ignore unloaded (r.length == 0)
|
|
|
|
|
// ribbons here, for example not load ribbons too far off
|
|
|
|
|
// screen??
|
|
|
|
|
|
|
|
|
|
ribbons
|
|
|
|
|
.preventTransitions(r)
|
|
|
|
|
.updateRibbon(
|
|
|
|
|
data.getImages(target, size, 'total'),
|
|
|
|
|
r_gid,
|
|
|
|
|
target)
|
|
|
|
|
.restoreTransitions(r, true)
|
2017-03-08 06:12:25 +03:00
|
|
|
}],
|
|
|
|
|
})
|
|
|
|
|
|
2017-03-08 06:18:47 +03:00
|
|
|
var PartialRibbons =
|
|
|
|
|
module.PartialRibbons = core.ImageGridFeatures.Feature({
|
2017-03-08 06:12:25 +03:00
|
|
|
title: '',
|
|
|
|
|
doc: '',
|
|
|
|
|
|
2017-03-08 06:18:47 +03:00
|
|
|
priority: 'high',
|
|
|
|
|
|
|
|
|
|
tag: 'ui-partial-ribbons-2',
|
|
|
|
|
exclusive: ['ui-partial-ribbons'],
|
2017-03-08 06:12:25 +03:00
|
|
|
depends: [
|
2017-03-08 06:18:47 +03:00
|
|
|
'ui',
|
2017-03-08 06:12:25 +03:00
|
|
|
],
|
|
|
|
|
|
2017-03-08 06:18:47 +03:00
|
|
|
actions: PartialRibbonsActions,
|
2017-03-08 06:12:25 +03:00
|
|
|
|
2017-03-08 06:18:47 +03:00
|
|
|
handlers: [
|
2017-03-08 06:26:23 +03:00
|
|
|
['focusImage.pre centerImage.pre',
|
|
|
|
|
function(target, list){
|
2017-04-17 19:27:25 +03:00
|
|
|
// NOTE: we have to do this as we are called BEFORE the
|
|
|
|
|
// actual focus change happens...
|
|
|
|
|
// XXX is there a better way to do this???
|
|
|
|
|
target = list != null ? target = this.data.getImage(target, list) : target
|
|
|
|
|
|
|
|
|
|
this.updateRibbon(target)
|
2017-03-08 06:26:23 +03:00
|
|
|
}],
|
|
|
|
|
['resizing.pre',
|
|
|
|
|
function(unit, size){
|
|
|
|
|
// XXX
|
2017-04-18 01:53:21 +03:00
|
|
|
this.updateRibbon()
|
2017-03-08 06:26:23 +03:00
|
|
|
}],
|
2017-03-08 06:18:47 +03:00
|
|
|
],
|
2017-03-08 06:12:25 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
|
* vim:set ts=4 sw=4 : */ return module })
|