Skip to content

Commit

Permalink
[TASK] Remove the loadEmpty option and create the lightbox when add…
Browse files Browse the repository at this point in the history
…ing an item
  • Loading branch information
deoostfrees committed Jul 10, 2024
1 parent e703293 commit 98e41b5
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 46 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,6 @@ The following options are available:

```js
{
// Load the lightbox empty if no elements are available
// (e.g. when elements are loaded via Ajax)
loadEmpty: false,

// Selector for elements that trigger Parvus
selector: '.lightbox',

Expand Down
14 changes: 2 additions & 12 deletions dist/js/parvus.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ function Parvus(userOptions) {
const mergeOptions = userOptions => {
// Default options
const DEFAULT_OPTIONS = {
loadEmpty: false,
selector: '.lightbox',
gallerySelector: null,
captions: true,
Expand Down Expand Up @@ -189,8 +188,9 @@ function Parvus(userOptions) {
* @param {HTMLElement} el - The element to be added
*/
const add = el => {
// Check if the lightbox already exists
if (!lightbox) {
return;
createLightbox();
}
if (!(el.tagName === 'A' && el.hasAttribute('href') || el.tagName === 'BUTTON' && el.hasAttribute('data-target'))) {
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.');
Expand Down Expand Up @@ -1395,17 +1395,7 @@ function Parvus(userOptions) {
const init = () => {
// Merge user options into defaults
config = mergeOptions(userOptions);

// Check if the lightbox should be loaded empty or if there are elements for the lightbox.
if (!config.loadEmpty && !document.querySelectorAll(config.selector).length) {
return;
}
reducedMotionCheck();

// Check if the lightbox already exists
if (!lightbox) {
createLightbox();
}
if (config.gallerySelector !== null) {
// Get a list of all `gallerySelector` elements within the document
const GALLERY_ELS = document.querySelectorAll(config.gallerySelector);
Expand Down
2 changes: 1 addition & 1 deletion dist/js/parvus.esm.min.js

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions dist/js/parvus.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
const mergeOptions = userOptions => {
// Default options
const DEFAULT_OPTIONS = {
loadEmpty: false,
selector: '.lightbox',
gallerySelector: null,
captions: true,
Expand Down Expand Up @@ -195,8 +194,9 @@
* @param {HTMLElement} el - The element to be added
*/
const add = el => {
// Check if the lightbox already exists
if (!lightbox) {
return;
createLightbox();
}
if (!(el.tagName === 'A' && el.hasAttribute('href') || el.tagName === 'BUTTON' && el.hasAttribute('data-target'))) {
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.');
Expand Down Expand Up @@ -1401,17 +1401,7 @@
const init = () => {
// Merge user options into defaults
config = mergeOptions(userOptions);

// Check if the lightbox should be loaded empty or if there are elements for the lightbox.
if (!config.loadEmpty && !document.querySelectorAll(config.selector).length) {
return;
}
reducedMotionCheck();

// Check if the lightbox already exists
if (!lightbox) {
createLightbox();
}
if (config.gallerySelector !== null) {
// Get a list of all `gallerySelector` elements within the document
const GALLERY_ELS = document.querySelectorAll(config.gallerySelector);
Expand Down
2 changes: 1 addition & 1 deletion dist/js/parvus.min.js

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions src/js/parvus.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export default function Parvus (userOptions) {
const mergeOptions = (userOptions) => {
// Default options
const DEFAULT_OPTIONS = {
loadEmpty: false,
selector: '.lightbox',
gallerySelector: null,
captions: true,
Expand Down Expand Up @@ -131,8 +130,9 @@ export default function Parvus (userOptions) {
* @param {HTMLElement} el - The element to be added
*/
const add = (el) => {
// Check if the lightbox already exists
if (!lightbox) {
return
createLightbox()
}

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

// Check if the lightbox should be loaded empty or if there are elements for the lightbox.
if (!config.loadEmpty && !document.querySelectorAll(config.selector).length) {
return
}

reducedMotionCheck()

// Check if the lightbox already exists
if (!lightbox) {
createLightbox()
}

if (config.gallerySelector !== null) {
// Get a list of all `gallerySelector` elements within the document
const GALLERY_ELS = document.querySelectorAll(config.gallerySelector)
Expand Down
8 changes: 4 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@ setTimeout(() => {
* Events
*
*/
prvs.on('open', function (event) {
prvs.on('open', (event) => {
console.log(`
Opened by: ${event.detail.source}
at index: ${prvs.currentIndex()},
selected slide: ${prvs.currentIndex() + 1}
`)
})

prvs.on('select', function () {
prvs.on('select', () => {
console.log(`
Selected index: ${prvs.currentIndex()},
selected slide: ${prvs.currentIndex() + 1}
`)
})

prvs.on('close', function () {
prvs.on('close', () => {
console.log('Closed')
})

prvs.on('destroy', function () {
prvs.on('destroy', () => {
console.log('Destroyed')
})

0 comments on commit 98e41b5

Please sign in to comment.