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

Template improvements #394

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
163 changes: 137 additions & 26 deletions lib/wraith/gallery_template/slideshow_template.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
margin-top: 60px;
}

.prev span:before,
.next span:before {
.prev span::before,
.next span::before {
font-size: 35px;
padding: 10px;
display: block;
Expand All @@ -43,28 +43,38 @@
display: block;
}

.prev span:before {
.prev span::before {
content:"\f0d9";
}
.next span:before {
.next span::before {
content:"\f0da";
}
.list-group-item.checked a:after {
color: #23e343;
}

.list-group-item a span {
word-wrap: break-word;
width: 95%;
display: block;
}
.list-group-item a:after {
.list-group-item a::after {
content:"\f00c";
font-family: "FontAwesome";
color: #eae6e6;
position: absolute;
right: 10px;
top: 10px;
}

.list-group-item.current a::after {
color: #E1AB2F;
font-weight: bold;
content: "---";
}
.list-group-item.checked a::after {
color: #23e343;
content:"\f00c";
font-weight: normal;
}

.checked a {
color: #000;
}
Expand All @@ -79,7 +89,7 @@
margin-left: 20px;
}

.compare:before {
.compare::before {
font-family: "FontAwesome";
content:"\f0c5";
font-size: 30px;
Expand All @@ -105,23 +115,116 @@
margin-right: 20px;
max-width: 30%;
}

.compare-modal ~ .prev {
z-index: 9999;
position: fixed;
top: 0;
left: 0;
width: 4%;
padding: 7px;
}

.compare-modal ~ .next {
z-index: 9999;
position: fixed;
top: 0;
right: 0;
width: 4%;
padding: 7px;
}

.compare-modal h1 {
color: white;
}

</style>
<script type="text/javascript">
$(function() {

var fullscreen = false;

function fullScreenSlide(slide) {
if (slide) {
fullscreen = true;
var title = slide.find('h4').first().text(),
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');
$('.slideshow-container').prepend('<div class="compare-modal"><div class="compare-container"><h1>' + title + '</h1><img src="'+newImage+'"/><img src="'+oldImage+'"/><img src="'+diffImage+'"/></div></div>');
$('.compare-modal').unbind().on('click', function(){
$(this).remove();
fullscreen = false;
})
}
}

function updateProgressIndicator(before, after, opts) {
// if we're the first entry in the batch
before = $(before);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to create new variables instead reusing existing ones.

var $before = $(before);

after = $(after);

// NEXT
$('.current').removeClass('current');
var path = after.find('.path').attr('name');
var item = getMenuItemCorrespondingTo(path);
item.addClass('current');

// CURRENT
var similarElements = getElementsOfSameClass(before);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can achieve similar functionality with:

var elementClasses = before.attr('class');
var similarElements = before.siblings(`[class="${elementClasses}"]`);

before.addClass('processed');

var allProcessed = true;
similarElements.each(function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to jQuery documentation:

.hasClass( className )
Description: Determine whether any of the matched elements are assigned the given class.

...you can just do:

if (!similarElements.hasClass('processed')) {
  (...)
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or as a one-liner:

var allProcessed = !similarElements.hasClass('processed');

if ( !$(this).hasClass('processed') ) {
allProcessed = false;
}
});

if (allProcessed) {
var path = before.find('.path').attr('name');
var item = getMenuItemCorrespondingTo(path);

item.addClass('checked');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually add is- or has- prefix to boolean class names:
is-checked
It makes it a tiny little bit cleaner IMO.

}
}

function getElementsOfSameClass(element) {
var classNamesOfElement = element.attr('class').split(/\s+/),
similarElements = element.parent().find('.' + classNamesOfElement.join('.'));
return similarElements;
}

function getMenuItemCorrespondingTo(path) {
var item = false;
$.each($('.list-group .list-group-item a'), function() {
if ($(this).attr('href').substring(1) == path) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use === strict comparison.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole function can also be a one-liner:

return $(`.list-group .list-group-item a[href="/${path}"]`);

item = $(this).parent();
}
})
return item;
}

// http://jquery.malsup.com/cycle/options.html
$('.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');
$.each($('.list-group .list-group-item a'), function() {
if ($(this).attr('href').substring(1) == path) {
$(this).parent().addClass('checked');
$(this).parent().addClass('current');
}
})
speed: 300,
before: updateProgressIndicator,
after: function () {
if (fullscreen) {
$('.compare-modal').remove();
var currentSlide = false;
$('.slide').each(function () {
if ($(this).css('display') === 'block') {
currentSlide = $(this);
}
});

fullScreenSlide(currentSlide);
}
},
timeout: 0
});
Expand All @@ -139,15 +242,23 @@
})

$('.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();
})
var slide = $(this).closest(".slide")
fullScreenSlide(slide);
})

window.addEventListener('keydown', function(e){
var leftArrowKeyCode = 37;
var rightArrowKeyCode = 39;

e = e || window.event;

if (e.keyCode === leftArrowKeyCode) {
$('.slideshow').cycle('prev');
}
else if (e.keyCode === rightArrowKeyCode) {
$('.slideshow').cycle('next');
}
});
})
</script>
</head>
Expand Down