Added escape key support to close current image.

This commit is contained in:
grmrgecko 2013-06-22 07:27:35 -05:00
parent fc7c34eb4c
commit d2f7bfebaf

View File

@ -284,8 +284,20 @@ function loadImage(image, animate, urlHistory) {
} }
$(document).ready(function() { $(document).ready(function() {
function escapeListen(listen) {
if (listen==false) {
$(document).off("keyup.dismiss.modal");
} else {
$(document).on("keyup.dismiss.modal", function(event) {
if (event.which==27) {
closeImageViewer();
}
});
}
}
$("#images_main").on("click", ".image", function() { $("#images_main").on("click", ".image", function() {
loadImage($(this), 0); loadImage($(this), 0);
escapeListen(true);
}); });
$("#imageViewer_previousButton").click(function() { $("#imageViewer_previousButton").click(function() {
repositionImage(4); repositionImage(4);
@ -318,6 +330,7 @@ $(document).ready(function() {
} }
} }
currentState = 2; currentState = 2;
escapeListen(false);
} }
$("#backdrop, #imageViewer_close").click(closeImageViewer); $("#backdrop, #imageViewer_close").click(closeImageViewer);
$(window).resize(function() { $(window).resize(function() {
@ -366,12 +379,18 @@ $(document).ready(function() {
return; return;
} }
$("#imageViewer_confirmDelete").modal(); $("#imageViewer_confirmDelete").modal();
escapeListen(false);
}); });
$("#imageViewer_confirmDelete_yes").click(function() { $("#imageViewer_confirmDelete_yes").click(function() {
$("#imageViewer_apiloader").load("<?=generateURL("api/delete")?>/", {hash: imageViewing}); $("#imageViewer_apiloader").load("<?=generateURL("api/delete")?>/", {hash: imageViewing});
closeImageViewer(); closeImageViewer();
$("#images_main .image[hash='"+imageViewing+"']").remove(); $("#images_main .image[hash='"+imageViewing+"']").remove();
}); });
$("#imageViewer_confirmDelete").on('hidden', function() {
if (!$("#backdrop").hasClass("hide")) {
escapeListen(true);
}
})
<?}?> <?}?>
<?}?> <?}?>
@ -402,6 +421,7 @@ $(document).ready(function() {
if (image.length>0) { if (image.length>0) {
if ($("#backdrop").hasClass("hide")) { if ($("#backdrop").hasClass("hide")) {
loadImage(image, 0, true); loadImage(image, 0, true);
escapeListen(true);
} else { } else {
loadImage(image, 1, true); loadImage(image, 1, true);
} }