Skip to content

Instantly share code, notes, and snippets.

@broguinn
Created January 9, 2018 18:26
Show Gist options
  • Save broguinn/b77e3d89456894ef7a719ef3bcbb47f1 to your computer and use it in GitHub Desktop.
Save broguinn/b77e3d89456894ef7a719ef3bcbb47f1 to your computer and use it in GitHub Desktop.
Patch for lazyload
index 5be7b5083434..4d845f5dd0aa 100644
--- a/htdocs/assets/js/lib/lazyload.js
+++ b/htdocs/assets/js/lib/lazyload.js
@@ -1,5 +1,9 @@
-// set up lazyload, which looks for data-img properties on img tags and automatically loads them lazily
-// src: https://github.com/verlok/lazyload
+/* set up lazyload, which looks for data-img properties on img tags and automatically loads them lazily
+ src: https://github.com/verlok/lazyload
+ version 10.4.x
+ We've modified from the original file by removing the IntersectionRatio check in onIntersection as it
+ occasionally is 0 and was being ignored
+*/
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
@@ -181,6 +185,7 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
var LazyLoad = function LazyLoad(instanceSettings, elements) {
this._settings = _extends({}, defaultSettings, instanceSettings);
+ this._initialized = false;
this._setObserver();
this.update(elements);
};
@@ -196,12 +201,13 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
var settings = this._settings;
var onIntersection = function onIntersection(entries) {
entries.forEach(function (entry) {
- if (entry.intersectionRatio > 0) {
+ if (_this._initialized && entry.intersectionRatio >= 0) {
var element = entry.target;
revealElement(element, settings);
_this._observer.unobserve(element);
}
});
+ _this._initialized = true;
_this._elements = purgeElements(_this._elements);
};
this._observer = new IntersectionObserver(onIntersection, {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment