Skip to content

Commit 98e41b5

Browse files
committed
[TASK] Remove the loadEmpty option and create the lightbox when adding an item
1 parent e703293 commit 98e41b5

File tree

7 files changed

+12
-46
lines changed

7 files changed

+12
-46
lines changed

README.md

-4
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,6 @@ The following options are available:
209209

210210
```js
211211
{
212-
// Load the lightbox empty if no elements are available
213-
// (e.g. when elements are loaded via Ajax)
214-
loadEmpty: false,
215-
216212
// Selector for elements that trigger Parvus
217213
selector: '.lightbox',
218214

dist/js/parvus.esm.js

+2-12
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ function Parvus(userOptions) {
117117
const mergeOptions = userOptions => {
118118
// Default options
119119
const DEFAULT_OPTIONS = {
120-
loadEmpty: false,
121120
selector: '.lightbox',
122121
gallerySelector: null,
123122
captions: true,
@@ -189,8 +188,9 @@ function Parvus(userOptions) {
189188
* @param {HTMLElement} el - The element to be added
190189
*/
191190
const add = el => {
191+
// Check if the lightbox already exists
192192
if (!lightbox) {
193-
return;
193+
createLightbox();
194194
}
195195
if (!(el.tagName === 'A' && el.hasAttribute('href') || el.tagName === 'BUTTON' && el.hasAttribute('data-target'))) {
196196
throw new Error('Use a link with the \'href\' attribute or a button with the \'data-target\' attribute. Both attributes must contain a path to the image file.');
@@ -1395,17 +1395,7 @@ function Parvus(userOptions) {
13951395
const init = () => {
13961396
// Merge user options into defaults
13971397
config = mergeOptions(userOptions);
1398-
1399-
// Check if the lightbox should be loaded empty or if there are elements for the lightbox.
1400-
if (!config.loadEmpty && !document.querySelectorAll(config.selector).length) {
1401-
return;
1402-
}
14031398
reducedMotionCheck();
1404-
1405-
// Check if the lightbox already exists
1406-
if (!lightbox) {
1407-
createLightbox();
1408-
}
14091399
if (config.gallerySelector !== null) {
14101400
// Get a list of all `gallerySelector` elements within the document
14111401
const GALLERY_ELS = document.querySelectorAll(config.gallerySelector);

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

+2-12
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@
123123
const mergeOptions = userOptions => {
124124
// Default options
125125
const DEFAULT_OPTIONS = {
126-
loadEmpty: false,
127126
selector: '.lightbox',
128127
gallerySelector: null,
129128
captions: true,
@@ -195,8 +194,9 @@
195194
* @param {HTMLElement} el - The element to be added
196195
*/
197196
const add = el => {
197+
// Check if the lightbox already exists
198198
if (!lightbox) {
199-
return;
199+
createLightbox();
200200
}
201201
if (!(el.tagName === 'A' && el.hasAttribute('href') || el.tagName === 'BUTTON' && el.hasAttribute('data-target'))) {
202202
throw new Error('Use a link with the \'href\' attribute or a button with the \'data-target\' attribute. Both attributes must contain a path to the image file.');
@@ -1401,17 +1401,7 @@
14011401
const init = () => {
14021402
// Merge user options into defaults
14031403
config = mergeOptions(userOptions);
1404-
1405-
// Check if the lightbox should be loaded empty or if there are elements for the lightbox.
1406-
if (!config.loadEmpty && !document.querySelectorAll(config.selector).length) {
1407-
return;
1408-
}
14091404
reducedMotionCheck();
1410-
1411-
// Check if the lightbox already exists
1412-
if (!lightbox) {
1413-
createLightbox();
1414-
}
14151405
if (config.gallerySelector !== null) {
14161406
// Get a list of all `gallerySelector` elements within the document
14171407
const GALLERY_ELS = document.querySelectorAll(config.gallerySelector);

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

+2-12
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ export default function Parvus (userOptions) {
5353
const mergeOptions = (userOptions) => {
5454
// Default options
5555
const DEFAULT_OPTIONS = {
56-
loadEmpty: false,
5756
selector: '.lightbox',
5857
gallerySelector: null,
5958
captions: true,
@@ -131,8 +130,9 @@ export default function Parvus (userOptions) {
131130
* @param {HTMLElement} el - The element to be added
132131
*/
133132
const add = (el) => {
133+
// Check if the lightbox already exists
134134
if (!lightbox) {
135-
return
135+
createLightbox()
136136
}
137137

138138
if (!((el.tagName === 'A' && el.hasAttribute('href')) || (el.tagName === 'BUTTON' && el.hasAttribute('data-target')))) {
@@ -1459,18 +1459,8 @@ export default function Parvus (userOptions) {
14591459
// Merge user options into defaults
14601460
config = mergeOptions(userOptions)
14611461

1462-
// Check if the lightbox should be loaded empty or if there are elements for the lightbox.
1463-
if (!config.loadEmpty && !document.querySelectorAll(config.selector).length) {
1464-
return
1465-
}
1466-
14671462
reducedMotionCheck()
14681463

1469-
// Check if the lightbox already exists
1470-
if (!lightbox) {
1471-
createLightbox()
1472-
}
1473-
14741464
if (config.gallerySelector !== null) {
14751465
// Get a list of all `gallerySelector` elements within the document
14761466
const GALLERY_ELS = document.querySelectorAll(config.gallerySelector)

test/test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,25 +36,25 @@ setTimeout(() => {
3636
* Events
3737
*
3838
*/
39-
prvs.on('open', function (event) {
39+
prvs.on('open', (event) => {
4040
console.log(`
4141
Opened by: ${event.detail.source}
4242
at index: ${prvs.currentIndex()},
4343
selected slide: ${prvs.currentIndex() + 1}
4444
`)
4545
})
4646

47-
prvs.on('select', function () {
47+
prvs.on('select', () => {
4848
console.log(`
4949
Selected index: ${prvs.currentIndex()},
5050
selected slide: ${prvs.currentIndex() + 1}
5151
`)
5252
})
5353

54-
prvs.on('close', function () {
54+
prvs.on('close', () => {
5555
console.log('Closed')
5656
})
5757

58-
prvs.on('destroy', function () {
58+
prvs.on('destroy', () => {
5959
console.log('Destroyed')
6060
})

0 commit comments

Comments
 (0)