you could use the JQueryUI dialog, or Bootstrap's Modal I personally use bootstrap's modal as i already load bootstrap for making responsive pages.
Bootstrap example
<div id="ModalEditor" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="modalLabel">Editor</h3>
</div>
<div class="modal-body">
//Put the contents of the dialog here
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button id="doneBtn" class="btn btn-success" data-dismiss="modal" aria-hidden="true">Done</button>
</div>
</div>
Javascript
$.ajax({
url:"someurl.com/getImages.php",
dataType:"json",
success:function(data) {
//insert your images into the modal body
for(var i=0; i<data.images.length; i++) {
var someimage = $('<img src="'+data.images[i].src+'" />') //make the image element however with whatever data you get
$("#ModalEditor .modal-body").append( someimage );
someimage.click(function() { $("#container").append($(this)); });
}
$("#ModalEditor").modal();
}
});
Hiding, Toggling
$("#ModalEditor").modal('hide') // will hide modal
$("#ModalEditor").modal('toggle') // will toggle the modal visible/hidden
Bootstrap also has premade stuff so you dont have to write code to trigger a modal for instance
<button type="button" data-toggle="modal" data-target="#ModalEditor">Launch modal</button>
Will trigger the modal toggle.
Also if you want to only like 1 image from the modal inserted just use a
$("#ModalEditor").modal('hide');
in the image click anon function to hide the modal after the image has been inserted.
Other things you could do:
- Generate the html of the images in the ajax call and save it so you can just reuse that html whenever you need to show the modal (if you change the contents of the modal-body inbetween calls)
Use below instead of having to set the click event for each image.
$("#ModalEditor .modal-body img").on("click",function() { $("#container").append($(this)); });