Skip to content

Commit

Permalink
Fixes #13
Browse files Browse the repository at this point in the history
  • Loading branch information
stephband committed May 19, 2022
1 parent 98043f0 commit 505c404
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 33 deletions.
6 changes: 3 additions & 3 deletions build/slide-show-figure.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/slide-show-ol.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/slide-show-shadow.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions build/slide-show-ul.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/slide-show.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions build/slide-show.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion modules/active.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function getAligned(scroller, elements) {

while ((slide = elements[--n])) {
const slideRect = rect(slide);

if (!slideRect) { continue; }

// Todo: do we need webkit property here?
Expand All @@ -94,6 +95,7 @@ function getAligned(scroller, elements) {

// If position has crossed the detection going left, we're in the money
if (x <= detection) {
console.log(x, detection, slide);
break;
}
}
Expand All @@ -118,7 +120,7 @@ export function updateActive(data) {
const { scroller, children, elements } = data;
const current = getAligned(scroller, elements);
let active;

console.log('CURRENT', current);
// If current is a loop ghost jump to the actual slide it references
if (!current) { return; }
if (isGhost(current)) {
Expand Down
2 changes: 2 additions & 0 deletions modules/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default {
))
.filter((child) => (data.active !== child && trigger('slide-active', child)))
.map((child) => data.active = child)
.log('ACTIVE')
.broadcast({ memory: true, hot: true });

const clicks = events('click', shadow)
Expand Down Expand Up @@ -173,6 +174,7 @@ export default {
// Update active when scroll comes to rest, but not mid-gesture.
scrollends(scroller)
.filter((e) => (data.connected && !data.gesturing))
// Of course, this causes a scroll, which causes a scrollend...
.each((e) => updateActive(data));

// Enable single finger scroll on mouse devices. Dodgy idea in my
Expand Down
43 changes: 31 additions & 12 deletions modules/test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@

import equals from '../../fn/modules/equals.js';

let promise = Promise.resolve(0);
let n = 0;

function runTest(name, fn, value, values, resolve, reject) {
function runTest(name, fn, expected, value, values, pass, fail) {
try {
fn(resolve, value, ...values);
fn((value) => (
// If value is an Error object
value instanceof Error ?
fail(value) :
// If value is expected
expected === undefined || equals(value, expected) ?
pass(value) :
// Otherwise
fail(new Error('done() value does not equal expected value'))
), value, ...values);
}
catch(e) {
reject(e);
fail(e);
}
}

export default function scheduleTest(time, name, fn, ...values) {
export default function scheduleTest(time, name, fn, expected, ...values) {
return promise = promise
.then((value) => new Promise((resolve, reject) =>
setTimeout(runTest, time * 1000, name, fn, value, values, (value) => {
// Log pass
.then((value) => new Promise((resolve, reject) => {
const pass = (value) => {
console.log('%c✓ Test ' + (++n) + ' %c' + name, 'color: #B6BD00; font-weight: 400;', 'color: #779AAB; font-weight: 400;');
resolve(value);
}, (e) => {
// Log fail
console.log('%c✗ Test ' + (++n) + ' %c' + name, 'color: #ba4029; font-weight: 400;', 'color: #779AAB; font-weight: 400;', e.message);
};

const fail = (e) => {
console.log('%c✗ Test ' + (++n) + ' %c' + name, 'color: #f02f2f; font-weight: 600;', 'color: #779AAB; font-weight: 400;', e.message);
reject();
})
));
};

return time === 'frame' ?
requestAnimationFrame(() => runTest(name, fn, expected, value, values, pass, fail)) :
time === 'tick' ?
Promise.resolve().then(() => runTest(name, fn, expected, value, values, pass, fail)) :
// Assume time is a number in seconds
setTimeout(runTest, time * 1000, name, fn, expected, value, values, pass, fail) ;
}));
}
13 changes: 7 additions & 6 deletions test/2-slide-show.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<a href="/" draggable="false" id="summit"><img src="../docs/images/summit.jpg" draggable="false" /></a>
</slide-show>
<pre>&lt;slide-show loop autoplay controls="navigation pagination fullscreen"&gt; - one child</pre>
<pre>&lt;slide-show loop autoplay controls="navigation pagination fullscreen"&gt; - one child</pre-->

<slide-show class="main-slide-show" loop autoplay controls="navigation pagination fullscreen" active="#mauverin">
<a href="/" draggable="false"><img src="../docs/images/donkeys.jpg" draggable="false" /></a>
Expand All @@ -91,7 +91,7 @@
<a href="/" draggable="false"><img src="../docs/images/summit.jpg" draggable="false" /></a>
</slide-show>

<slide-show class="tab-slide-show">
<!--slide-show class="tab-slide-show">
<a class="tab-button button" href="#1" draggable="false">Explore</a>
<a class="tab-button button active" href="#2" draggable="false">Buy</a>
<a class="tab-button button" href="#3" draggable="false">Free trial</a>
Expand Down Expand Up @@ -156,7 +156,7 @@


// -----

/*
test(0, 'create <slide-show> with no children', (done) => {
const show = document.createElement('slide-show');
done(show);
Expand Down Expand Up @@ -298,13 +298,14 @@
// In Chrome it's all right now. Probably. Sometimes it
// needs one more.
requestAnimationFrame(() => {
window.confirm('Is picture of rocks visible?') && done(show);
// So is the active slide in view? Even roughly speaking?
done(show.active.getBoundingClientRect().left < 100);
})
)
)
);
});

}, true);
*/
</script>
</body>
</html>

0 comments on commit 505c404

Please sign in to comment.