Version Description
- 22 aug. 2017
- Update lazyload script to latest version
- Change the way the script is loaded
Download this release
Release Info
| Developer | wp_media |
| Plugin | |
| Version | 1.2 |
| Comparing to | |
| See all releases | |
Code changes from version 1.1.1 to 1.2
- assets/js/lazyload-8.0.3.js +326 -0
- assets/js/lazyload-8.0.3.min.js +1 -0
- readme.txt +8 -3
- rocket-lazy-load.php +73 -36
assets/js/lazyload-8.0.3.js
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
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; };
|
| 2 |
+
|
| 3 |
+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
| 4 |
+
|
| 5 |
+
(function (global, factory) {
|
| 6 |
+
(typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : global.LazyLoad = factory();
|
| 7 |
+
})(this, function () {
|
| 8 |
+
'use strict';
|
| 9 |
+
|
| 10 |
+
var defaultSettings = {
|
| 11 |
+
elements_selector: "img",
|
| 12 |
+
container: window,
|
| 13 |
+
threshold: 300,
|
| 14 |
+
throttle: 150,
|
| 15 |
+
data_src: "original",
|
| 16 |
+
data_srcset: "originalSet",
|
| 17 |
+
class_loading: "loading",
|
| 18 |
+
class_loaded: "loaded",
|
| 19 |
+
class_error: "error",
|
| 20 |
+
class_initial: "initial",
|
| 21 |
+
skip_invisible: true,
|
| 22 |
+
callback_load: null,
|
| 23 |
+
callback_error: null,
|
| 24 |
+
callback_set: null,
|
| 25 |
+
callback_processed: null
|
| 26 |
+
};
|
| 27 |
+
|
| 28 |
+
var isBot = !("onscroll" in window) || /glebot/.test(navigator.userAgent);
|
| 29 |
+
|
| 30 |
+
var callCallback = function callCallback(callback, argument) {
|
| 31 |
+
if (callback) {
|
| 32 |
+
callback(argument);
|
| 33 |
+
}
|
| 34 |
+
};
|
| 35 |
+
|
| 36 |
+
var getTopOffset = function getTopOffset(element) {
|
| 37 |
+
return element.getBoundingClientRect().top + window.pageYOffset - element.ownerDocument.documentElement.clientTop;
|
| 38 |
+
};
|
| 39 |
+
|
| 40 |
+
var isBelowViewport = function isBelowViewport(element, container, threshold) {
|
| 41 |
+
var fold = container === window ? window.innerHeight + window.pageYOffset : getTopOffset(container) + container.offsetHeight;
|
| 42 |
+
return fold <= getTopOffset(element) - threshold;
|
| 43 |
+
};
|
| 44 |
+
|
| 45 |
+
var getLeftOffset = function getLeftOffset(element) {
|
| 46 |
+
return element.getBoundingClientRect().left + window.pageXOffset - element.ownerDocument.documentElement.clientLeft;
|
| 47 |
+
};
|
| 48 |
+
|
| 49 |
+
var isAtRightOfViewport = function isAtRightOfViewport(element, container, threshold) {
|
| 50 |
+
var documentWidth = window.innerWidth;
|
| 51 |
+
var fold = container === window ? documentWidth + window.pageXOffset : getLeftOffset(container) + documentWidth;
|
| 52 |
+
return fold <= getLeftOffset(element) - threshold;
|
| 53 |
+
};
|
| 54 |
+
|
| 55 |
+
var isAboveViewport = function isAboveViewport(element, container, threshold) {
|
| 56 |
+
var fold = container === window ? window.pageYOffset : getTopOffset(container);
|
| 57 |
+
return fold >= getTopOffset(element) + threshold + element.offsetHeight;
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
var isAtLeftOfViewport = function isAtLeftOfViewport(element, container, threshold) {
|
| 61 |
+
var fold = container === window ? window.pageXOffset : getLeftOffset(container);
|
| 62 |
+
return fold >= getLeftOffset(element) + threshold + element.offsetWidth;
|
| 63 |
+
};
|
| 64 |
+
|
| 65 |
+
var isInsideViewport = function isInsideViewport(element, container, threshold) {
|
| 66 |
+
return !isBelowViewport(element, container, threshold) && !isAboveViewport(element, container, threshold) && !isAtRightOfViewport(element, container, threshold) && !isAtLeftOfViewport(element, container, threshold);
|
| 67 |
+
};
|
| 68 |
+
|
| 69 |
+
/* Creates instance and notifies it through the window element */
|
| 70 |
+
var createInstance = function createInstance(classObj, options) {
|
| 71 |
+
var instance = new classObj(options);
|
| 72 |
+
var event = new CustomEvent("LazyLoad::Initialized", { detail: { instance: instance } });
|
| 73 |
+
window.dispatchEvent(event);
|
| 74 |
+
};
|
| 75 |
+
|
| 76 |
+
/* Auto initialization of one or more instances of lazyload, depending on the
|
| 77 |
+
options passed in (plain object or an array) */
|
| 78 |
+
var autoInitialize = function autoInitialize(classObj, options) {
|
| 79 |
+
var optsLength = options.length;
|
| 80 |
+
if (!optsLength) {
|
| 81 |
+
// Plain object
|
| 82 |
+
createInstance(classObj, options);
|
| 83 |
+
} else {
|
| 84 |
+
// Array of objects
|
| 85 |
+
for (var i = 0; i < optsLength; i++) {
|
| 86 |
+
createInstance(classObj, options[i]);
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
};
|
| 90 |
+
|
| 91 |
+
var setSourcesForPicture = function setSourcesForPicture(element, srcsetDataAttribute) {
|
| 92 |
+
var parent = element.parentElement;
|
| 93 |
+
if (parent.tagName !== "PICTURE") {
|
| 94 |
+
return;
|
| 95 |
+
}
|
| 96 |
+
for (var i = 0; i < parent.children.length; i++) {
|
| 97 |
+
var pictureChild = parent.children[i];
|
| 98 |
+
if (pictureChild.tagName === "SOURCE") {
|
| 99 |
+
var sourceSrcset = pictureChild.dataset[srcsetDataAttribute];
|
| 100 |
+
if (sourceSrcset) {
|
| 101 |
+
pictureChild.setAttribute("srcset", sourceSrcset);
|
| 102 |
+
}
|
| 103 |
+
}
|
| 104 |
+
}
|
| 105 |
+
};
|
| 106 |
+
|
| 107 |
+
var setSources = function setSources(element, srcsetDataAttribute, srcDataAttribute) {
|
| 108 |
+
var tagName = element.tagName;
|
| 109 |
+
var elementSrc = element.dataset[srcDataAttribute];
|
| 110 |
+
if (tagName === "IMG") {
|
| 111 |
+
setSourcesForPicture(element, srcsetDataAttribute);
|
| 112 |
+
var imgSrcset = element.dataset[srcsetDataAttribute];
|
| 113 |
+
if (imgSrcset) {
|
| 114 |
+
element.setAttribute("srcset", imgSrcset);
|
| 115 |
+
}
|
| 116 |
+
if (elementSrc) {
|
| 117 |
+
element.setAttribute("src", elementSrc);
|
| 118 |
+
}
|
| 119 |
+
return;
|
| 120 |
+
}
|
| 121 |
+
if (tagName === "IFRAME") {
|
| 122 |
+
if (elementSrc) {
|
| 123 |
+
element.setAttribute("src", elementSrc);
|
| 124 |
+
}
|
| 125 |
+
return;
|
| 126 |
+
}
|
| 127 |
+
if (elementSrc) {
|
| 128 |
+
element.style.backgroundImage = 'url("' + elementSrc + '")';
|
| 129 |
+
}
|
| 130 |
+
};
|
| 131 |
+
|
| 132 |
+
/*
|
| 133 |
+
* Constructor
|
| 134 |
+
*/
|
| 135 |
+
|
| 136 |
+
var LazyLoad = function LazyLoad(instanceSettings) {
|
| 137 |
+
this._settings = _extends({}, defaultSettings, instanceSettings);
|
| 138 |
+
this._queryOriginNode = this._settings.container === window ? document : this._settings.container;
|
| 139 |
+
|
| 140 |
+
this._previousLoopTime = 0;
|
| 141 |
+
this._loopTimeout = null;
|
| 142 |
+
this._boundHandleScroll = this.handleScroll.bind(this);
|
| 143 |
+
|
| 144 |
+
this._isFirstLoop = true;
|
| 145 |
+
window.addEventListener("resize", this._boundHandleScroll);
|
| 146 |
+
this.update();
|
| 147 |
+
};
|
| 148 |
+
|
| 149 |
+
LazyLoad.prototype = {
|
| 150 |
+
|
| 151 |
+
/*
|
| 152 |
+
* Private methods
|
| 153 |
+
*/
|
| 154 |
+
|
| 155 |
+
_reveal: function _reveal(element) {
|
| 156 |
+
var settings = this._settings;
|
| 157 |
+
|
| 158 |
+
var errorCallback = function errorCallback() {
|
| 159 |
+
/* As this method is asynchronous, it must be protected against external destroy() calls */
|
| 160 |
+
if (!settings) {
|
| 161 |
+
return;
|
| 162 |
+
}
|
| 163 |
+
element.removeEventListener("load", loadCallback);
|
| 164 |
+
element.removeEventListener("error", errorCallback);
|
| 165 |
+
element.classList.remove(settings.class_loading);
|
| 166 |
+
element.classList.add(settings.class_error);
|
| 167 |
+
callCallback(settings.callback_error, element);
|
| 168 |
+
};
|
| 169 |
+
|
| 170 |
+
var loadCallback = function loadCallback() {
|
| 171 |
+
/* As this method is asynchronous, it must be protected against external destroy() calls */
|
| 172 |
+
if (!settings) {
|
| 173 |
+
return;
|
| 174 |
+
}
|
| 175 |
+
element.classList.remove(settings.class_loading);
|
| 176 |
+
element.classList.add(settings.class_loaded);
|
| 177 |
+
element.removeEventListener("load", loadCallback);
|
| 178 |
+
element.removeEventListener("error", errorCallback);
|
| 179 |
+
/* Calling LOAD callback */
|
| 180 |
+
callCallback(settings.callback_load, element);
|
| 181 |
+
};
|
| 182 |
+
|
| 183 |
+
if (element.tagName === "IMG" || element.tagName === "IFRAME") {
|
| 184 |
+
element.addEventListener("load", loadCallback);
|
| 185 |
+
element.addEventListener("error", errorCallback);
|
| 186 |
+
element.classList.add(settings.class_loading);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
setSources(element, settings.data_srcset, settings.data_src);
|
| 190 |
+
/* Calling SET callback */
|
| 191 |
+
callCallback(settings.callback_set, element);
|
| 192 |
+
},
|
| 193 |
+
|
| 194 |
+
_loopThroughElements: function _loopThroughElements() {
|
| 195 |
+
var settings = this._settings,
|
| 196 |
+
elements = this._elements,
|
| 197 |
+
elementsLength = !elements ? 0 : elements.length;
|
| 198 |
+
var i = void 0,
|
| 199 |
+
processedIndexes = [],
|
| 200 |
+
firstLoop = this._isFirstLoop;
|
| 201 |
+
|
| 202 |
+
for (i = 0; i < elementsLength; i++) {
|
| 203 |
+
var element = elements[i];
|
| 204 |
+
/* If must skip_invisible and element is invisible, skip it */
|
| 205 |
+
if (settings.skip_invisible && element.offsetParent === null) {
|
| 206 |
+
continue;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
if (isBot || isInsideViewport(element, settings.container, settings.threshold)) {
|
| 210 |
+
if (firstLoop) {
|
| 211 |
+
element.classList.add(settings.class_initial);
|
| 212 |
+
}
|
| 213 |
+
/* Start loading the image */
|
| 214 |
+
this._reveal(element);
|
| 215 |
+
/* Marking the element as processed. */
|
| 216 |
+
processedIndexes.push(i);
|
| 217 |
+
element.dataset.wasProcessed = true;
|
| 218 |
+
}
|
| 219 |
+
}
|
| 220 |
+
/* Removing processed elements from this._elements. */
|
| 221 |
+
while (processedIndexes.length) {
|
| 222 |
+
elements.splice(processedIndexes.pop(), 1);
|
| 223 |
+
/* Calling the end loop callback */
|
| 224 |
+
callCallback(settings.callback_processed, elements.length);
|
| 225 |
+
}
|
| 226 |
+
/* Stop listening to scroll event when 0 elements remains */
|
| 227 |
+
if (elementsLength === 0) {
|
| 228 |
+
this._stopScrollHandler();
|
| 229 |
+
}
|
| 230 |
+
/* Sets isFirstLoop to false */
|
| 231 |
+
if (firstLoop) {
|
| 232 |
+
this._isFirstLoop = false;
|
| 233 |
+
}
|
| 234 |
+
},
|
| 235 |
+
|
| 236 |
+
_purgeElements: function _purgeElements() {
|
| 237 |
+
var elements = this._elements,
|
| 238 |
+
elementsLength = elements.length;
|
| 239 |
+
var i = void 0,
|
| 240 |
+
elementsToPurge = [];
|
| 241 |
+
|
| 242 |
+
for (i = 0; i < elementsLength; i++) {
|
| 243 |
+
var element = elements[i];
|
| 244 |
+
/* If the element has already been processed, skip it */
|
| 245 |
+
if (element.dataset.wasProcessed) {
|
| 246 |
+
elementsToPurge.push(i);
|
| 247 |
+
}
|
| 248 |
+
}
|
| 249 |
+
/* Removing elements to purge from this._elements. */
|
| 250 |
+
while (elementsToPurge.length > 0) {
|
| 251 |
+
elements.splice(elementsToPurge.pop(), 1);
|
| 252 |
+
}
|
| 253 |
+
},
|
| 254 |
+
|
| 255 |
+
_startScrollHandler: function _startScrollHandler() {
|
| 256 |
+
if (!this._isHandlingScroll) {
|
| 257 |
+
this._isHandlingScroll = true;
|
| 258 |
+
this._settings.container.addEventListener("scroll", this._boundHandleScroll);
|
| 259 |
+
}
|
| 260 |
+
},
|
| 261 |
+
|
| 262 |
+
_stopScrollHandler: function _stopScrollHandler() {
|
| 263 |
+
if (this._isHandlingScroll) {
|
| 264 |
+
this._isHandlingScroll = false;
|
| 265 |
+
this._settings.container.removeEventListener("scroll", this._boundHandleScroll);
|
| 266 |
+
}
|
| 267 |
+
},
|
| 268 |
+
|
| 269 |
+
/*
|
| 270 |
+
* Public methods
|
| 271 |
+
*/
|
| 272 |
+
|
| 273 |
+
handleScroll: function handleScroll() {
|
| 274 |
+
var throttle = this._settings.throttle;
|
| 275 |
+
|
| 276 |
+
if (throttle !== 0) {
|
| 277 |
+
var now = Date.now();
|
| 278 |
+
var remainingTime = throttle - (now - this._previousLoopTime);
|
| 279 |
+
if (remainingTime <= 0 || remainingTime > throttle) {
|
| 280 |
+
if (this._loopTimeout) {
|
| 281 |
+
clearTimeout(this._loopTimeout);
|
| 282 |
+
this._loopTimeout = null;
|
| 283 |
+
}
|
| 284 |
+
this._previousLoopTime = now;
|
| 285 |
+
this._loopThroughElements();
|
| 286 |
+
} else if (!this._loopTimeout) {
|
| 287 |
+
this._loopTimeout = setTimeout(function () {
|
| 288 |
+
this._previousLoopTime = Date.now();
|
| 289 |
+
this._loopTimeout = null;
|
| 290 |
+
this._loopThroughElements();
|
| 291 |
+
}.bind(this), remainingTime);
|
| 292 |
+
}
|
| 293 |
+
} else {
|
| 294 |
+
this._loopThroughElements();
|
| 295 |
+
}
|
| 296 |
+
},
|
| 297 |
+
|
| 298 |
+
update: function update() {
|
| 299 |
+
// Converts to array the nodeset obtained querying the DOM from _queryOriginNode with elements_selector
|
| 300 |
+
this._elements = Array.prototype.slice.call(this._queryOriginNode.querySelectorAll(this._settings.elements_selector));
|
| 301 |
+
this._purgeElements();
|
| 302 |
+
this._loopThroughElements();
|
| 303 |
+
this._startScrollHandler();
|
| 304 |
+
},
|
| 305 |
+
|
| 306 |
+
destroy: function destroy() {
|
| 307 |
+
window.removeEventListener("resize", this._boundHandleScroll);
|
| 308 |
+
if (this._loopTimeout) {
|
| 309 |
+
clearTimeout(this._loopTimeout);
|
| 310 |
+
this._loopTimeout = null;
|
| 311 |
+
}
|
| 312 |
+
this._stopScrollHandler();
|
| 313 |
+
this._elements = null;
|
| 314 |
+
this._queryOriginNode = null;
|
| 315 |
+
this._settings = null;
|
| 316 |
+
}
|
| 317 |
+
};
|
| 318 |
+
|
| 319 |
+
/* Automatic instances creation if required (useful for async script loading!) */
|
| 320 |
+
var autoInitOptions = window.lazyLoadOptions;
|
| 321 |
+
if (autoInitOptions) {
|
| 322 |
+
autoInitialize(LazyLoad, autoInitOptions);
|
| 323 |
+
}
|
| 324 |
+
|
| 325 |
+
return LazyLoad;
|
| 326 |
+
});
|
assets/js/lazyload-8.0.3.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
| 1 |
+
var _extends=Object.assign||function(a){for(var b=1;b<arguments.length;b++){var c=arguments[b];for(var d in c)Object.prototype.hasOwnProperty.call(c,d)&&(a[d]=c[d])}return a},_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a};!function(a,b){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?module.exports=b():"function"==typeof define&&define.amd?define(b):a.LazyLoad=b()}(this,function(){"use strict";var a={elements_selector:"img",container:window,threshold:300,throttle:150,data_src:"original",data_srcset:"originalSet",class_loading:"loading",class_loaded:"loaded",class_error:"error",class_initial:"initial",skip_invisible:!0,callback_load:null,callback_error:null,callback_set:null,callback_processed:null},b=!("onscroll"in window)||/glebot/.test(navigator.userAgent),c=function(a,b){a&&a(b)},d=function(a){return a.getBoundingClientRect().top+window.pageYOffset-a.ownerDocument.documentElement.clientTop},e=function(a,b,c){return(b===window?window.innerHeight+window.pageYOffset:d(b)+b.offsetHeight)<=d(a)-c},f=function(a){return a.getBoundingClientRect().left+window.pageXOffset-a.ownerDocument.documentElement.clientLeft},g=function(a,b,c){var d=window.innerWidth;return(b===window?d+window.pageXOffset:f(b)+d)<=f(a)-c},h=function(a,b,c){return(b===window?window.pageYOffset:d(b))>=d(a)+c+a.offsetHeight},i=function(a,b,c){return(b===window?window.pageXOffset:f(b))>=f(a)+c+a.offsetWidth},j=function(a,b,c){return!(e(a,b,c)||h(a,b,c)||g(a,b,c)||i(a,b,c))},k=function(a,b){var c=new a(b),d=new CustomEvent("LazyLoad::Initialized",{detail:{instance:c}});window.dispatchEvent(d)},l=function(a,b){var c=a.parentElement;if("PICTURE"===c.tagName)for(var d=0;d<c.children.length;d++){var e=c.children[d];if("SOURCE"===e.tagName){var f=e.dataset[b];f&&e.setAttribute("srcset",f)}}},m=function(a,b,c){var d=a.tagName,e=a.dataset[c];if("IMG"===d){l(a,b);var f=a.dataset[b];return f&&a.setAttribute("srcset",f),void(e&&a.setAttribute("src",e))}if("IFRAME"===d)return void(e&&a.setAttribute("src",e));e&&(a.style.backgroundImage='url("'+e+'")')},n=function(b){this._settings=_extends({},a,b),this._queryOriginNode=this._settings.container===window?document:this._settings.container,this._previousLoopTime=0,this._loopTimeout=null,this._boundHandleScroll=this.handleScroll.bind(this),this._isFirstLoop=!0,window.addEventListener("resize",this._boundHandleScroll),this.update()};n.prototype={_reveal:function(a){var b=this._settings,d=function d(){b&&(a.removeEventListener("load",e),a.removeEventListener("error",d),a.classList.remove(b.class_loading),a.classList.add(b.class_error),c(b.callback_error,a))},e=function e(){b&&(a.classList.remove(b.class_loading),a.classList.add(b.class_loaded),a.removeEventListener("load",e),a.removeEventListener("error",d),c(b.callback_load,a))};"IMG"!==a.tagName&&"IFRAME"!==a.tagName||(a.addEventListener("load",e),a.addEventListener("error",d),a.classList.add(b.class_loading)),m(a,b.data_srcset,b.data_src),c(b.callback_set,a)},_loopThroughElements:function(){var a=this._settings,d=this._elements,e=d?d.length:0,f=void 0,g=[],h=this._isFirstLoop;for(f=0;f<e;f++){var i=d[f];a.skip_invisible&&null===i.offsetParent||(b||j(i,a.container,a.threshold))&&(h&&i.classList.add(a.class_initial),this._reveal(i),g.push(f),i.dataset.wasProcessed=!0)}for(;g.length;)d.splice(g.pop(),1),c(a.callback_processed,d.length);0===e&&this._stopScrollHandler(),h&&(this._isFirstLoop=!1)},_purgeElements:function(){var a=this._elements,b=a.length,c=void 0,d=[];for(c=0;c<b;c++){a[c].dataset.wasProcessed&&d.push(c)}for(;d.length>0;)a.splice(d.pop(),1)},_startScrollHandler:function(){this._isHandlingScroll||(this._isHandlingScroll=!0,this._settings.container.addEventListener("scroll",this._boundHandleScroll))},_stopScrollHandler:function(){this._isHandlingScroll&&(this._isHandlingScroll=!1,this._settings.container.removeEventListener("scroll",this._boundHandleScroll))},handleScroll:function(){var a=this._settings.throttle;if(0!==a){var b=Date.now(),c=a-(b-this._previousLoopTime);c<=0||c>a?(this._loopTimeout&&(clearTimeout(this._loopTimeout),this._loopTimeout=null),this._previousLoopTime=b,this._loopThroughElements()):this._loopTimeout||(this._loopTimeout=setTimeout(function(){this._previousLoopTime=Date.now(),this._loopTimeout=null,this._loopThroughElements()}.bind(this),c))}else this._loopThroughElements()},update:function(){this._elements=Array.prototype.slice.call(this._queryOriginNode.querySelectorAll(this._settings.elements_selector)),this._purgeElements(),this._loopThroughElements(),this._startScrollHandler()},destroy:function(){window.removeEventListener("resize",this._boundHandleScroll),this._loopTimeout&&(clearTimeout(this._loopTimeout),this._loopTimeout=null),this._stopScrollHandler(),this._elements=null,this._queryOriginNode=null,this._settings=null}};var o=window.lazyLoadOptions;return o&&function(a,b){var c=b.length;if(c)for(var d=0;d<c;d++)k(a,b[d]);else k(a,b)}(n,o),n});
|
readme.txt
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
=== Rocket Lazy Load ===
|
| 2 |
-
Contributors: geekpress, wp_media
|
| 3 |
Tags: lazyload, lazy load, images, thumbnail, thumbnails, smiley, smilies, avatar, gravatar
|
| 4 |
Requires at least: 3.0
|
| 5 |
-
Tested up to: 4.
|
| 6 |
-
Stable tag: 1.
|
| 7 |
|
| 8 |
The tiny Lazy Load script for WordPress without jQuery or others libraries.
|
| 9 |
|
|
@@ -45,6 +45,11 @@ function deactivate_rocket_lazyload_on_single() {
|
|
| 45 |
Simply add a 'data-no-lazy="1"' property in you IMG tag.
|
| 46 |
|
| 47 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
= 1.1.1 =
|
| 49 |
* 13 feb. 2017
|
| 50 |
* Bug fix: Remove use of short tag to prevent 500 error on some installations
|
| 1 |
=== Rocket Lazy Load ===
|
| 2 |
+
Contributors: Contributors: geekpress, tabrisrp, creativejuiz, wp_media
|
| 3 |
Tags: lazyload, lazy load, images, thumbnail, thumbnails, smiley, smilies, avatar, gravatar
|
| 4 |
Requires at least: 3.0
|
| 5 |
+
Tested up to: 4.8.1
|
| 6 |
+
Stable tag: 1.2
|
| 7 |
|
| 8 |
The tiny Lazy Load script for WordPress without jQuery or others libraries.
|
| 9 |
|
| 45 |
Simply add a 'data-no-lazy="1"' property in you IMG tag.
|
| 46 |
|
| 47 |
== Changelog ==
|
| 48 |
+
= 1.2 =
|
| 49 |
+
* 22 aug. 2017
|
| 50 |
+
* Update lazyload script to latest version
|
| 51 |
+
* Change the way the script is loaded
|
| 52 |
+
|
| 53 |
= 1.1.1 =
|
| 54 |
* 13 feb. 2017
|
| 55 |
* Bug fix: Remove use of short tag to prevent 500 error on some installations
|
rocket-lazy-load.php
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
<?php
|
| 2 |
-
defined( 'ABSPATH' )
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Plugin Name: Rocket Lazy Load
|
| 6 |
* Plugin URI: http://wordpress.org/plugins/rocket-lazy-load/
|
| 7 |
* Description: The tiny Lazy Load script for WordPress without jQuery or others libraries.
|
| 8 |
-
* Version: 1.
|
| 9 |
* Author: WP Media
|
| 10 |
* Author URI: https://wp-rocket.me
|
| 11 |
* Text Domain: rocket-lazy-load
|
|
@@ -26,11 +26,11 @@ defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );
|
|
| 26 |
* You should have received a copy of the GNU General Public License
|
| 27 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 28 |
*/
|
| 29 |
-
define( 'ROCKET_LL_VERSION', '1.
|
| 30 |
define( 'ROCKET_LL_PATH', realpath( plugin_dir_path( __FILE__ ) ) . '/' );
|
| 31 |
define( 'ROCKET_LL_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets/' );
|
| 32 |
define( 'ROCKET_LL_FRONT_JS_URL', ROCKET_LL_ASSETS_URL . 'js/' );
|
| 33 |
-
define( 'ROCKET_LL_JS_VERSION' , '
|
| 34 |
|
| 35 |
|
| 36 |
/**
|
|
@@ -64,8 +64,7 @@ function rocket_lazyload_get_option( $option, $default = false ) {
|
|
| 64 |
}
|
| 65 |
|
| 66 |
/**
|
| 67 |
-
*
|
| 68 |
-
* No jQuery or other library is required
|
| 69 |
*
|
| 70 |
* @since 1.0
|
| 71 |
*/
|
|
@@ -74,43 +73,81 @@ function rocket_lazyload_script() {
|
|
| 74 |
return;
|
| 75 |
}
|
| 76 |
|
| 77 |
-
$
|
| 78 |
-
$ll_url = ROCKET_LL_FRONT_JS_URL . 'lazyload-' . ROCKET_LL_JS_VERSION . $suffix . '.js';
|
| 79 |
|
| 80 |
echo <<<HTML
|
| 81 |
-
<script
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
//todo: check if $.fn.fitvids() is available
|
| 93 |
-
if ( typeof $ === "function" ) {
|
| 94 |
$( element ).parent().fitVids();
|
|
|
|
|
|
|
|
|
|
| 95 |
}
|
| 96 |
-
}
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
} else {
|
| 103 |
-
clearInterval( temp );
|
| 104 |
-
}
|
| 105 |
-
}, 50 );
|
| 106 |
-
}
|
| 107 |
-
} // if element is an iframe
|
| 108 |
-
}
|
| 109 |
-
});
|
| 110 |
-
});})(window,document);</script>
|
| 111 |
HTML;
|
| 112 |
}
|
| 113 |
-
add_action( '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
/**
|
| 116 |
* Replace Gravatar, thumbnails, images in post content and in widget text by LazyLoad
|
| 1 |
<?php
|
| 2 |
+
defined( 'ABSPATH' ) || die( 'Cheatin\' uh?' );
|
| 3 |
|
| 4 |
/**
|
| 5 |
* Plugin Name: Rocket Lazy Load
|
| 6 |
* Plugin URI: http://wordpress.org/plugins/rocket-lazy-load/
|
| 7 |
* Description: The tiny Lazy Load script for WordPress without jQuery or others libraries.
|
| 8 |
+
* Version: 1.2
|
| 9 |
* Author: WP Media
|
| 10 |
* Author URI: https://wp-rocket.me
|
| 11 |
* Text Domain: rocket-lazy-load
|
| 26 |
* You should have received a copy of the GNU General Public License
|
| 27 |
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 28 |
*/
|
| 29 |
+
define( 'ROCKET_LL_VERSION', '1.2' );
|
| 30 |
define( 'ROCKET_LL_PATH', realpath( plugin_dir_path( __FILE__ ) ) . '/' );
|
| 31 |
define( 'ROCKET_LL_ASSETS_URL', plugin_dir_url( __FILE__ ) . 'assets/' );
|
| 32 |
define( 'ROCKET_LL_FRONT_JS_URL', ROCKET_LL_ASSETS_URL . 'js/' );
|
| 33 |
+
define( 'ROCKET_LL_JS_VERSION' , '8.0.3' );
|
| 34 |
|
| 35 |
|
| 36 |
/**
|
| 64 |
}
|
| 65 |
|
| 66 |
/**
|
| 67 |
+
* Set lazyload options
|
|
|
|
| 68 |
*
|
| 69 |
* @since 1.0
|
| 70 |
*/
|
| 73 |
return;
|
| 74 |
}
|
| 75 |
|
| 76 |
+
$threshold = apply_filters( 'rocket_lazyload_threshold', 300 );
|
|
|
|
| 77 |
|
| 78 |
echo <<<HTML
|
| 79 |
+
<script>
|
| 80 |
+
window.lazyLoadOptions = {
|
| 81 |
+
elements_selector: "img, iframe",
|
| 82 |
+
data_src: "lazySrc",
|
| 83 |
+
data_srcset: "lazySrcset",
|
| 84 |
+
class_loading: "lazyloading",
|
| 85 |
+
class_loaded: "lazyloaded",
|
| 86 |
+
threshold: $threshold,
|
| 87 |
+
callback_set: function(element) {
|
| 88 |
+
//todo: check fitvids compatibility (class or data-attribute)
|
| 89 |
+
if ( element.tagName === "IFRAME" && element.classList.contains("fitvidscompatible") ) {
|
| 90 |
+
if ( element.classList.contains("lazyloaded") ) {
|
| 91 |
+
//todo: check if $.fn.fitvids() is available
|
| 92 |
+
if ( typeof $ === "function" ) {
|
| 93 |
+
$( element ).parent().fitVids();
|
| 94 |
+
}
|
| 95 |
+
} else {
|
| 96 |
+
var temp = setInterval( function() {
|
| 97 |
//todo: check if $.fn.fitvids() is available
|
| 98 |
+
if ( element.classList.contains("lazyloaded") && typeof $ === "function" ) {
|
| 99 |
$( element ).parent().fitVids();
|
| 100 |
+
clearInterval( temp );
|
| 101 |
+
} else {
|
| 102 |
+
clearInterval( temp );
|
| 103 |
}
|
| 104 |
+
}, 50 );
|
| 105 |
+
}
|
| 106 |
+
} // if element is an iframe
|
| 107 |
+
}
|
| 108 |
+
};
|
| 109 |
+
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
HTML;
|
| 111 |
}
|
| 112 |
+
add_action( 'wp_footer', 'rocket_lazyload_script', 9 );
|
| 113 |
+
|
| 114 |
+
/**
|
| 115 |
+
* Enqueue the lazyload script
|
| 116 |
+
*
|
| 117 |
+
* @since 1.2
|
| 118 |
+
* @author Remy Perona
|
| 119 |
+
*/
|
| 120 |
+
function rocket_lazyload_enqueue() {
|
| 121 |
+
if ( ( ! get_rocket_option( 'lazyload' ) && ! get_rocket_option( 'lazyload_iframes' ) ) || ( ! apply_filters( 'do_rocket_lazyload', true ) && ! apply_filters( 'do_rocket_lazyload_iframes', true ) ) ) {
|
| 122 |
+
return;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
| 126 |
+
$lazyload_url = get_rocket_cdn_url( WP_ROCKET_FRONT_JS_URL . 'lazyload-' . WP_ROCKET_LAZYLOAD_JS_VERSION . $suffix . '.js', array( 'all', 'css_and_js', 'js' ) );
|
| 127 |
+
|
| 128 |
+
wp_enqueue_script( 'rocket-lazyload', $lazyload_url, null, null, true );
|
| 129 |
+
}
|
| 130 |
+
add_action( 'wp_enqueue_scripts', 'rocket_lazyload_enqueue', PHP_INT_MAX );
|
| 131 |
+
|
| 132 |
+
/**
|
| 133 |
+
* Add tags to the lazyload script to async and prevent concatenation
|
| 134 |
+
*
|
| 135 |
+
* @since 1.2
|
| 136 |
+
* @author Remy Perona
|
| 137 |
+
*
|
| 138 |
+
* @param string $tag HTML for the script.
|
| 139 |
+
* @param string $handle Handle for the script.
|
| 140 |
+
*
|
| 141 |
+
* @return string Updated HTML
|
| 142 |
+
*/
|
| 143 |
+
function rocket_lazyload_async_script( $tag, $handle ) {
|
| 144 |
+
if ( 'rocket-lazyload' === $handle ) {
|
| 145 |
+
return str_replace( '<script', '<script async data-cfasync="false" data-minify="1"', $tag );
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
return $tag;
|
| 149 |
+
}
|
| 150 |
+
add_filter( 'script_loader_tag', 'rocket_lazyload_async_script', 10, 2 );
|
| 151 |
|
| 152 |
/**
|
| 153 |
* Replace Gravatar, thumbnails, images in post content and in widget text by LazyLoad
|
