Skip to content

Commit

Permalink
Merge pull request #16 from oddbird/toggle-view
Browse files Browse the repository at this point in the history
Fix toggleView, add button
  • Loading branch information
mirisuzanne authored Jan 3, 2024
2 parents b882ea3 + 74e1d23 commit b87385a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ <h2><code>&lt;button slide-event&gt;previous&lt;button&gt;</code></h2>
<button slide-event>previous</button>
<button slide-event>next</button>
<button slide-event="start">restart</button>
<button slide-event="toggleView">toggle view</button>
</div>
</div>
<div>
Expand Down
11 changes: 6 additions & 5 deletions slide-deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,15 @@ class slideDeck extends HTMLElement {

// event handlers
toggleView = (to) => {
if (!to) {
let next = to;
if (!next) {
const current = this.getAttribute('slide-view');
const l = slideDeck.slideViews - 1; // adjust for 0-index
const i = slideDeck.slideViews.indexOf(current);
const next = slideDeck.slideViews[(i + 1) % l];
const l = slideDeck.slideViews.length;
const i = slideDeck.slideViews.indexOf(current) || 0;
next = slideDeck.slideViews[(i + 1) % l];
}

this.setAttribute('slide-view', to || next || 'grid');
this.setAttribute('slide-view', next || 'grid');
}

startEvent = () => {
Expand Down

0 comments on commit b87385a

Please sign in to comment.