Skip to content

Commit 4ea8e38

Browse files
committed
[TASK] Remove the detail property from custom events
1 parent dba4678 commit 4ea8e38

File tree

7 files changed

+29
-59
lines changed

7 files changed

+29
-59
lines changed

README.md

-8
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,6 @@ The following events are available:
300300
| `close` | Triggered after Parvus has been closed |
301301
| `destroy` | Triggered after Parvus has been destroyed |
302302

303-
Except for the `close` and `destroy` events, you can access the current source element using the `event.detail.source` property.
304-
305-
```js
306-
prvs.on('open', function (event) {
307-
console.log(event.detail.source);
308-
})
309-
```
310-
311303
## Browser Support
312304

313305
Parvus is supported on the latest versions of the following browsers:

dist/js/parvus.esm.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,7 @@ function Parvus(userOptions) {
465465
preload(currentIndex - 1);
466466

467467
// Create and dispatch a new event
468-
fire('open', {
469-
source: el
470-
});
468+
dispatchCustomEvent('open');
471469
};
472470

473471
/**
@@ -742,11 +740,7 @@ function Parvus(userOptions) {
742740
updateCounter();
743741

744742
// Create and dispatch a new event
745-
fire('select', {
746-
detail: {
747-
source: GROUPS[activeGroup].triggerElements[currentIndex]
748-
}
749-
});
743+
dispatchCustomEvent('select');
750744
};
751745

752746
/**
@@ -1313,7 +1307,7 @@ function Parvus(userOptions) {
13131307
LIGHTBOX_TRIGGER_ELS.forEach(remove);
13141308

13151309
// Create and dispatch a new event
1316-
fire('destroy');
1310+
dispatchCustomEvent('destroy');
13171311
};
13181312

13191313
/**
@@ -1347,11 +1341,9 @@ function Parvus(userOptions) {
13471341
* Dispatch a custom event
13481342
*
13491343
* @param {String} type - The type of the event to dispatch
1350-
* @param {Function} event - The event object
13511344
*/
1352-
const fire = (type, event = {}) => {
1345+
const dispatchCustomEvent = type => {
13531346
const CUSTOM_EVENT = new CustomEvent(type, {
1354-
detail: event,
13551347
cancelable: true
13561348
});
13571349
lightbox.dispatchEvent(CUSTOM_EVENT);

dist/js/parvus.esm.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/js/parvus.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,7 @@
471471
preload(currentIndex - 1);
472472

473473
// Create and dispatch a new event
474-
fire('open', {
475-
source: el
476-
});
474+
dispatchCustomEvent('open');
477475
};
478476

479477
/**
@@ -748,11 +746,7 @@
748746
updateCounter();
749747

750748
// Create and dispatch a new event
751-
fire('select', {
752-
detail: {
753-
source: GROUPS[activeGroup].triggerElements[currentIndex]
754-
}
755-
});
749+
dispatchCustomEvent('select');
756750
};
757751

758752
/**
@@ -1319,7 +1313,7 @@
13191313
LIGHTBOX_TRIGGER_ELS.forEach(remove);
13201314

13211315
// Create and dispatch a new event
1322-
fire('destroy');
1316+
dispatchCustomEvent('destroy');
13231317
};
13241318

13251319
/**
@@ -1353,11 +1347,9 @@
13531347
* Dispatch a custom event
13541348
*
13551349
* @param {String} type - The type of the event to dispatch
1356-
* @param {Function} event - The event object
13571350
*/
1358-
const fire = (type, event = {}) => {
1351+
const dispatchCustomEvent = type => {
13591352
const CUSTOM_EVENT = new CustomEvent(type, {
1360-
detail: event,
13611353
cancelable: true
13621354
});
13631355
lightbox.dispatchEvent(CUSTOM_EVENT);

dist/js/parvus.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/parvus.js

+4-12
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,7 @@ export default function Parvus (userOptions) {
445445
preload(currentIndex - 1)
446446

447447
// Create and dispatch a new event
448-
fire('open', {
449-
source: el
450-
})
448+
dispatchCustomEvent('open')
451449
}
452450

453451
/**
@@ -775,11 +773,7 @@ export default function Parvus (userOptions) {
775773
updateCounter()
776774

777775
// Create and dispatch a new event
778-
fire('select', {
779-
detail: {
780-
source: GROUPS[activeGroup].triggerElements[currentIndex]
781-
}
782-
})
776+
dispatchCustomEvent('select')
783777
}
784778

785779
/**
@@ -1375,7 +1369,7 @@ export default function Parvus (userOptions) {
13751369
LIGHTBOX_TRIGGER_ELS.forEach(remove)
13761370

13771371
// Create and dispatch a new event
1378-
fire('destroy')
1372+
dispatchCustomEvent('destroy')
13791373
}
13801374

13811375
/**
@@ -1409,11 +1403,9 @@ export default function Parvus (userOptions) {
14091403
* Dispatch a custom event
14101404
*
14111405
* @param {String} type - The type of the event to dispatch
1412-
* @param {Function} event - The event object
14131406
*/
1414-
const fire = (type, event = {}) => {
1407+
const dispatchCustomEvent = (type) => {
14151408
const CUSTOM_EVENT = new CustomEvent(type, {
1416-
detail: event,
14171409
cancelable: true
14181410
})
14191411

test/test.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
/**
2-
* Import language file
2+
* Import Parvus
33
*
44
*/
55
import Parvus from '../dist/js/parvus.esm.min.js'
6+
7+
/**
8+
* Import language file
9+
*
10+
*/
611
import de from '../src/l10n/de.js'
712

813
/**
@@ -36,25 +41,22 @@ setTimeout(() => {
3641
* Events
3742
*
3843
*/
39-
prvs.on('open', (event) => {
40-
console.log(`
41-
Opened by: ${event.detail.source}
42-
at index: ${prvs.currentIndex()},
43-
selected slide: ${prvs.currentIndex() + 1}
44-
`)
44+
prvs.on('open', () => {
45+
console.log(`Open:
46+
Index: ${prvs.currentIndex()},
47+
Slide: ${prvs.currentIndex() + 1}`)
4548
})
4649

4750
prvs.on('select', () => {
48-
console.log(`
49-
Selected index: ${prvs.currentIndex()},
50-
selected slide: ${prvs.currentIndex() + 1}
51-
`)
51+
console.log(`Select:
52+
Index: ${prvs.currentIndex()},
53+
Slide: ${prvs.currentIndex() + 1}`)
5254
})
5355

5456
prvs.on('close', () => {
55-
console.log('Closed')
57+
console.log('Close')
5658
})
5759

5860
prvs.on('destroy', () => {
59-
console.log('Destroyed')
61+
console.log('Destroy')
6062
})

0 commit comments

Comments
 (0)