You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.7 KiB
69 lines
1.7 KiB
7 years ago
|
|
||
|
/* - ++resource++static/js/photo-gallery.js - */
|
||
|
$(document).ready(function(){
|
||
|
$('li img').on('click',function(){
|
||
|
var src = $(this).attr('src');
|
||
|
var img = '<img src="' + src + '" class="img-responsive"/>';
|
||
|
|
||
|
//start of new code new code
|
||
|
var index = $(this).parent('li').index();
|
||
|
|
||
|
var html = '';
|
||
|
html += img;
|
||
|
html += '<div style="height:25px;clear:both;display:block;">';
|
||
|
html += '<a class="controls next" href="'+ (index+2) + '">próximo </a>';
|
||
|
html += '<a class="controls previous" href="' + (index) + '"> anterior</a>';
|
||
|
html += '</div>';
|
||
|
|
||
|
$('#myModal').modal();
|
||
|
$('#myModal').on('shown.bs.modal', function(){
|
||
|
$('#myModal .modal-body').html(html);
|
||
|
//new code
|
||
|
$('a.controls').trigger('click');
|
||
|
})
|
||
|
$('#myModal').on('hidden.bs.modal', function(){
|
||
|
$('#myModal .modal-body').html('');
|
||
|
});
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
});
|
||
|
})
|
||
|
|
||
|
|
||
|
$(document).on('click', 'a.controls', function(){
|
||
|
var index = $(this).attr('href');
|
||
|
var src = $('ul.row li:nth-child('+ index +') img').attr('src');
|
||
|
|
||
|
$('.modal-body img').attr('src', src);
|
||
|
|
||
|
var newPrevIndex = parseInt(index) - 1;
|
||
|
var newNextIndex = parseInt(newPrevIndex) + 2;
|
||
|
|
||
|
if($(this).hasClass('previous')){
|
||
|
$(this).attr('href', newPrevIndex);
|
||
|
$('a.next').attr('href', newNextIndex);
|
||
|
}else{
|
||
|
$(this).attr('href', newNextIndex);
|
||
|
$('a.previous').attr('href', newPrevIndex);
|
||
|
}
|
||
|
|
||
|
var total = $('ul.row li').length + 1;
|
||
|
//hide next button
|
||
|
if(total === newNextIndex){
|
||
|
$('a.next').hide();
|
||
|
}else{
|
||
|
$('a.next').show()
|
||
|
}
|
||
|
//hide previous button
|
||
|
if(newPrevIndex === 0){
|
||
|
$('a.previous').hide();
|
||
|
}else{
|
||
|
$('a.previous').show()
|
||
|
}
|
||
|
|
||
|
|
||
|
return false;
|
||
|
});
|