Welcome to mirror list, hosted at ThFree Co, Russian Federation.

lightbox.js « js « files_imageviewer « apps - github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6e45547ebb4bdb3bd81e4b206cfa36b7c6c1ca40 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

var lightBoxShown=false;
$(document).ready(function() {
	if(typeof FileActions!=='undefined'){
		images={};//image cache
		var overlay=$('<div id="lightbox_overlay"/>');
		$( 'body' ).append(overlay);
		var container=$('<div id="lightbox"/>');
		$( 'body' ).append(container);
		FileActions.register('image','View',function(filename){
			var location='ajax/download.php?files='+filename+'&dir='+$('#dir').val();
			overlay.show();
			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));
	$('#lightbox').show();
	setTimeout(function(){
		lightBoxShown=true;
	},100);
}

function hideLightbox(){
	if(lightBoxShown){
		$('#lightbox_overlay').hide();
		$('#lightbox').hide();
		lightBoxShown=false;
	}
}