@beyonk/svelte-carousel
Advanced tools
Comparing version 2.1.1 to 2.2.0
@@ -83,2 +83,7 @@ (function (global, factory) { | ||
} | ||
function custom_event(type, detail) { | ||
const e = document.createEvent('CustomEvent'); | ||
e.initCustomEvent(type, false, false, detail); | ||
return e; | ||
} | ||
@@ -97,2 +102,16 @@ let current_component; | ||
} | ||
function createEventDispatcher() { | ||
const component = current_component; | ||
return (type, detail) => { | ||
const callbacks = component.$$.callbacks[type]; | ||
if (callbacks) { | ||
// TODO are there situations where events could be dispatched | ||
// in a server (non-DOM) environment? | ||
const event = custom_event(type, detail); | ||
callbacks.slice().forEach(fn => { | ||
fn.call(component, event); | ||
}); | ||
} | ||
}; | ||
} | ||
@@ -538,2 +557,4 @@ const dirty_components = []; | ||
let timer; | ||
const dispatch = createEventDispatcher(); | ||
@@ -544,3 +565,4 @@ onMount(() => { | ||
perPage, | ||
loop | ||
loop, | ||
onChange: handleChange | ||
})); | ||
@@ -568,2 +590,9 @@ | ||
function handleChange (event) { | ||
dispatch('change', { | ||
currentSlide: controller.currentSlide, | ||
slideCount: controller.innerElements.length | ||
} ); | ||
} | ||
let { $$slots = {}, $$scope } = $$props; | ||
@@ -570,0 +599,0 @@ |
@@ -6,3 +6,3 @@ { | ||
"main": "dist/index.js", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"scripts": { | ||
@@ -9,0 +9,0 @@ "build": "rollup -c", |
@@ -20,2 +20,3 @@ <p align="center"> | ||
``` | ||
npm install | ||
npm run dev # http://localhost:12001 | ||
@@ -102,2 +103,10 @@ ``` | ||
// will show 1 slide below 500px width, 2 at 500, 3 at 800. | ||
``` | ||
``` | ||
### Events | ||
The Carousel components emits the following events: | ||
| Name | Data | Description | | ||
|----------|--------------------------------|--------------------------------------------------------------------------------| | ||
| `change` | `{ currentSlide, slideCount }` | `currentSlide`: The current slide index. Can be a positive or negative integer. `slideCount`: The number of slides. | |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No License Found
License(Experimental) License information could not be found
Found 1 instance in 1 package
71311
6
0
1210
111