Added automatic slide show
This commit is contained in:
@@ -26,7 +26,7 @@ from datetime import datetime
|
||||
|
||||
# (c) ville.rantanen@helsinki.fi
|
||||
|
||||
__version__='1.3'
|
||||
__version__='1.4'
|
||||
|
||||
webfilesearch=re.compile('.*index.html$|.*gallerystyle.css$|.*galleryscript.js$|.*descriptions.csv$|\..*',re.I)
|
||||
imagesearch=re.compile('.*\.jpg$|.*\.jpeg$|.*\.gif$|.*\.png$|.*\.svg$|.*\.pdf$',re.I)
|
||||
|
||||
@@ -27,6 +27,8 @@ var currentimage=-1;
|
||||
var currentlist=-1;
|
||||
var originals=false;
|
||||
var preloader;
|
||||
var slideshowtimer;
|
||||
var slideshowinterval;
|
||||
|
||||
function setup() {
|
||||
// Setup run at the load of page.
|
||||
@@ -35,7 +37,12 @@ function setup() {
|
||||
}
|
||||
//hidethumbs();
|
||||
document.onkeydown=keypressed;
|
||||
var req=request();
|
||||
slideshowinterval=request('auto');
|
||||
if (slideshowinterval!=-1) {
|
||||
slideshowtimer=setInterval('slidenext()',1000*slideshowinterval);
|
||||
}
|
||||
var req=request('p');
|
||||
if (req==-1) { req=request('q'); }
|
||||
if (req!=-1) {
|
||||
showimage(req);
|
||||
} else {
|
||||
@@ -104,14 +111,19 @@ function preload(i) {
|
||||
function preloadcheck() {
|
||||
var imgs=document.getElementById('preloadcontainer').childNodes;
|
||||
var tob=document.getElementById('desccontainer');
|
||||
var completed=preloadcheckcount();
|
||||
var colorValue=32*completed/imgs.length + 223;
|
||||
tob.style.backgroundColor="rgb("+colorValue+","+colorValue+","+colorValue+")";
|
||||
if (imgs.length==completed) { clearInterval(preloader); tob.style.backgroundColor="rgb(255,255,255)"; }
|
||||
return;
|
||||
}
|
||||
function preloadcheckcount() {
|
||||
var imgs=document.getElementById('preloadcontainer').childNodes;
|
||||
var completed=0;
|
||||
for (i=0;i<imgs.length;i++) {
|
||||
if (imgs[i].complete) { completed++; }
|
||||
}
|
||||
var colorValue=32*completed/imgs.length + 223;
|
||||
tob.style.backgroundColor="rgb("+colorValue+","+colorValue+","+colorValue+")";
|
||||
if (imgs.length==completed) { clearInterval(preloader); tob.style.backgroundColor="rgb(255,255,255)"; }
|
||||
return
|
||||
return completed;
|
||||
}
|
||||
|
||||
function thumblist(n,curr) {
|
||||
@@ -268,26 +280,42 @@ function sortlist(property) {
|
||||
return;
|
||||
}
|
||||
|
||||
function request() {
|
||||
// Fetch ?q=search request and present first match.
|
||||
var query = location.search.substr(1).split("=");
|
||||
if ((query[0]=="q") && query.length>1 && query[1].length>0) {
|
||||
for (imname in imagelist) {
|
||||
if (imagelist[imname].indexOf(unescape(query[1])) != -1) {
|
||||
return parseInt(imname);
|
||||
break;
|
||||
function request(type) {
|
||||
// Check for URL queries
|
||||
var queries = location.search.substr(1).split("&");
|
||||
for (que=0;que<queries.length;que++) {
|
||||
var query = queries[que].split("=");
|
||||
if (type=="q") {
|
||||
// Fetch ?q=search request and present first match.
|
||||
if ((query[0]=="q") && query.length>1 && query[1].length>0) {
|
||||
for (imname in imagelist) {
|
||||
if (imagelist[imname].indexOf(unescape(query[1])) != -1) {
|
||||
return parseInt(imname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (type=="p") {
|
||||
// Fetch ?p=position request and return the integer
|
||||
if ((query[0]=="p") && query.length>1 && query[1].length>0) {
|
||||
var retval=parseInt(query[1]);
|
||||
if (isNaN(retval)) { return -1; }
|
||||
retval=Math.max(1,retval);
|
||||
retval=Math.min(retval,imagelist.length);
|
||||
return retval-1;
|
||||
}
|
||||
}
|
||||
if (type=="auto") {
|
||||
// Fetch ?auto=num seconds request and return the boolean
|
||||
if ((query[0]=="auto") && query.length>1 && query[1].length>0) {
|
||||
var retval=parseInt(query[1]);
|
||||
if (isNaN(retval)) { return -1; }
|
||||
retval=Math.max(1,retval);
|
||||
return retval;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fetch ?p=position request and return the integer
|
||||
if ((query[0]=="p") && query.length>1 && query[1].length>0) {
|
||||
var retval=parseInt(query[1]);
|
||||
if (isNaN(retval)) { return -1; }
|
||||
retval=Math.max(1,retval);
|
||||
retval=Math.min(retval,imagelist.length);
|
||||
return retval-1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -421,7 +449,7 @@ function getmaxthumbs() {
|
||||
}
|
||||
|
||||
function hidethumbs() {
|
||||
// hide all thumbnails
|
||||
// hide all thumbnails (obsolete)
|
||||
if (notsupported()) {
|
||||
return;
|
||||
}
|
||||
@@ -431,6 +459,16 @@ function hidethumbs() {
|
||||
return;
|
||||
}
|
||||
|
||||
function slidenext() {
|
||||
var imgs=document.getElementById('preloadcontainer').childNodes;
|
||||
var completed=preloadcheckcount();
|
||||
if (imgs.length==completed) {
|
||||
currentimage-=1;
|
||||
if (currentimage<0) { currentimage=imagelist.length-1; }
|
||||
showimage(currentimage);
|
||||
}
|
||||
}
|
||||
|
||||
function keypressed(e) {
|
||||
//if (currentimage==-1) { return; }
|
||||
if (document.getElementById('marklist')!=null) {
|
||||
@@ -439,37 +477,48 @@ function keypressed(e) {
|
||||
var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode;
|
||||
maxThumb=getmaxthumbs();
|
||||
var shift=evtobj.shiftKey;
|
||||
// shift end: move to last image
|
||||
if (unicode==35 && shift==1) {
|
||||
currentimage=imagelist.length-1;
|
||||
showimage(currentimage);
|
||||
}
|
||||
// shift home: move to first item
|
||||
if (unicode==36 && shift==1) {
|
||||
currentimage=0;
|
||||
showimage(currentimage);
|
||||
}
|
||||
// arrow left: move 1 left
|
||||
if (unicode==37 && shift==0) {
|
||||
currentimage-=1;
|
||||
if (currentimage<0) { currentimage=imagelist.length-1; }
|
||||
showimage(currentimage);
|
||||
}
|
||||
// shift arrow left: move 1 page left
|
||||
if (unicode==37 && shift==1) {
|
||||
currentimage-=maxThumb;
|
||||
if (currentimage<0) { currentimage=imagelist.length-1; }
|
||||
showimage(currentimage);
|
||||
}
|
||||
// arrow right: move 1 right
|
||||
if (unicode==39 && shift==0) {
|
||||
currentimage+=1;
|
||||
if (currentimage>(imagelist.length-1)) { currentimage=0; }
|
||||
showimage(currentimage);
|
||||
}
|
||||
// shift arrow right: move 1 page right
|
||||
if (unicode==39 && shift==1) {
|
||||
currentimage+=maxThumb;
|
||||
if (currentimage>(imagelist.length-1)) { currentimage=0; }
|
||||
showimage(currentimage);
|
||||
}
|
||||
// x: mark image
|
||||
if (unicode==88) {
|
||||
markitem(currentimage);
|
||||
}
|
||||
}
|
||||
if (slideshowinterval!=-1) {
|
||||
clearInterval(slideshowtimer);
|
||||
slideshowtimer=setInterval('slidenext()',1000*slideshowinterval);
|
||||
}
|
||||
//Debug:
|
||||
//alert(unicode);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user