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 1 commit
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
85 changes: 66 additions & 19 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 Down Expand Up @@ -149,22 +159,59 @@
}
}

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: 'cover',
prev: '.prev',
next: '.next',
speed: 300,
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');
}
})
},
before: updateProgressIndicator,
after: function () {
if (fullscreen) {
$('.compare-modal').remove();
Expand Down