diff --git a/ignite-html-lazyload.js b/ignite-html-lazyload.js index 7998420..ccb680c 100644 --- a/ignite-html-lazyload.js +++ b/ignite-html-lazyload.js @@ -8,7 +8,7 @@ import { IgniteTemplate } from "../ignite-html/ignite-template.js"; */ class IgniteLazyLoad { static watch(element, callback) { - //Setup the watching counter if we haven't yet. + //Setup the watching list if we haven't yet. if (!IgniteLazyLoad.watching) { IgniteLazyLoad.watching = []; } @@ -68,6 +68,19 @@ class IgniteLazyLoad { //Save the original source. this._lazy_src = this._attributes["src"]; + //Override the attribute changed function, if someone tries to set src and our lazy_src is set, override that. + //Otherwise we might show the wrong lazy loaded image. + var originalAttributeChanged = this.onAttributeChanged; + this.onAttributeChanged = (name, newValue) => { + if (name == "src" && this._lazy_src) { + //Update the lazy src + this._lazy_src = newValue; + } else { + //Call the original function. + originalAttributeChanged.call(this, name, newValue); + } + }; + //If we have a placeholder set it if (placeholder) { if (placeholder instanceof IgniteProperty) {