Hi fhya:
In my theme/items/show.php, at the beginning when it get the files there where I collect all the images that associate with the item:
===
<!-- The following returns all of the files associated with an item. -->
<?php if (metadata($item, 'has files')): ?>
<div id="itemfiles" class="element">
<h3>Images</h3>
<div class="element-text">
<?php //the following to get all the images associate with an item and build a popup window to display all the images
$image_files = array();
$pdf_files = array();
$image_filenames = array();
$pdf_original_names = array();
$thumbnails = array();
foreach($item->Files as $f)
{
$mime = $f["mime_type"];
// echo WEB_ROOT; //http://localhost/omeka
if(isImg($mime))
{
//$file is image
$imguri = new imageUrl();
$imguri->image = $f->getProperty('fullsize_uri');
$imguri ->thumbnail = $f->getProperty('thumbnail_uri');
array_push($thumbnails, $f->getProperty('thumbnail_uri'));
array_push($image_files, $imguri);
array_push($image_filenames, metadata($f, 'filename')); //save the file name only --will be use to display the thumnail
}
else{
//pdf file or other format
$pdf_file = WEB_ROOT . '/files/original/' . metadata($f, 'filename');
array_push($pdf_files, $pdf_file);
array_push($pdf_original_names, metadata($f, 'original_filename'));
}
}
//iterate through
//only display 1st image
foreach($thumbnails as $img=>$url)//foreach loop to display the first thumbnail
{
$thumnail_url = $url;
echo '<button id="show-gallery" style="border:none;"><img src="' . $thumnail_url .'" /></button>'; //display 1st thumbnail and get out.
?>
<!--<button id="show-gallery" > View Gallery </button>-->
<?php $itmTitle = metadata($item, array('Dublin Core', 'Title')); ?>
<script type="text/javascript">
var gallery = JSON.parse('<?php echo json_encode($image_files); ?>');
var galleryTitle = <?php echo json_encode($itmTitle); ?>;
</script>
<?php
break;
} // end of foreach loop to display the first thumbnail
//display pdf files
===
Display first image as a button image and execute the js on the click event.
The js is rather long:
=====
jQuery(function($){
var imagewidget = {};
(function(){
var gallery = [];
var galleryTitle = "";
var isZoom = false;
var thumbWidth = 0;
var thumbStripWidth = 0;
var thumbPerPage = 0;
var scrollOffset = 0;
var selectedIndex = 0;
var currentPage = 0;
var scrollAnimationTime = 700;
imagewidget.setup = function(_gallery, _galleryTitle) {
gallery = _gallery;
galleryTitle = _galleryTitle
// insert modal html
var modalString = '<div class="modal fade" id="galleryModal">'+
' <div class="modal-dialog">'+
' <div class="modal-content">'+
' <div class="modal-header">'+
' <div id="close-container"><button id="close-button" class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button></div>'+
' <div id="zoom-container"><button id="zoom-button" class="btn btn-success"><span class="glyphicon glyphicon-zoom-in" aria-hidden="true"></span></button></div>'+
' <div id="download-container"><span class="glyphicon glyphicon-download" aria-hidden="true"></span></div>'+
' <h4 class="modal-title">'+galleryTitle+'</h4>'+
' </div>'+
' <div class="modal-body">'+
' <div id="gallery-viewport">'+
' <img src="" id="gallery-image" />'+
' </div>'+
' <div id="left-container">'+
' <button id="left-page-button" href="" class="btn btn-primary"><span class="glyphicon glyphicon-fast-backward" aria-hidden="true"></span></button> '+
' <button id="left-button" href="" class="btn btn-primary"><span class="glyphicon glyphicon-step-backward" aria-hidden="true"></span></button> '+
' </div>'+
' <div id="right-container">'+
' <button id="right-button" href="" class="btn btn-primary"><span class="glyphicon glyphicon-step-forward" aria-hidden="true"></span></button> '+
' <button id="right-page-button" href="" class="btn btn-primary"><span class="glyphicon glyphicon-fast-forward" aria-hidden="true"></span></button> '+
' </div>'+
' <div id="gallery-thumbnail-strip">'+
' <div id="gallery-strip">';
$.each(gallery, function(i, v){
modalString += '<div> <img class="gallery-thumbnail unselected-thumbnail" src="'+v.thumbnail+'" /> </div>';
});
modalString += ' </div>'+
' </div>'+
' </div>'+
' </div>'+
' </div>'+
'</div>';
$("body").append($(modalString));
$(".gallery-thumbnail").click(function() {
selectedIndex = $(".gallery-thumbnail").index(this);
setImageToSelected();
});
$('#gallery-viewport').click(function(){
isZoom = ! isZoom;
setZoom();
});
$("#zoom-button").click(function(){
isZoom = ! isZoom;
setZoom();
});
var leftMove = function() {
if (--selectedIndex < 0) {
selectedIndex = 0;
}
setImageToSelected();
}
var rightMove = function() {
if (++selectedIndex >= gallery.length) {
selectedIndex = gallery.length-1;
}
setImageToSelected();
}
$('#left-button').click(function(){
leftMove()
});
$('#right-button').click(function(){
rightMove();
});
var scrollPageLeft = function() {
if (--currentPage < 0) {
currentPage = 0;
} else {
setToPage();
}
}
var scrollPageRight = function() {
if (++currentPage > Math.floor(gallery.length / thumbPerPage)) {
--currentPage;
} else {
setToPage();
}
}
$('#left-page-button').click(function() {
scrollPageLeft()
});
$('#right-page-button').click(function() {
scrollPageRight();
});
$(document).keydown(function(e) {
switch(e.which) {
case 37: // left
leftMove();
break;
case 38: // up
isZoom = true;
setZoom();
break;
case 39: // right
rightMove();
break;
case 40: // down
isZoom = false;
setZoom();
break;
default: return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
});
}
var performScroll = function() {
var newScroll = currentPage * thumbPerPage * thumbWidth;
$( "#gallery-thumbnail-strip" ).animate({
scrollLeft: newScroll,
}, scrollAnimationTime, function() {
// Animation complete.
});
};
var setZoom = function() {
if (isZoom) {
$("#gallery-image").css('max-height', $('#gallery-image')[0].naturalHeight);
$("#gallery-image").css('max-width', $('#gallery-image')[0].naturalWidth);
$("#zoom-button span").removeClass("glyphicon-zoom-in");
$("#zoom-button span").addClass("glyphicon-zoom-out");
} else {
$("#gallery-image").css('max-height', Math.floor($('.modal-content').height() * 0.80 -60) + 'px');
$("#gallery-image").css('max-width', Math.floor($('.modal-content').width() * 0.80) + 'px');
$("#zoom-button span").removeClass("glyphicon-zoom-out");
$("#zoom-button span").addClass("glyphicon-zoom-in");
}
}
var calculatePages = function() {
thumbStripWidth = Math.floor($('.modal-content').width() - 200);
$("#gallery-thumbnail-strip").width(thumbStripWidth + 'px');
thumbWidth = $("#gallery-strip div:first").width();
thumbPerPage = Math.floor(thumbStripWidth/thumbWidth);
}
var resizeModal = function() {
$('.modal-dialog').css('width', '95%')
$('.modal-content').css('height', Math.floor($(window).height() * 0.90) + 'px')
setZoom();
var thumbnailSize = Math.floor($('.modal-content').height() * 0.23 -60) + 'px';
$(".gallery-thumbnail").css('height', thumbnailSize);
$(".gallery-thumbnail").css('width', thumbnailSize);
calculatePages();
$("#gallery-viewport").css('height', Math.floor($('.modal-content').height() * 0.80 -60) + 'px');
}
var setImageToSelected = function() {
isZoom = false;
setZoom();
$("#gallery-strip div img").removeClass('selected-thumbnail');
$("#gallery-strip div img").addClass('unselected-thumbnail');
$("#gallery-strip div:eq("+selectedIndex+") img").addClass('selected-thumbnail');
$("#gallery-image").attr("src", gallery[selectedIndex].image);
$('#download-button').attr('href', gallery[selectedIndex].image);
var selectedPage = Math.floor(selectedIndex / thumbPerPage);
if (currentPage != selectedPage){
currentPage = selectedPage;
performScroll();
}
setEnabledButtons();
}
var setToPage = function() {
performScroll();
selectedIndex = currentPage * thumbPerPage;
setImageToSelected();
}
var setEnabledButtons = function() {
if (currentPage == 0) {
$('#left-page-button').attr('disabled', 'disabled');
} else {
$('#left-page-button').removeAttr('disabled');
}
if (selectedIndex == 0) {
$('#left-button').attr('disabled', 'disabled');
} else {
$('#left-button').removeAttr('disabled');
}
if (selectedIndex == gallery.length -1) {
$('#right-button').attr('disabled', 'disabled');
} else {
$('#right-button').removeAttr('disabled');
}
if (selectedIndex != 0 && currentPage == Math.floor(gallery.length / thumbPerPage) ) {
$('#right-page-button').attr('disabled', 'disabled');
} else {
$('#right-page-button').removeAttr('disabled');
}
}
imagewidget.showGallery = function() {
$('#galleryModal').modal('show');
resizeModal();
$('#galleryModal').on('shown.bs.modal', function() {
selectedIndex = 0;
currentPage = 0;
calculatePages();
setImageToSelected();
$("#gallery-thumbnail-strip").scrollLeft(0);
});
}
$(window).resize(function() {
resizeModal();
});
})();
$("#show-gallery").click(function(){
imagewidget.showGallery();
});
imagewidget.setup(gallery, galleryTitle);
});
======
Hope that help.
Cheers,
Melania