summaryrefslogtreecommitdiffstats
path: root/apps/files_imageviewer/js/lightbox.js
diff options
context:
space:
mode:
authorRobin Appelman <icewind1991@gmail.com>2011-06-04 20:43:32 +0200
committerRobin Appelman <icewind1991@gmail.com>2011-06-04 20:48:53 +0200
commit4b9665a952e723075185b7ef8837c9e38432f63a (patch)
treec9d256b64cd3b96bf2fad524654714bcfb70bef8 /apps/files_imageviewer/js/lightbox.js
parent1eb0faa2642babdd3031fdfa611ee10d1a3ccec5 (diff)
downloadnextcloud-server-4b9665a952e723075185b7ef8837c9e38432f63a.tar.gz
nextcloud-server-4b9665a952e723075185b7ef8837c9e38432f63a.zip
image viewer plugin
Diffstat (limited to 'apps/files_imageviewer/js/lightbox.js')
-rw-r--r--apps/files_imageviewer/js/lightbox.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/apps/files_imageviewer/js/lightbox.js b/apps/files_imageviewer/js/lightbox.js
new file mode 100644
index 00000000000..dd091aa0d77
--- /dev/null
+++ b/apps/files_imageviewer/js/lightbox.js
@@ -0,0 +1,46 @@
+$(document).ready(function() {
+ images={};//image cache
+ FileActions.register('image','View',function(filename){
+ var location='ajax/download.php?files='+filename+'&dir='+$('#dir').val();
+ var overlay=$('<div id="lightbox_overlay"/>');
+ $( 'body' ).append(overlay);
+ var container=$('<div id="lightbox"/>');
+ $( 'body' ).append(container);
+ if(!images[location]){
+ var img = new Image();
+ img.onload = function(){
+ images[location]=img;
+ showLightbox(container,img);
+ }
+ img.src = location;
+ }else{
+ showLightbox(container,images[location]);
+ }
+ });
+ $( 'body' ).click(hideLightbox);
+ FileActions.setDefault('image','View');
+});
+
+function showLightbox(container,img){
+ var maxWidth = $( window ).width() - 50;
+ var maxHeight = $( window ).height() - 50;
+ if( img.width > maxWidth || img.height > maxHeight ) { // One of these is larger than the window
+ var ratio = img.width / img.height;
+ if( img.height >= maxHeight ) {
+ img.height = maxHeight;
+ img.width = maxHeight * ratio;
+ } else {
+ img.width = maxWidth;
+ img.height = maxWidth * ratio;
+ }
+ }
+ container.empty();
+ container.append(img);
+ container.css('top',Math.round( ($( window ).height() - img.height)/2));
+ container.css('left',Math.round( ($( window ).width() - img.width)/2));
+}
+
+function hideLightbox(){
+ $('#lightbox_overlay').remove();
+ $('#lightbox').remove();
+} \ No newline at end of file