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

Template improvements #394

wants to merge 4 commits into from

Conversation

ChrisBAshton
Copy link
Contributor

Started work on improving the slideshow template, but ran out of time before properly addressing the progress indicator work. Ought to add keyboard controls too, for easy full-screen navigation.

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}"]`);

@@ -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);

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');

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}"]`);

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.

vfonic and others added 2 commits November 16, 2016 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants