7. Custom types
Matthieu Stroh edited this page Sep 11, 2018
·
8 revisions
How to add a custom lightbox type
import Lightbox from '@novembrecom/nlightbox';
class LightboxItemTest { }
LightboxItemTest.TYPE_NAME = 'test';
Argument | Description |
---|---|
lightbox | Instance of the lightbox |
key | Unique key assigned to the element |
dataset | All the properties specified in the data-lightbox attribute go here |
constructor(lightbox, key, dataset) {
this.lightbox = lightbox;
this.key = key;
this.loaded = false;
this.loading = false;
this.failed = false;
this.data = null;
}
The load function either returns an HTML Element object, or a Promise that resolves an HTML Element if you want to perform asynchronous tasks before.
class LightboxItemTest {
constructor(lightbox, key, dataset) {
this.lightbox = lightbox;
this.key = key;
this.loaded = false;
this.loading = false;
this.failed = false;
this.data = null;
// ...
}
/**
* This function should return the content of your element
* @return {Element}
*/
load() {
// ...
}
}
const lightbox = new Lightbox({ uid: 'lightbox-1' });
// you can register multiple classes
lightbox.init([ LightboxItemTest ]);
e. Remember we specified a type name which is used here in the
data-lightbox
attribute
<button data-lightbox='{ "group": "lightbox-1", "type": "test", ... }'></button>