Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [5.1.0] - 2025-06-05

### Added

- Extend Option with (optional) "container" parameter which can be used to specify the container the overlay should be attached to

## [5.0.4] - 2021-01-17

### Changed
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ The option object can include the following properties:
* One or more space separated classes to be added to the basicLightbox element.
*/
className: '',
/*
* (optional) dom object the lightbox markup will be appended to, default: document.body
*/
container: dom-object
/*
* Function that gets executed before the lightbox will be shown.
* Returning false will prevent the lightbox from showing.
Expand All @@ -238,4 +242,4 @@ $basicLightbox__duration: .4s; // Transition duration
$basicLightbox__timing: ease; // Transition timing

@import 'src/styles/main';
```
```
2 changes: 1 addition & 1 deletion dist/basicLightbox.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,14 @@ const validateOptions = function(opts = {}) {
if (opts.className == null) opts.className = ''
if (opts.onShow == null) opts.onShow = () => {}
if (opts.onClose == null) opts.onClose = () => {}
if (opts.container == null) opts.container = document.body;


if (typeof opts.closable !== 'boolean') throw new Error('Property `closable` must be a boolean')
if (typeof opts.className !== 'string') throw new Error('Property `className` must be a string')
if (typeof opts.onShow !== 'function') throw new Error('Property `onShow` must be a function')
if (typeof opts.onClose !== 'function') throw new Error('Property `onClose` must be a function')
if (typeof opts.container !== 'object') throw new Error('Property `conteiner` must be a object')

return opts

Expand Down Expand Up @@ -137,11 +140,12 @@ const render = function(content, opts) {
* Shows a lightbox by appending an element to the DOM.
* @param {Node} elem
* @param {Function} next - The callback that gets executed when the lightbox starts to show up.
* @param {?Object} opts
* @returns {Boolean} success
*/
const show = function(elem, next) {
const show = function(elem, next, opts) {

document.body.appendChild(elem)
opts.container.appendChild(elem)

// Wait a while to ensure that the class change triggers the animation
setTimeout(() => {
Expand Down Expand Up @@ -223,7 +227,7 @@ export const create = function(content, opts) {
// Continue with the callback when available
if (typeof next === 'function') return next(instance)

})
}, opts)

}

Expand Down