Skip to content

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


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.

3 participants