/*
Copyright 2011 Ville Rantanen
This program is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .
*/
var maxThumb=10;
var uagent = navigator.userAgent.toLowerCase();
var pathlist=[];
var pathimage=[];
var imagelist=[];
var filelist=[];
var imagedesc=[];
var imagetime=[];
var marklist=[]
var currentimage=-1;
var currentlist=-1;
var originals=false;
function setup() {
// Setup run at the load of page.
if (notsupported()) {
return;
}
hidethumbs();
document.onkeydown=keypressed;
var req=request();
if (req!=-1) {
showimage(req);
} else {
thumblist(0,-1);
subfolderbiglist();
}
return;
}
function showimage(i) {
// Main function to show a single image
if (i>imagelist.length-1 || i<0) { return; }
thumblist(i,i);
showbigimage(i);
preload(i);
subfoldersmalllist();
currentimage=i;
return;
}
function showbigimage(i) {
// The medium version of image in the big image container
if (i==-1) { return; }
ob=document.getElementById('imagecontainer');
width=document.body.clientWidth-30;
height=document.body.clientHeight-225;
if (originals) { mediumstr=encodeURIComponent(imagelist[i]); }
else { mediumstr='_med/med_'+encodeURIComponent(imagelist[i])+'.jpg'; }
ob.innerHTML='

';
document.getElementById('imagesingle').style.maxWidth=width;
ob.style.height=height;
document.getElementById('imagesingle').style.maxHeight=height;
dc=document.getElementById('desccontainer');
dc.innerHTML=currentlink(i)+imagedesc[i];
dc.style.display='block';
return;
}
function currentlink(i) {
// gets the search term for this image
index = location.href.split("?");
s='['+String(i+1)+'] ';
return s;
}
function preload(i) {
// preloads left and right images
if (imagelist.length==0) { return; }
ob=document.getElementById('preloadcontainer');
right=Math.max(0,i+1);
right=Math.min(right,imagelist.length-1);
left=Math.max(0,i-1);
left=Math.min(left,imagelist.length-1);
if (originals) {
prestr='
';
prestr+='
';
} else {
prestr='
';
prestr+='
';
}
ob.innerHTML=prestr;
return;
}
function thumblist(n,curr) {
// creates the short thumbnail list
maxThumb=getmaxthumbs();
if (imagelist.length==0) { return; }
ob=document.getElementById('thumbcontainer');
ob.style.width=document.body.clientWidth-30;
startI=Math.max(0,n+1-Math.round((maxThumb/2)));
startI=Math.min(startI,imagelist.length-maxThumb);
startI=Math.max(0,startI);
endI=Math.min(startI+maxThumb,imagelist.length);
currentlist=endI;
nright=endI-Math.round((maxThumb/2))+maxThumb-1;
nleft=nright-maxThumb-maxThumb;
if (maxThumb%2==1) { nright+=1; nleft+=1; }
leftstr='← ('+startI+')
';
rightstr='→ ('+(imagelist.length-endI)+')
';
menustr='';
thumbstr='Images'+menustr+'
';
ob.innerHTML=thumbstr;
if (curr>-1) {
c=document.getElementById('n'+curr);
if (c) {c.className="imagebox thumbbox rounded"; }
}
if (marklist.length>0) {
for (m in marklist) {
var mth=document.getElementById('n'+marklist[m])
if (mth!=null) {
mth.className+=" marked";
}
}
}
return;
}
function allthumbs() {
// Shows all the thumbnails in the current folder
ob=document.getElementById('thumbcontainer');
thumbstr='Images
';
ob.innerHTML=thumbstr;
ic=document.getElementById('imagecontainer');
ic.innerHTML='';
ic.style.height=0;
dc=document.getElementById('desccontainer');
dc.style.display='none';
currentimage=-1;
return;
}
function subfoldersmalllist() {
// Shows a small subfolder list
ob=document.getElementById('pathcontainer');
pathstr='Subfolders: ';
for (p=0; p'+nicestring(pathlist[p][0])+'('+String(pathlist[p][1])+')/ ';
}
pathstr+='';
if (pathlist.length==0) {
ob.innerHTML='';
} else { ob.innerHTML=pathstr; }
return;
}
function subfolderbiglist() {
// Shows a subfolder list with thumbnails
ob=document.getElementById('pathcontainer');
pathstr='Subfolders:
';
for (p=0; p0) {
imgstr='';
} else { imgstr=''; }
pathstr+=''+imgstr+''+nicestring(pathlist[p][0])+' ('+String(pathlist[p][1])+')';
}
if (pathlist.length==0) {
ob.innerHTML='';
} else { ob.innerHTML=pathstr; }
return;
}
function sortlist(property) {
// sorts the image list based on time or name, or reverse sort
var templist=[]
var tempmark=[]
var tempcurrent=imagelist[currentimage];
for (i in imagelist) {
templist.push({name:imagelist[i], time:imagetime[i], desc:imagedesc[i]});
}
for (i in marklist) {
tempmark.push(imagelist[marklist[i]]);
}
if (property=='time') {
templist.sort(function(a,b) {
return a.time-b.time
})
}
if (property=='alpha') {
templist.sort(function(a, b){
if (a.name < b.name)
return -1
if (a.name > b.name)
return 1
return 0
})
}
if (property=='rev') {
templist.reverse();
}
for (i in imagelist) {
imagelist[i]=templist[i].name;
imagetime[i]=templist[i].time;
imagedesc[i]=templist[i].desc;
if (imagelist[i] == tempcurrent) {
currentimage=i;
}
}
var markidx=0;
marklist=[];
for (i in tempmark) {
markidx=imagelist.indexOf(tempmark[i]);
if (markidx!=-1) {
marklist.push(markidx);
}
}
thumblist(currentimage,currentimage);
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;
}
}
}
// 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;
}
function markitem(i) {
// Adds an item in a list of selected images
if (imagelist.length==0) { return; }
if (i==-1) { return; }
var lel=document.getElementById('listcontainer');
if (lel.innerHTML.length<4) {
lel.innerHTML='';
}
var existidx=marklist.indexOf(i);
if (existidx==-1) {
marklist.push(i);
} else {
marklist.splice(existidx,1);
}
marklisteditor();
showimage(i);
return;
}
function unmarkitem(i) {
// remove an item from selection list
marklist.splice(i,1);
marklisteditor();
showimage(currentimage);
return;
}
function marklisteditor() {
// print out an editor view of the selection list
var mel=document.getElementById('marklist');
var liststr='';
var dlstr='X'+
'';
dlstr+=imagelist[marklist[i]]+'%0A';
}
dlstr+='">Download as file';
liststr+='';
mel.innerHTML=liststr;
return;
}
function marklisttable() {
// print out a copy-pastable text box of the selection list
var mel=document.getElementById('marklist');
mel.innerHTML='';
var cel=document.getElementById('marktable');
cel.onclick=marklistselect;
cel.onblur=marklistblur;
cel.cols=80;
cel.hasfocus=false;
for (i in marklist) {
cel.value=cel.value+'"'+imagelist[marklist[i]]+'"\r\n';
}
var rows=cel.value.split(/\r?\n|\r/).length + 1;
cel.rows=rows;
marklistselect();
return;
}
function deletemarklist() {
// delete the selection list
var answer = confirm("Delete your selection list?")
if (answer) {
var lel=document.getElementById('listcontainer');
lel.innerHTML='';
marklist=[];
showimage(currentimage);
}
return
}
function marklistselect() {
// set focus to selection list text area
var cel=document.getElementById('marktable');
cel.hasfocus=true;
cel.select();
}
function marklistblur() {
// set blur to selection list text area
var cel=document.getElementById('marktable');
cel.hasfocus=false;
}
function nicestring(s) {
// Return a nice version of a string
s=String(s);
if (s.length<20) {
return s;
}
s=s.replace(/_/g,' ');
s=s.replace(/-/g,' ');
if (s.length>30) {
s=s.substring(0,26)+'..'+s.substring(s.length-4);
}
return s;
}
function titlestring(s) {
// Return a nice version of a string for title attribute
s=s.replace(/"/g,""");
s=s.replace(/<\/?[^>]+(>|$)/g, "");
return s;
}
function fliporiginals() {
// Use original images / medium size jpegs
if (originals)
{ originals=false; }
else
{ originals=true; }
showimage(currentimage);
}
function getmaxthumbs() {
return Math.floor((document.body.clientWidth-30)/100)-2;
}
function hidethumbs() {
// hide all thumbnails
if (notsupported()) {
return;
}
for (n=0; n(imagelist.length-1)) { currentimage=0; }
showimage(currentimage);
}
if (unicode==39 && shift==1) {
currentimage+=maxThumb;
if (currentimage>(imagelist.length-1)) { currentimage=0; }
showimage(currentimage);
}
if (unicode==88) {
markitem(currentimage);
}
//Debug:
//alert(unicode);
return;
}
function notsupported() {
// not supported devices (i.e. the javascript doesnt work properly )
if (uagent.search('series60')>-1) {
return true;
}
if (uagent.search('opera mobi')>-1) {
return true;
}
return false;
}