App-sitelenmute

 view release on metacpan or  search on metacpan

share/view/index.js  view on Meta::CPAN

    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();
}

function setupHeader()
{
  ehdr.empty();
  var el;
  if(imgs.index)
  {
    el = new Element('a', { 'title': 'Back to index', 'href': encodeURI(imgs.index) });
    el.set('html', '<img src="view/back.png"/>');
    ehdr.adopt(el);
  }
  if(imgs.data[eidx].file)
  {
    var file = encodeURI(imgs.data[eidx].file[0]);
    el = new Element('a', { 'title': 'Download image', 'href': file });
    el.set('html', '<img src="view/eye.png"/>');
    ehdr.adopt(el);
  }
  if(imgs.download)
  {
    el = new Element('a', { 'title': 'Download album', 'href': imgs.download });
    el.set('html', '<img src="view/download.png"/>');
    ehdr.adopt(el);
  }
  if(imgs.captions)
  {
    el = new Element('a', { 'title': 'Toggle captions' });
    el.setStyle('cursor', 'pointer');
    el.addEvent('click', toggleCap);
    var img = new Element('img', { 'id': 'togglecap', 'src': 'view/cap-' + capst + '.png' });
    img.inject(el);
    el.inject(ehdr);
  }
  if(imgs.data[eidx].date)
    ehdr.adopt(new Element('span', { 'title': 'EXIF timestamp', 'html': imgs.data[eidx].date }));
  el = new Element('a', { 'title': 'Overview', 'href': 'view/overview.html' });
  el.set('html', '<img src="view/overview.png"/>');
  ehdr.adopt(el);
  ehdr.setStyle('display', (ehdr.children.length? 'block': 'none'));
  ehdr.removeEvent('click', toggleSlideshow);
}

function onMainReady()
{
  resizeMainImg(eimg);
  eimg.setStyle('opacity', 0);
  eimg.addClass('current');
  eimg.inject(ebuff);

  setupHeader();
  if(imgs.data[eidx].file)
  {
    var file = encodeURI(imgs.data[eidx].file[0]);
    eimg.addEvent('click', function() { window.location = file; });
    eimg.setStyle('cursor', 'pointer'); // fallback
    eimg.setStyle('cursor', 'zoom-in');
  }

  // caption
  if(!imgs.data[eidx]['caption'])
    hideCap();
  else
  {
    var cap = imgs.data[eidx]['caption'];
    ecap.eidx = eidx
    ecap.empty();
    if(cap[0].length)
      ecap.adopt(new Element('div', { 'id': 'title', 'text': cap[0] }));
    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()



( run in 0.738 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )