Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling update() on a not-initialized lazyloaded viewer causes to add a duplicate 360 icon #138

Open
Xriuk opened this issue Oct 21, 2022 · 0 comments

Comments

@Xriuk
Copy link

Xriuk commented Oct 21, 2022

<div
    class="cloudimage-360"
    id="tw-360-1"
    data-folder="https://localhost:44396/files/"
    data-image-list-x="[...]"
    data-lazyload
    data-lazyload-selector="lazyload"></div>

If a viewer with data-lazyload (or lazyload) set is not yet loaded and it's updated instead by calling window.CI360.update("tw-360-1"), this causes to add a 360 icon to it, which then gets added again after it loads causing a duplicate icon, and the second one does not get deleted.

I believe this is caused by

this.init(container, true);

which in turn creates the icon here
if (update) {
removeChildFromParent(this.innerBox, this.iconsContainer);
removeChildFromParent(this.innerBox, this.boxShadowEl);
removeChildFromParent(this.innerBox, this.view360Icon);
this.remove360ViewCircleIcon();
this.iconsContainer = createIconsContainer(this.innerBox);
if (!this.hide360Logo && !this.lazyload && this.logoSrc) {
this.add360ViewIcon();
setView360Icon(this.view360Icon, this.logoSrc);
}

This could be easily solved by checking isReady() before updating:

isReady() {
const loadedXImages = this.imagesX.filter(image => image);
const loadedYImages = this.imagesY.filter(image => image);
const totalAmount = this.amountX + this.amountY;
return loadedXImages.length + loadedYImages.length === totalAmount;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant