Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

fix: resets interval timer on control click #56

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@

// (6:1) {#if controls}
function create_if_block_1(ctx) {
var button0, t, button1, current, dispose;
var button0, resetInterval_action, t, button1, resetInterval_action_1, current, dispose;

const left_control_slot_1 = ctx.$$slots["left-control"];
const left_control_slot = create_slot(left_control_slot_1, ctx, get_left_control_slot_context);
Expand Down Expand Up @@ -397,13 +397,15 @@
left_control_slot.m(button0, null);
}

resetInterval_action = ctx.resetInterval.call(null, button0, ctx.autoplay) || {};
insert(target, t, anchor);
insert(target, button1, anchor);

if (right_control_slot) {
right_control_slot.m(button1, null);
}

resetInterval_action_1 = ctx.resetInterval.call(null, button1, ctx.autoplay) || {};
current = true;
},

Expand All @@ -412,9 +414,17 @@
left_control_slot.p(get_slot_changes(left_control_slot_1, ctx, changed, get_left_control_slot_changes), get_slot_context(left_control_slot_1, ctx, get_left_control_slot_context));
}

if (typeof resetInterval_action.update === 'function' && changed.autoplay) {
resetInterval_action.update.call(null, ctx.autoplay);
}

if (right_control_slot && right_control_slot.p && changed.$$scope) {
right_control_slot.p(get_slot_changes(right_control_slot_1, ctx, changed, get_right_control_slot_changes), get_slot_context(right_control_slot_1, ctx, get_right_control_slot_context));
}

if (typeof resetInterval_action_1.update === 'function' && changed.autoplay) {
resetInterval_action_1.update.call(null, ctx.autoplay);
}
},

i(local) {
Expand All @@ -436,13 +446,15 @@
}

if (left_control_slot) left_control_slot.d(detaching);
if (resetInterval_action && typeof resetInterval_action.destroy === 'function') resetInterval_action.destroy();

if (detaching) {
detach(t);
detach(button1);
}

if (right_control_slot) right_control_slot.d(detaching);
if (resetInterval_action_1 && typeof resetInterval_action_1.destroy === 'function') resetInterval_action_1.destroy();
run_all(dispose);
}
};
Expand Down Expand Up @@ -731,7 +743,24 @@
currentSlide: controller.currentSlide,
slideCount: controller.innerElements.length
} );
}
}

function resetInterval(node, condition) {
function handleReset(event) {
pause();
resume();
}

if(condition) {
node.addEventListener('click', handleReset);
}

return {
destroy() {
node.removeEventListener('click', handleReset);
}
}
}

let { $$slots = {}, $$scope } = $$props;

Expand Down Expand Up @@ -789,6 +818,7 @@
go,
pause,
resume,
resetInterval,
currentPerPage,
totalDots,
div0_binding,
Expand Down
34 changes: 32 additions & 2 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ const get_left_control_slot_context = ({}) => ({});

// (6:1) {#if controls}
function create_if_block_1(ctx) {
var button0, t, button1, current, dispose;
var button0, resetInterval_action, t, button1, resetInterval_action_1, current, dispose;

const left_control_slot_1 = ctx.$$slots["left-control"];
const left_control_slot = create_slot(left_control_slot_1, ctx, get_left_control_slot_context);
Expand Down Expand Up @@ -391,13 +391,15 @@ function create_if_block_1(ctx) {
left_control_slot.m(button0, null);
}

resetInterval_action = ctx.resetInterval.call(null, button0, ctx.autoplay) || {};
insert(target, t, anchor);
insert(target, button1, anchor);

if (right_control_slot) {
right_control_slot.m(button1, null);
}

resetInterval_action_1 = ctx.resetInterval.call(null, button1, ctx.autoplay) || {};
current = true;
},

Expand All @@ -406,9 +408,17 @@ function create_if_block_1(ctx) {
left_control_slot.p(get_slot_changes(left_control_slot_1, ctx, changed, get_left_control_slot_changes), get_slot_context(left_control_slot_1, ctx, get_left_control_slot_context));
}

if (typeof resetInterval_action.update === 'function' && changed.autoplay) {
resetInterval_action.update.call(null, ctx.autoplay);
}

if (right_control_slot && right_control_slot.p && changed.$$scope) {
right_control_slot.p(get_slot_changes(right_control_slot_1, ctx, changed, get_right_control_slot_changes), get_slot_context(right_control_slot_1, ctx, get_right_control_slot_context));
}

if (typeof resetInterval_action_1.update === 'function' && changed.autoplay) {
resetInterval_action_1.update.call(null, ctx.autoplay);
}
},

i(local) {
Expand All @@ -430,13 +440,15 @@ function create_if_block_1(ctx) {
}

if (left_control_slot) left_control_slot.d(detaching);
if (resetInterval_action && typeof resetInterval_action.destroy === 'function') resetInterval_action.destroy();

if (detaching) {
detach(t);
detach(button1);
}

if (right_control_slot) right_control_slot.d(detaching);
if (resetInterval_action_1 && typeof resetInterval_action_1.destroy === 'function') resetInterval_action_1.destroy();
run_all(dispose);
}
};
Expand Down Expand Up @@ -725,7 +737,24 @@ function instance($$self, $$props, $$invalidate) {
currentSlide: controller.currentSlide,
slideCount: controller.innerElements.length
} );
}
}

function resetInterval(node, condition) {
function handleReset(event) {
pause();
resume();
}

if(condition) {
node.addEventListener('click', handleReset);
}

return {
destroy() {
node.removeEventListener('click', handleReset);
}
}
}

let { $$slots = {}, $$scope } = $$props;

Expand Down Expand Up @@ -783,6 +812,7 @@ function instance($$self, $$props, $$invalidate) {
go,
pause,
resume,
resetInterval,
currentPerPage,
totalDots,
div0_binding,
Expand Down
21 changes: 19 additions & 2 deletions src/Carousel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<slot></slot>
</div>
{#if controls}
<button class="left" on:click={left} aria-label="left">
<button class="left" on:click={left} use:resetInterval={autoplay} aria-label="left">
<slot name="left-control"></slot>
</button>
<button class="right" on:click={right} aria-label="right">
<button class="right" on:click={right} use:resetInterval={autoplay} aria-label="right">
<slot name="right-control"></slot>
</button>
{/if}
Expand Down Expand Up @@ -165,5 +165,22 @@
currentSlide: controller.currentSlide,
slideCount: controller.innerElements.length
} )
}

function resetInterval(node, condition) {
function handleReset(event) {
pause();
resume();
}

if(condition) {
node.addEventListener('click', handleReset);
}

return {
destroy() {
node.removeEventListener('click', handleReset);
}
}
}
</script>