only load image viewer when in file browser
This commit is contained in:
parent
153d8fec30
commit
277e644558
|
@ -1,55 +1,57 @@
|
||||||
var lightBoxShown=false;
|
if(typeof ileActions!=='undefined'){
|
||||||
$(document).ready(function() {
|
var lightBoxShown=false;
|
||||||
images={};//image cache
|
$(document).ready(function() {
|
||||||
var overlay=$('<div id="lightbox_overlay"/>');
|
images={};//image cache
|
||||||
$( 'body' ).append(overlay);
|
var overlay=$('<div id="lightbox_overlay"/>');
|
||||||
var container=$('<div id="lightbox"/>');
|
$( 'body' ).append(overlay);
|
||||||
$( 'body' ).append(container);
|
var container=$('<div id="lightbox"/>');
|
||||||
FileActions.register('image','View',function(filename){
|
$( 'body' ).append(container);
|
||||||
var location='ajax/download.php?files='+filename+'&dir='+$('#dir').val();
|
FileActions.register('image','View',function(filename){
|
||||||
overlay.show();
|
var location='ajax/download.php?files='+filename+'&dir='+$('#dir').val();
|
||||||
if(!images[location]){
|
overlay.show();
|
||||||
var img = new Image();
|
if(!images[location]){
|
||||||
img.onload = function(){
|
var img = new Image();
|
||||||
images[location]=img;
|
img.onload = function(){
|
||||||
showLightbox(container,img);
|
images[location]=img;
|
||||||
|
showLightbox(container,img);
|
||||||
|
}
|
||||||
|
img.src = location;
|
||||||
|
}else{
|
||||||
|
showLightbox(container,images[location]);
|
||||||
}
|
}
|
||||||
img.src = location;
|
});
|
||||||
}else{
|
$( 'body' ).click(hideLightbox);
|
||||||
showLightbox(container,images[location]);
|
FileActions.setDefault('image','View');
|
||||||
}
|
|
||||||
});
|
});
|
||||||
$( 'body' ).click(hideLightbox);
|
|
||||||
FileActions.setDefault('image','View');
|
|
||||||
});
|
|
||||||
|
|
||||||
function showLightbox(container,img){
|
function showLightbox(container,img){
|
||||||
var maxWidth = $( window ).width() - 50;
|
var maxWidth = $( window ).width() - 50;
|
||||||
var maxHeight = $( window ).height() - 50;
|
var maxHeight = $( window ).height() - 50;
|
||||||
if( img.width > maxWidth || img.height > maxHeight ) { // One of these is larger than the window
|
if( img.width > maxWidth || img.height > maxHeight ) { // One of these is larger than the window
|
||||||
var ratio = img.width / img.height;
|
var ratio = img.width / img.height;
|
||||||
if( img.height >= maxHeight ) {
|
if( img.height >= maxHeight ) {
|
||||||
img.height = maxHeight;
|
img.height = maxHeight;
|
||||||
img.width = maxHeight * ratio;
|
img.width = maxHeight * ratio;
|
||||||
} else {
|
} else {
|
||||||
img.width = maxWidth;
|
img.width = maxWidth;
|
||||||
img.height = maxWidth * ratio;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue