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

Fix the carousel option #47

Merged
merged 5 commits into from
Sep 16, 2015
Merged

Fix the carousel option #47

merged 5 commits into from
Sep 16, 2015

Conversation

jacobmllr95
Copy link
Contributor

  • Detect the correct direction in the goTo function to set the
    correct classes.
    • To detect a forwards direction we need to check if the index is
      higher than the currentItemIndex or if the index is 0 an the
      currentItemIndex is the index of the last item (go from the last item
      to the first).
    • To detect a backwards direction we need to check if the index
      is lower than the currentItemIndex or if the index is the index
      of the last item and the currentItemIndex is 0 (go from the first
      item to the last).
  • Fix the initial button state when the carousel option is disabled.

This changes make sure that the className doesn’t contain any trailing
spaces.
* Detect the correct direction in the `goTo` function  to set the
correct classes.
    * To detect a forwards direction we need to check if the `index` is
higher than the `currentItemIndex` **or** if the `index` is `0` an the
`currentItemIndex` is the index of the last item (go from the last item
to the first).
    * To detect a backwards direction we need to check if the `index`
is lower than the `currentItemIndex` **or** if the `index` is the index
of the last item and the `currentItemIndex` is `0` (go from the first
item to the last).
* Fix the initial button state when the `carousel` option is disabled
@jacobmllr95 jacobmllr95 mentioned this pull request Sep 15, 2015
@peduarte
Copy link
Owner

Thanks @jackmu95 will take a proper look at this later on! 👏

@jacobmllr95
Copy link
Contributor Author

No problem :)

I forgot to create a separate branch for my fist pull request (#46) so this is also included in this PR. I hope it's OK... But while testing anything was fine 👍

@peduarte
Copy link
Owner

So this PR includes the changes you made in #46? Can I close #46 then?

@jacobmllr95
Copy link
Contributor Author

Yes it does. And you can close #46.

@peduarte
Copy link
Owner

This will need some tests written to make sure it's all working properly.

For example (in pseudo code)

if click on [next] 
when current item is [last]
[nextItem] to have class [Wallop-item--showNext]
...test other classes...

Similar tests for backwards direction

If you are happy writing the tests, I can then double check everything is working and merge this PR.

Otherwise, I will write tests later

@jacobmllr95
Copy link
Contributor Author

I will write the tests and update the PR 👍

@jacobmllr95
Copy link
Contributor Author

I added a test for the button state on initialization when the carousel option is disabled and updated the test for the carousel.

To test the button state I made some changes to the createSlider function. I does now add the previous and next button to the wallop slider.

this.currentItemIndex = 0;
addClass(this.allItemsArray[this.currentItemIndex], this.options.currentItemClass);
}

// Update the button state on initialization when the `carousel` option isn't enabled
if (!this.carousel) {
this.updateButtonStates();
Copy link
Owner

Choose a reason for hiding this comment

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

What's the use case of doing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the carousel option is disabled, the previous button gets disabled when you are on the first item and the next button gets disabled when you are on the last item. When the wallop slider is initialized and the start item is the first or the last one, the depending button isn't disabled (see http://codepen.io/anon/pen/zvrWpp).

this.currentItemIndex = 0;
addClass(this.allItemsArray[this.currentItemIndex], this.options.currentItemClass);
}

// Update button states to make sure the correct state is set on initialization
this.updateButtonStates();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed to set the correct button state on initialization when the carousel option is disabled. This was not the case before (see http://codepen.io/anon/pen/zvrWpp). To get the correct state for the previous button, you need to click next and the previous.

Copy link
Owner

Choose a reason for hiding this comment

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

Ahh yes, well spotted! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks ;)

peduarte pushed a commit that referenced this pull request Sep 16, 2015
@peduarte peduarte merged commit 9be5c44 into peduarte:master Sep 16, 2015
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