diff --git a/src/main.c b/src/main.c index 8cb7735..fb40a40 100644 --- a/src/main.c +++ b/src/main.c @@ -323,20 +323,24 @@ void photo_handler( struct gallery_info* gallery, gc->photos->string[ gc->photos->length - 1 ] ); /* Requested settings pass-thru -- if differing from defaults */ - if ( width != DEFAULT_WIDTH ) - hdf_set_int_value( cgi->hdf, "settings.width", width ); - if ( height != DEFAULT_HEIGHT ) - hdf_set_int_value( cgi->hdf, "settings.height", height ); - if ( quality != DEFAULT_QUALITY ) - hdf_set_int_value( cgi->hdf, "settings.quality", quality ); + hdf_set_int_value( cgi->hdf, "settings.width", width ); + hdf_set_int_value( cgi->hdf, "settings.height", height ); + hdf_set_int_value( cgi->hdf, "settings.quality", quality ); hdf_set_value( cgi->hdf, "settings.rotation", rotation_str ); hdf_set_int_value( cgi->hdf, "photo.origwidth", photo->meta.size.width ); hdf_set_int_value( cgi->hdf, "photo.origheight", photo->meta.size.height ); - hdf_set_int_value( cgi->hdf, "photo.width", dims.width ); - hdf_set_int_value( cgi->hdf, "photo.height", dims.height ); + if ( original ) { + hdf_set_int_value( cgi->hdf, "photo.width", + photo->meta.size.width ); + hdf_set_int_value( cgi->hdf, "photo.height", + photo->meta.size.height ); + } else { + hdf_set_int_value( cgi->hdf, "photo.width", dims.width ); + hdf_set_int_value( cgi->hdf, "photo.height", dims.height ); + } if ( photo->annotation != NULL ) diff --git a/templates/lib.js b/templates/lib.js new file mode 100644 index 0000000..a54120b --- /dev/null +++ b/templates/lib.js @@ -0,0 +1,96 @@ +function getXHR() { + var httpRequest; + if (window.XMLHttpRequest) { // Mozilla, Safari, ... + httpRequest = new XMLHttpRequest(); + } else if (window.ActiveXObject) { // IE + httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); + } + return httpRequest; +} + +function fetchImage( width, height ) { + data = getData(); + xhr = getXHR(); + photo_obj = document.getElementById( 'photoimg' ); + + xhr.onreadystatechange = function() { + if ( xhr.readyState == 4) { + document.zoom_en = true; + if ( xhr.status == 200 ) { + eval( 'data=' + xhr.responseText ); + photo_obj.src = + data.uri + '/' + data.photo.resized; + document.data = data; + } + } + }; + + /* Note the requested size */ + document.requestWidth = width; + document.requestHeight = height; + + /* Cancel any existing timers */ + if ( document.zoom_timer ) + window.clearTimeout( document.zoom_timer ); + + /* Set a timer to fetch this data after a 3 second delay */ + url = document.location.protocol + "//" + + document.location.hostname + + document.location.pathname + + '?width=' + Math.round(width) + + '&height=' + Math.round(height) + + '&quality=' + data.settings.quality + + '&json=1'; + + document.zoom_timer = window.setTimeout( function() { + document.zoom_en = false; + xhr.open('GET', url ); + xhr.send(null); + document.zoom_timer = false; + }, 3000 ); +} + +function setZoom( zoom ) { + data = getData(); + + document.zoom = zoom; + width = data.photo.origwidth*zoom; + height = data.photo.origheight*zoom; + + photo_obj = document.getElementById( 'photoimg' ); + if ( photo_obj ) { + photo_obj.width = width; + photo_obj.height = height; + + /* If the size is bigger than our present image, request a + * bigger one from the server. */ + if ( ( width > data.photo.width ) || + ( height > data.photo.height ) ) { + fetchImage( width, height ); + } + } + zoomlabel = document.getElementById( 'zoomlabel' ); + if ( zoomlabel ) { + zoomlabel.innerHTML = zoom; + } +} + +function resetZoom() { + data = getData(); + if ( document.zoom_en ) + setZoom( data.photo.zoom ); +} + +function adjustZoom( amount ) { + data = getData(); + if ( document.zoom == null ) + document.zoom = data.photo.zoom; + if ( document.zoom_en ) + setZoom( document.zoom + amount ); +} + +function wheelHandler( delta ) { + if ( document.zoom_en ) + adjustZoom( delta * 0.01 ); +} +document.zoom_en = true; diff --git a/templates/photo.cs b/templates/photo.cs index e7e101e..5b05310 100644 --- a/templates/photo.cs +++ b/templates/photo.cs @@ -5,6 +5,47 @@ body { }
Quality: (100% = PNG)
-
+
+ Zoom:
+ [-0.1]
+ [-0.01]
+ [1.0]
+ [+0.01]
+ [+0.1]
+ [reset]