Added automatic slide show

This commit is contained in:
ville rantanen
2012-01-04 13:58:05 +02:00
parent 65ba792af8
commit b3edbc2c4f
2 changed files with 74 additions and 25 deletions

View File

@@ -26,7 +26,7 @@ from datetime import datetime
# (c) ville.rantanen@helsinki.fi # (c) ville.rantanen@helsinki.fi
__version__='1.3' __version__='1.4'
webfilesearch=re.compile('.*index.html$|.*gallerystyle.css$|.*galleryscript.js$|.*descriptions.csv$|\..*',re.I) webfilesearch=re.compile('.*index.html$|.*gallerystyle.css$|.*galleryscript.js$|.*descriptions.csv$|\..*',re.I)
imagesearch=re.compile('.*\.jpg$|.*\.jpeg$|.*\.gif$|.*\.png$|.*\.svg$|.*\.pdf$',re.I) imagesearch=re.compile('.*\.jpg$|.*\.jpeg$|.*\.gif$|.*\.png$|.*\.svg$|.*\.pdf$',re.I)

View File

@@ -27,6 +27,8 @@ var currentimage=-1;
var currentlist=-1; var currentlist=-1;
var originals=false; var originals=false;
var preloader; var preloader;
var slideshowtimer;
var slideshowinterval;
function setup() { function setup() {
// Setup run at the load of page. // Setup run at the load of page.
@@ -35,7 +37,12 @@ function setup() {
} }
//hidethumbs(); //hidethumbs();
document.onkeydown=keypressed; 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) { if (req!=-1) {
showimage(req); showimage(req);
} else { } else {
@@ -104,14 +111,19 @@ function preload(i) {
function preloadcheck() { function preloadcheck() {
var imgs=document.getElementById('preloadcontainer').childNodes; var imgs=document.getElementById('preloadcontainer').childNodes;
var tob=document.getElementById('desccontainer'); 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; var completed=0;
for (i=0;i<imgs.length;i++) { for (i=0;i<imgs.length;i++) {
if (imgs[i].complete) { completed++; } if (imgs[i].complete) { completed++; }
} }
var colorValue=32*completed/imgs.length + 223; return completed;
tob.style.backgroundColor="rgb("+colorValue+","+colorValue+","+colorValue+")";
if (imgs.length==completed) { clearInterval(preloader); tob.style.backgroundColor="rgb(255,255,255)"; }
return
} }
function thumblist(n,curr) { function thumblist(n,curr) {
@@ -268,9 +280,13 @@ function sortlist(property) {
return; return;
} }
function request() { 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. // 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) { if ((query[0]=="q") && query.length>1 && query[1].length>0) {
for (imname in imagelist) { for (imname in imagelist) {
if (imagelist[imname].indexOf(unescape(query[1])) != -1) { if (imagelist[imname].indexOf(unescape(query[1])) != -1) {
@@ -279,6 +295,8 @@ function request() {
} }
} }
} }
}
if (type=="p") {
// Fetch ?p=position request and return the integer // Fetch ?p=position request and return the integer
if ((query[0]=="p") && query.length>1 && query[1].length>0) { if ((query[0]=="p") && query.length>1 && query[1].length>0) {
var retval=parseInt(query[1]); var retval=parseInt(query[1]);
@@ -287,7 +305,17 @@ function request() {
retval=Math.min(retval,imagelist.length); retval=Math.min(retval,imagelist.length);
return retval-1; 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;
}
}
}
return -1; return -1;
} }
@@ -421,7 +449,7 @@ function getmaxthumbs() {
} }
function hidethumbs() { function hidethumbs() {
// hide all thumbnails // hide all thumbnails (obsolete)
if (notsupported()) { if (notsupported()) {
return; return;
} }
@@ -431,6 +459,16 @@ function hidethumbs() {
return; 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) { function keypressed(e) {
//if (currentimage==-1) { return; } //if (currentimage==-1) { return; }
if (document.getElementById('marklist')!=null) { if (document.getElementById('marklist')!=null) {
@@ -439,37 +477,48 @@ function keypressed(e) {
var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode; var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode;
maxThumb=getmaxthumbs(); maxThumb=getmaxthumbs();
var shift=evtobj.shiftKey; var shift=evtobj.shiftKey;
// shift end: move to last image
if (unicode==35 && shift==1) { if (unicode==35 && shift==1) {
currentimage=imagelist.length-1; currentimage=imagelist.length-1;
showimage(currentimage); showimage(currentimage);
} }
// shift home: move to first item
if (unicode==36 && shift==1) { if (unicode==36 && shift==1) {
currentimage=0; currentimage=0;
showimage(currentimage); showimage(currentimage);
} }
// arrow left: move 1 left
if (unicode==37 && shift==0) { if (unicode==37 && shift==0) {
currentimage-=1; currentimage-=1;
if (currentimage<0) { currentimage=imagelist.length-1; } if (currentimage<0) { currentimage=imagelist.length-1; }
showimage(currentimage); showimage(currentimage);
} }
// shift arrow left: move 1 page left
if (unicode==37 && shift==1) { if (unicode==37 && shift==1) {
currentimage-=maxThumb; currentimage-=maxThumb;
if (currentimage<0) { currentimage=imagelist.length-1; } if (currentimage<0) { currentimage=imagelist.length-1; }
showimage(currentimage); showimage(currentimage);
} }
// arrow right: move 1 right
if (unicode==39 && shift==0) { if (unicode==39 && shift==0) {
currentimage+=1; currentimage+=1;
if (currentimage>(imagelist.length-1)) { currentimage=0; } if (currentimage>(imagelist.length-1)) { currentimage=0; }
showimage(currentimage); showimage(currentimage);
} }
// shift arrow right: move 1 page right
if (unicode==39 && shift==1) { if (unicode==39 && shift==1) {
currentimage+=maxThumb; currentimage+=maxThumb;
if (currentimage>(imagelist.length-1)) { currentimage=0; } if (currentimage>(imagelist.length-1)) { currentimage=0; }
showimage(currentimage); showimage(currentimage);
} }
// x: mark image
if (unicode==88) { if (unicode==88) {
markitem(currentimage); markitem(currentimage);
} }
if (slideshowinterval!=-1) {
clearInterval(slideshowtimer);
slideshowtimer=setInterval('slidenext()',1000*slideshowinterval);
}
//Debug: //Debug:
//alert(unicode); //alert(unicode);