Share correct image in native share (fix #254)
parent
ddf14abb17
commit
cdfcec1a3f
|
@ -553,8 +553,8 @@ export default class Viewer extends Mixins(GlobalMixin) {
|
||||||
return this.thumbElem(photo) || thumbEl;
|
return this.thumbElem(photo) || thumbEl;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Scroll to keep the thumbnail in view
|
|
||||||
this.photoswipe.on("slideActivate", (e) => {
|
this.photoswipe.on("slideActivate", (e) => {
|
||||||
|
// Scroll to keep the thumbnail in view
|
||||||
const thumb = this.thumbElem(e.slide.data?.photo);
|
const thumb = this.thumbElem(e.slide.data?.photo);
|
||||||
if (thumb && this.fullyOpened) {
|
if (thumb && this.fullyOpened) {
|
||||||
const rect = thumb.getBoundingClientRect();
|
const rect = thumb.getBoundingClientRect();
|
||||||
|
@ -564,6 +564,12 @@ export default class Viewer extends Mixins(GlobalMixin) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove active class from others and add to this one
|
||||||
|
document
|
||||||
|
.querySelectorAll(".pswp__item")
|
||||||
|
.forEach((el) => el.classList.remove("active"));
|
||||||
|
e.slide.holderElement?.classList.add("active");
|
||||||
});
|
});
|
||||||
|
|
||||||
this.photoswipe.init();
|
this.photoswipe.init();
|
||||||
|
@ -703,8 +709,10 @@ export default class Viewer extends Mixins(GlobalMixin) {
|
||||||
// Check navigator support
|
// Check navigator support
|
||||||
if (!this.canShare) throw new Error("Share not supported");
|
if (!this.canShare) throw new Error("Share not supported");
|
||||||
|
|
||||||
// Get image data from "img.pswp__img"
|
// Get image data from active slide
|
||||||
const img = document.querySelector("img.pswp__img") as HTMLImageElement;
|
const img = document.querySelector(
|
||||||
|
".pswp__item.active img.pswp__img"
|
||||||
|
) as HTMLImageElement;
|
||||||
if (!img?.src) return;
|
if (!img?.src) return;
|
||||||
|
|
||||||
// Shre image data using navigator api
|
// Shre image data using navigator api
|
||||||
|
|
Loading…
Reference in New Issue