App-sitelenmute

 view release on metacpan or  search on metacpan

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

// Sitelen Mute: a modern, minimalist javascript photo gallery
// Copyright(c) 2011-2016 by wave++ "Yuri D'Elia" <wavexx@thregr.org>
// Distributed under GPLv2+ (see COPYING) WITHOUT ANY WARRANTY.
"use strict";

var datafile = 'data.json';

// dimensions
var padding = 22;
var duration = 500;      // for scrolling
var thrdelay = 1500;     // throbber delay
var hidedelay = 3000;    // header and caption hiding delay
var slidedelay = 5000;   // slide show delay
var prefetch = 1;
var minupscale = 640 * 480;
var thumbrt = 16/9 - 5/3;
var cutrt = 0.15;
var capdelay = 5000;
var rdwdelay = 500;

// state variables
var emain;      // main object
var eback;      // background
var enoise;     // additive noise
var eflash;     // flashing object
var ehdr;       // header
var ecap;       // caption
var capst;      // caption status
var captm;      // caption timeout
var elist;      // thumbnail list
var fscr;       // thumbnail list scroll fx
var econt;      // picture container
var ebuff;      // picture buffer
var oimg;       // old image
var eimg;       // new image
var cthumb;     // current thumbnail
var mthumb;     // thumbnail measurement cache
var eidx;       // current index
var tthr;       // throbber timeout
var imgs;       // image list
var first;      // first image
var idle;       // general idle timer
var idleMouse;  // idle mouse timer
var clayout;    // current layout
var csr;        // current scaling ratio
var sdir;       // scrolling direction
var slideshow;  // slideshow status

Element.Events.hashchange =
{
  onAdd: function()
  {
    var hash = window.location.hash;

    var hashchange = function()
    {
      if(hash == window.location.hash) return;
      else hash = window.location.hash;

      var value = (!hash.indexOf('#')? hash.substr(1): hash);
      window.fireEvent('hashchange', value);
      document.fireEvent('hashchange', value);
    };

    if("onhashchange" in window
        && (!Browser.ie || Browser.version > 7))
      window.onhashchange = hashchange;
    else
      hashchange.periodical(50);
  }
};

function resize()
{
  // best layout
  var msize = emain.getSize();
  var rt = (imgs.thumb.min[0] / imgs.thumb.min[1]);
  var maxw = msize.x - imgs.thumb.min[0] - padding;
  var maxh = msize.y * rt - imgs.thumb.min[1] - padding;
  var layout = (maxw >= maxh? 'horizontal': 'vertical');

  // calculate a good multiplier for the thumbnail size
  var m = (layout == 'horizontal'?
    (msize.x * window.devicePixelRatio * thumbrt) / imgs.thumb.min[0]:
    (msize.y * window.devicePixelRatio * thumbrt) / imgs.thumb.min[1]);
  if(m >= 1)
    m = Math.pow(2, Math.floor(Math.log(m) / Math.LN2));
  else
    m = Math.pow(2, Math.ceil(Math.log(m) / Math.LN2));
  var sr = m / window.devicePixelRatio;

  if(layout != clayout || sr != csr)
  {
    onLayoutChanged(layout, sr);
    if(cthumb) centerThumb(0);
    clayout = layout;
    csr = sr;
  }

  // resize main container
  var epos = elist.getPosition();
  if(layout == 'horizontal')
  {



( run in 1.194 second using v1.01-cache-2.11-cpan-39bf76dae61 )