custom hash url
Closed this issue · 2 comments
Hi Sachin, great plugin!
How can I go about adding a custom hash to the current slide? I need to add a custom url which corresponds to the source url of the current image in the slide show.
I've tried adding a custom data attribute ( called data-source ) to the source where lightgallery grabs the source ( data-src ) but it look like lightgallery only copies the src and not the actual element so I can't grab the data-attribute to use with my event listener as such:
<div
class="portfolio-item"
data-src="../url/to/image/that/lightgallery/use"
data-sub-html="text which lightgallery uses>"
data-source="../url/to/original/post/where/the/image/are/from">
var lg = document.getElementById( 'portfolio' );
lightGallery( lg, {
download: false
} );
lg.addEventListener( 'onAfterSlide', function( event ){
var currentSlide = document.querySelector('.lg-current');
console.log( currentSlide );
}, false);
Any help or suggestions would be greatly appreciated,
Sograra
Hey @sograra ,
Sorry for the delayed response.
The plugin instances are stored in lgData variable.
// Access data
pluginData = window.lgData[lg.getAttribute('lg-uid')];
// get data-source
lg.addEventListener( 'onAfterSlide', function( event ){
const source = pluginData.items[event.detail.index].getAttribute('data-source');
}, false);
If you are just looking for custom-hash for each slide, it is already done in v2 - https://github.com/sachinchoolur/lightGallery/blob/v2/src/plugins/hash/lg-hash.ts
V2 will be released once the documentation work is completed
This issue has been automatically marked as stale because it has not had recent activity. If the issue is still valid for version 2.x, please re-open. Apologize for not responding on time. Thank you for your contributions.