Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve keyboard accessibility of slideshow gallery #510

Merged
merged 3 commits into from
Mar 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions lib/wraith/gallery_template/slideshow_template.erb
Original file line number Diff line number Diff line change
Expand Up @@ -108,28 +108,41 @@
</style>
<script type="text/javascript">
$(function() {
$('.slideshow').cycle({
var slideshow = $('.slideshow');
var compareModal = $('.compare-modal');

slideshow.cycle({
fx: 'scrollHorz',
speed: 300,
prev: '.prev',
next: '.next',
before: function (curr, next, opts) {
$('.current').removeClass('current');
var path = $(next).find('.path').attr('name');
var $next = $(next);
var path = $next.find('.path').attr('name');
$.each($('.list-group .list-group-item a'), function() {
if ($(this).attr('href').substring(1) == path) {
$(this).parent().addClass('checked');
$(this).parent().addClass('current');
}
})
});

var newImage = $next.find('a.shot:eq(0)').attr('href');
var oldImage = $next.find('a.shot:eq(1)').attr('href');
var diffImage = $next.find('a.shot:eq(2)').attr('href');
compareModal.html('<div class="compare-container"><img src="'+newImage+'"/><img src="'+oldImage+'"/><img src="'+diffImage+'"/></div>');
},
timeout: 0
});

$(document).on('click', '.compare', function() {
compareModal.show();
});

$('.list-group .list-group-item a').unbind().on('click', function(){
var href = $(this).attr('href').substring(1);

$('.slideshow').cycle($('.slide.'+href+':first').index());
slideshow.cycle($('.slide.'+href+':first').index());
})

$('.shot').unbind().on('click', function(e){
Expand All @@ -138,20 +151,24 @@
window.open(url,'_blank');
})

$('.compare').unbind().on('click', function(){
var slide = $(this).closest(".slide"),
newImage = slide.find('a.shot:eq(0)').attr('href'),
oldImage = slide.find('a.shot:eq(1)').attr('href'),
diffImage = slide.find('a.shot:eq(2)').attr('href');
$('.container').append('<div class="compare-modal"><div class="compare-container"><img src="'+newImage+'"/><img src="'+oldImage+'"/><img src="'+diffImage+'"/></div></div>');
$('.compare-modal').unbind().on('click', function(){
$(this).remove();
})
})
compareModal.on('click', function(){
$(this).hide();
});

$(document).on('keyup', function(e) {
if (e.keyCode === 27) { // Escape
compareModal.hide();
} else if (e.keyCode === 37) { // Left
slideshow.cycle('prev');
} else if (e.keyCode === 39) { // Right
slideshow.cycle('next');
}
});
})
</script>
</head>
<body>
<div class="compare-modal" style="display: none;"></div>
<div class="container">
<div class="row">
<div class="col-sm-12 col-md-3">
Expand Down