-
Notifications
You must be signed in to change notification settings - Fork 69
Add native lazy loading callback #155
base: master
Are you sure you want to change the base?
Conversation
| IMAGE: "c-image", | ||
| IMAGE_LAZY_LOADED: "-lazy-loaded", | ||
| IMAGE_LAZY_LOADING: "-lazy-loading", | ||
| IMAGE_LAZY_ERROR: "-lazy-error", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Respect the existing quotation style and prioritize single quotes.
| IMAGE: "c-image", | |
| IMAGE_LAZY_LOADED: "-lazy-loaded", | |
| IMAGE_LAZY_LOADING: "-lazy-loading", | |
| IMAGE_LAZY_ERROR: "-lazy-error", | |
| IMAGE: 'c-image', | |
| IMAGE_LAZY_LOADED: '-lazy-loaded', | |
| IMAGE_LAZY_LOADING: '-lazy-loading', | |
| IMAGE_LAZY_ERROR: '-lazy-error', |
| /** | ||
| * Trigger lazyload | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superfluous comment given the called function name.
| /** | |
| * Trigger lazyload | |
| */ |
| /** | ||
| * Trigger lazyload | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superfluous comment given the called function name.
| /** | |
| * Trigger lazyload | |
| */ |
| triggerLazyloadCallbacks(); | ||
| }); | ||
|
|
||
| this.load.on("loading", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Respect the existing quotation style and prioritize single quotes.
| this.load.on("loading", () => { | |
| this.load.on('loading', () => { |
| /** | ||
| * Remove previous lazyload callbacks | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superfluous comment given the called function name.
| /** | |
| * Remove previous lazyload callbacks | |
| */ |
| /** | ||
| * Observe new scroll elements | ||
| * | ||
| * @param $newContainer (HTMLElement) | ||
| */ | ||
| addScrollElements($newContainer) { | ||
| this.scroll?.addScrollElements($newContainer) | ||
| } | ||
|
|
||
| /** | ||
| * Unobserve scroll elements | ||
| * | ||
| * @param $oldContainer (HTMLElement) | ||
| */ | ||
| removeScrollElements($oldContainer) { | ||
| this.scroll?.removeScrollElements($oldContainer) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misaligned block comment syntax and invalid parameter tags.
| /** | |
| * Observe new scroll elements | |
| * | |
| * @param $newContainer (HTMLElement) | |
| */ | |
| addScrollElements($newContainer) { | |
| this.scroll?.addScrollElements($newContainer) | |
| } | |
| /** | |
| * Unobserve scroll elements | |
| * | |
| * @param $oldContainer (HTMLElement) | |
| */ | |
| removeScrollElements($oldContainer) { | |
| this.scroll?.removeScrollElements($oldContainer) | |
| } | |
| /** | |
| * Observe new scroll elements | |
| * | |
| * @param {HTMLElement} $newContainer | |
| */ | |
| addScrollElements($newContainer) { | |
| this.scroll?.addScrollElements($newContainer) | |
| } | |
| /** | |
| * Unobserve scroll elements | |
| * | |
| * @param {HTMLElement} $oldContainer | |
| */ | |
| removeScrollElements($oldContainer) { | |
| this.scroll?.removeScrollElements($oldContainer) | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of scope coding style corrections. Ideally, these corrections should be their own commit either in a different pull request or directly on the main branch.
Respect the existing quotation style and prioritize single quotes.
| // https://gomakethings.com/how-to-get-the-closest-parent-element-with-a-matching-selector-using-vanilla-javascript/ | ||
| const queryClosestParent = ($el, selector) => { | ||
| // Element.matches() polyfill | ||
| if (!Element.prototype.matches) { | ||
| Element.prototype.matches = | ||
| Element.prototype.matchesSelector || | ||
| Element.prototype.mozMatchesSelector || | ||
| Element.prototype.msMatchesSelector || | ||
| Element.prototype.oMatchesSelector || | ||
| Element.prototype.webkitMatchesSelector || | ||
| function (s) { | ||
| var matches = ( | ||
| this.document || this.ownerDocument | ||
| ).querySelectorAll(s), | ||
| i = matches.length; | ||
| while (--i >= 0 && matches.item(i) !== this) {} | ||
| return i > -1; | ||
| }; | ||
| } | ||
|
|
||
| // Get the closest matching element | ||
| for (; $el && $el !== document; $el = $el.parentNode) { | ||
| if ($el.matches(selector)) return $el; | ||
| } | ||
| return null; | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary polyfill removed in f527488 (2022-06) and replaced in 082f3b5 (2021-10) with Element.prototype.closest.
| // https://gomakethings.com/how-to-get-the-closest-parent-element-with-a-matching-selector-using-vanilla-javascript/ | |
| const queryClosestParent = ($el, selector) => { | |
| // Element.matches() polyfill | |
| if (!Element.prototype.matches) { | |
| Element.prototype.matches = | |
| Element.prototype.matchesSelector || | |
| Element.prototype.mozMatchesSelector || | |
| Element.prototype.msMatchesSelector || | |
| Element.prototype.oMatchesSelector || | |
| Element.prototype.webkitMatchesSelector || | |
| function (s) { | |
| var matches = ( | |
| this.document || this.ownerDocument | |
| ).querySelectorAll(s), | |
| i = matches.length; | |
| while (--i >= 0 && matches.item(i) !== this) {} | |
| return i > -1; | |
| }; | |
| } | |
| // Get the closest matching element | |
| for (; $el && $el !== document; $el = $el.parentNode) { | |
| if ($el.matches(selector)) return $el; | |
| } | |
| return null; | |
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use Element.prototype.closest instead of the queryClosestParent polyfill. See comment in html.js
Respect the existing quotation style and prioritize single quotes.
No description provided.