App-sitelenmute
view release on metacpan or search on metacpan
share/view/index.js view on Meta::CPAN
function onScroll()
{
var beg, end;
if(imgs.data.length < 2)
{
beg = 0;
end = 1;
}
else
{
var mins, maxs;
if(clayout == 'horizontal')
{
mins = elist.getScrollTop();
maxs = mins + elist.getHeight();
}
else
{
mins = elist.getScrollLeft();
maxs = mins + elist.getWidth();
}
beg = lowerBound(mthumb.beg, mins);
end = lowerBound(mthumb.end, maxs) + 1;
var psize = Math.max(1, Math.floor((end - beg) / 2));
beg = Math.max(0, beg - psize);
end = Math.min(imgs.data.length, end + psize);
}
for(var i = beg; i != end; ++i)
{
if(!imgs.data[i].thumbLoaded)
loadThumb(i);
}
}
function centerThumb(duration)
{
var thumbPos = cthumb.getPosition();
var thumbSize = cthumb.getSize();
var listSize = elist.getSize();
var listScroll = elist.getScroll();
var x = thumbPos.x + listScroll.x - listSize.x / 2 + thumbSize.x / 2;
var y = thumbPos.y + listScroll.y - listSize.y / 2 + thumbSize.y / 2;
if(fscr) fscr.cancel();
fscr = new Fx.Scroll(elist, { duration: duration });
fscr.addEvent('complete', function()
{
fscr = undefined;
onScroll();
});
fscr.start(x, y);
}
function umod(i, m)
{
if(i < 0) i = m + i;
return i % m;
}
function resetTimeout(id)
{
if(id) clearTimeout(id)
return null;
}
function hideCap(nodelay)
{
captm = resetTimeout(captm);
if(!nodelay)
ecap.tween('opacity', 0);
else
{
ecap.get('tween').cancel();
ecap.setStyle('display', 'none');
}
}
function showCap(nodelay)
{
if(capst == 'never') return;
var cap = imgs.data[ecap.eidx]['caption'];
if(!cap || (cap[0].length + cap[1].length == 0))
{
hideCap(true);
return;
}
captm = resetTimeout(captm);
ecap.get('tween').cancel();
if(nodelay) ecap.fade('show');
else ecap.tween('opacity', 1);
ecap.setStyle('display', 'block');
if(capst != 'always')
{
// calculate a decent reading time
var words = cap[0].split(' ').length + cap[1].split(' ').length;
var delay = Math.max(capdelay, rdwdelay * words);
captm = hideCap.delay(delay);
}
}
function toggleCap()
{
if(!imgs.captions) return;
// switch mode
if(capst == 'normal')
capst = 'never';
else if(capst == 'never')
capst = 'always';
else
capst = 'normal';
// update visual state
if(capst == 'never')
hideCap(true);
else if(ecap.eidx == eidx)
showCap(true);
// update indicator
var img = document.id('togglecap', ehdr);
img.src = 'view/cap-' + capst + '.png';
showHdr();
}
function setSlideshowOff()
{
if(slideshow == 'off') return;
idle.removeEvent('idle', next);
showHdr();
elist.setStyle('display', 'block');
slideshow = 'off';
}
function setSlideshowOn()
{
if(slideshow == 'on') return;
idle.addEvent('idle', next);
hideHdr();
elist.setStyle('display', 'none');
slideshow = 'on';
}
function toggleSlideshow()
{
if(slideshow == 'on')
setSlideshowOff();
else
setSlideshowOn();
resize();
}
share/view/index.js view on Meta::CPAN
if(cap[1].length)
ecap.adopt(new Element('div', { 'id': 'desc', 'text': cap[1] }));
showCap(first);
}
// disable transitions for first image
var d = duration;
if(first !== false)
{
first = false;
d = 0;
}
// start animations
if(oimg)
{
// scrolling direction
var pred = umod(oimg.idx + sdir, imgs.data.length);
if(pred != eidx)
{
var diff = umod(eidx - oimg.idx, imgs.data.length);
if(diff == 1)
sdir = 1;
else if(diff == imgs.data.length - 1)
sdir = -1;
else
sdir = 0;
}
// fade old image
oimg.removeClass('current');
var fx = oimg.get('tween');
fx.cancel();
fx.duration = d;
fx.removeEvents('complete');
fx.addEvent('complete', function(x) { x.destroy(); });
fx.start('opacity', 0);
oimg = undefined;
}
var fx = new Fx.Tween(eimg, { duration: d });
if(d)
{
var now = ts();
fx.addEvent('complete', function()
{
detectSlowness(now);
});
}
eimg.set('tween', fx);
fx.start('opacity', 1);
var rp = Math.floor(Math.random() * 100);
eback.src = '';
if (imgs.data[eidx].blur)
{
eback.src = encodeURI(imgs.data[eidx].blur);
enoise.setStyle('background-position', rp + 'px ' + rp + 'px');
}
tthr = resetTimeout(tthr);
idle.start();
if(slideshow != 'on') showHdr();
centerThumb(d);
// prefetch next image
if(prefetch && sdir != 0)
{
var data = imgs.data[umod(eidx + sdir, imgs.data.length)];
Asset.images([encodeURI(data.img[0]), data.blur? data.blur :[]]);
}
}
function showThrobber()
{
var img = new Element('img', { id: 'throbber' });
img.src = "view/throbber.gif";
ehdr.empty();
img.inject(ehdr);
ehdr.setStyle('display', 'block');
idle.stop();
showHdr();
}
function hideHdr()
{
ehdr.tween('opacity', 0);
emain.addClass('no-cursor');
}
function showHdr()
{
emain.removeClass('no-cursor');
ehdr.get('tween').cancel();
ehdr.fade('show');
}
function flash()
{
eflash.setStyle('display', 'block');
eflash.tween('opacity', 1, 0);
}
function prev()
{
if(eidx != 0)
switchTo(eidx - 1);
else
{
flash();
switchTo(imgs.data.length - 1);
}
}
function next()
{
if(eidx != imgs.data.length - 1)
switchTo(eidx + 1);
else
{
flash();
switchTo(0);
}
}
function switchTo(i)
{
window.location.replace("#" + i);
}
function load(i)
{
if(i == eidx) return;
var data = imgs.data[i];
var assets = Asset.images([data.img[0], data.blur? data.blur: []],
{
onComplete: function() { if(i == eidx) onMainReady(); }
});
if(!oimg) oimg = eimg;
eimg = assets[0];
eimg.idx = eidx = i;
if(cthumb) cthumb.removeClass('current');
cthumb = imgs.data[eidx].ethumb;
cthumb.addClass('current');
resetTimeout(tthr);
tthr = showThrobber.delay(thrdelay);
}
function getLocationIndex()
{
var hash = window.location.hash;
var idx = parseInt(!hash.indexOf('#')? hash.substr(1): hash);
if(isNaN(idx) || idx < 0)
idx = 0;
else if(idx >= imgs.data.length)
idx = imgs.data.length - 1;
return idx;
}
function change()
{
load(getLocationIndex());
}
function loadThumb(i)
{
var x = imgs.data[i];
x.eimg.setStyle('background-image', 'url("' + x.thumb[0] + '")');
x.thumbLoaded = true;
}
function initGallery(data)
{
// prepare the data
imgs = data;
if(imgs.name) document.title = imgs.name;
imgs.captions = false;
capst = 'normal';
for(var i = 0; i != imgs.data.length; ++i)
{
if(imgs.data[i]['caption'])
{
imgs.captions = true;
break;
}
}
// build the dom
emain = $('gallery');
emain.setStyle('display', 'none');
eback = new Element('img', { id: 'background' });
eback.inject(emain);
enoise = new Element('div', { id: 'noise' });
enoise.inject(emain);
econt = new Element('div', { id: 'content' });
econt.inject(emain);
ebuff = new Element('div');
ebuff.inject(econt);
eflash = new Element('div', { id: 'flash' });
eflash.setStyles({ 'opacity': 0, 'display': 'none' });
( run in 0.567 second using v1.01-cache-2.11-cpan-99c4e6809bf )