add wp-rocket
This commit is contained in:
109
wp-content/plugins/wp-rocket/assets/js/browser-checker.js
Normal file
109
wp-content/plugins/wp-rocket/assets/js/browser-checker.js
Normal file
@@ -0,0 +1,109 @@
|
||||
class RocketBrowserCompatibilityChecker {
|
||||
|
||||
constructor( options ) {
|
||||
this.passiveSupported = false;
|
||||
|
||||
this._checkPassiveOption( this );
|
||||
this.options = this.passiveSupported ? options : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes browser check for addEventListener passive option.
|
||||
*
|
||||
* @link https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
|
||||
* @private
|
||||
*
|
||||
* @param self Instance of this object.
|
||||
* @returns {boolean}
|
||||
*/
|
||||
_checkPassiveOption( self ) {
|
||||
try {
|
||||
const options = {
|
||||
// This function will be called when the browser attempts to access the passive property.
|
||||
get passive() {
|
||||
self.passiveSupported = true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener( 'test', null, options );
|
||||
window.removeEventListener( 'test', null, options );
|
||||
} catch ( err ) {
|
||||
self.passiveSupported = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the browser supports requestIdleCallback and cancelIdleCallback. If no, shims its behavior with a polyfills.
|
||||
*
|
||||
* @link @link https://developers.google.com/web/updates/2015/08/using-requestidlecallback
|
||||
*/
|
||||
initRequestIdleCallback() {
|
||||
if ( ! 'requestIdleCallback' in window ) {
|
||||
window.requestIdleCallback = ( cb ) => {
|
||||
const start = Date.now();
|
||||
return setTimeout( () => {
|
||||
cb( {
|
||||
didTimeout: false,
|
||||
timeRemaining: function timeRemaining() {
|
||||
return Math.max( 0, 50 - ( Date.now() - start ) );
|
||||
}
|
||||
} );
|
||||
}, 1 );
|
||||
};
|
||||
}
|
||||
|
||||
if ( ! 'cancelIdleCallback' in window ) {
|
||||
window.cancelIdleCallback = ( id ) => clearTimeout( id );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if data saver mode is on.
|
||||
*
|
||||
* @link https://developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/save-data/#detecting_the_save-data_setting
|
||||
*
|
||||
* @returns {boolean|boolean}
|
||||
*/
|
||||
isDataSaverModeOn() {
|
||||
return (
|
||||
'connection' in navigator
|
||||
&&
|
||||
true === navigator.connection.saveData
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the browser supports link prefetch.
|
||||
*
|
||||
* @returns {boolean|boolean}
|
||||
*/
|
||||
supportsLinkPrefetch() {
|
||||
const elem = document.createElement( 'link' );
|
||||
return (
|
||||
elem.relList
|
||||
&&
|
||||
elem.relList.supports
|
||||
&&
|
||||
elem.relList.supports( 'prefetch' )
|
||||
&&
|
||||
window.IntersectionObserver
|
||||
&&
|
||||
'isIntersecting' in IntersectionObserverEntry.prototype
|
||||
);
|
||||
}
|
||||
|
||||
isSlowConnection() {
|
||||
return (
|
||||
'connection' in navigator
|
||||
&&
|
||||
'effectiveType' in navigator.connection
|
||||
&&
|
||||
(
|
||||
'2g' === navigator.connection.effectiveType
|
||||
||
|
||||
'slow-2g' === navigator.connection.effectiveType
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
1
wp-content/plugins/wp-rocket/assets/js/browser-checker.min.js
vendored
Normal file
1
wp-content/plugins/wp-rocket/assets/js/browser-checker.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){return protoProps&&defineProperties(Constructor.prototype,protoProps),staticProps&&defineProperties(Constructor,staticProps),Constructor}}();function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}var RocketBrowserCompatibilityChecker=function(){function RocketBrowserCompatibilityChecker(options){_classCallCheck(this,RocketBrowserCompatibilityChecker),this.passiveSupported=!1,this._checkPassiveOption(this),this.options=!!this.passiveSupported&&options}return _createClass(RocketBrowserCompatibilityChecker,[{key:"_checkPassiveOption",value:function(self){try{var options={get passive(){return!(self.passiveSupported=!0)}};window.addEventListener("test",null,options),window.removeEventListener("test",null,options)}catch(err){self.passiveSupported=!1}}},{key:"initRequestIdleCallback",value:function(){!1 in window&&(window.requestIdleCallback=function(cb){var start=Date.now();return setTimeout(function(){cb({didTimeout:!1,timeRemaining:function(){return Math.max(0,50-(Date.now()-start))}})},1)}),!1 in window&&(window.cancelIdleCallback=function(id){return clearTimeout(id)})}},{key:"isDataSaverModeOn",value:function(){return"connection"in navigator&&!0===navigator.connection.saveData}},{key:"supportsLinkPrefetch",value:function(){var elem=document.createElement("link");return elem.relList&&elem.relList.supports&&elem.relList.supports("prefetch")&&window.IntersectionObserver&&"isIntersecting"in IntersectionObserverEntry.prototype}},{key:"isSlowConnection",value:function(){return"connection"in navigator&&"effectiveType"in navigator.connection&&("2g"===navigator.connection.effectiveType||"slow-2g"===navigator.connection.effectiveType)}}]),RocketBrowserCompatibilityChecker}();
|
16
wp-content/plugins/wp-rocket/assets/js/cpcss-removal.js
Normal file
16
wp-content/plugins/wp-rocket/assets/js/cpcss-removal.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const wprRemoveCPCSS = () => {
|
||||
if ( document.querySelector( 'link[data-rocket-async="style"][rel="preload"]' ) ) {
|
||||
setTimeout( wprRemoveCPCSS, 200 );
|
||||
} else {
|
||||
const elem = document.getElementById( 'rocket-critical-css' );
|
||||
if ( elem && 'remove' in elem ) {
|
||||
elem.remove();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if ( window.addEventListener ) {
|
||||
window.addEventListener( 'load', wprRemoveCPCSS );
|
||||
} else if ( window.attachEvent ) {
|
||||
window.attachEvent( 'onload', wprRemoveCPCSS );
|
||||
}
|
1
wp-content/plugins/wp-rocket/assets/js/cpcss-removal.min.js
vendored
Normal file
1
wp-content/plugins/wp-rocket/assets/js/cpcss-removal.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";var wprRemoveCPCSS=function wprRemoveCPCSS(){var elem;document.querySelector('link[data-rocket-async="style"][rel="preload"]')?setTimeout(wprRemoveCPCSS,200):(elem=document.getElementById("rocket-critical-css"))&&"remove"in elem&&elem.remove()};window.addEventListener?window.addEventListener("load",wprRemoveCPCSS):window.attachEvent&&window.attachEvent("onload",wprRemoveCPCSS);
|
1
wp-content/plugins/wp-rocket/assets/js/editor/editor.js
Normal file
1
wp-content/plugins/wp-rocket/assets/js/editor/editor.js
Normal file
@@ -0,0 +1 @@
|
||||
this.DisableEmbeds=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(e,t){!function(){e.exports=this.wp.blocks}()},function(e,t){!function(){e.exports=this.wp.domReady}()},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n(1);n.n(o)()(function(){Object(r.unregisterBlockType)("core-embed/wordpress")})}]);
|
108
wp-content/plugins/wp-rocket/assets/js/lazyload-scripts.js
Normal file
108
wp-content/plugins/wp-rocket/assets/js/lazyload-scripts.js
Normal file
@@ -0,0 +1,108 @@
|
||||
class RocketLazyLoadScripts {
|
||||
|
||||
constructor( triggerEvents, browser ) {
|
||||
this.attrName = 'data-rocketlazyloadscript';
|
||||
this.browser = browser;
|
||||
this.options = this.browser.options;
|
||||
this.triggerEvents = triggerEvents;
|
||||
this.userEventListener = this.triggerListener.bind( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the LazyLoad Scripts handler.
|
||||
*/
|
||||
init() {
|
||||
this._addEventListener( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the handler.
|
||||
*/
|
||||
reset() {
|
||||
this._removeEventListener( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener for each of the configured user interactivity event type. When an even is triggered, it invokes
|
||||
* the triggerListener() method.
|
||||
*
|
||||
* @private
|
||||
*
|
||||
* @param self Instance of this object.
|
||||
*/
|
||||
_addEventListener( self ) {
|
||||
this.triggerEvents.forEach(
|
||||
eventName => window.addEventListener( eventName, self.userEventListener, self.options )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the listener for each of the configured user interactivity event type.
|
||||
*
|
||||
* @private
|
||||
*
|
||||
* @param self Instance of this object.
|
||||
*/
|
||||
_removeEventListener( self ) {
|
||||
this.triggerEvents.forEach(
|
||||
eventName => window.removeEventListener( eventName, self.userEventListener, self.options )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the script's src from the data attribute, which will then trigger the browser to request and
|
||||
* load the script.
|
||||
*/
|
||||
_loadScriptSrc() {
|
||||
const scripts = document.querySelectorAll( `script[${ this.attrName }]` );
|
||||
|
||||
if ( 0 === scripts.length ) {
|
||||
this.reset();
|
||||
return;
|
||||
}
|
||||
|
||||
Array.prototype.slice.call( scripts ).forEach( elem => {
|
||||
const scriptSrc = elem.getAttribute( this.attrName );
|
||||
|
||||
elem.setAttribute( 'src', scriptSrc );
|
||||
elem.removeAttribute( this.attrName );
|
||||
} );
|
||||
|
||||
this.reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Window event listener - when triggered, invokes the load script src handler and then resets.
|
||||
*/
|
||||
triggerListener() {
|
||||
this._loadScriptSrc();
|
||||
this._removeEventListener( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Named static constructor to encapsulate how to create the object.
|
||||
*/
|
||||
static run() {
|
||||
// Bail out if the browser checker does not exist.
|
||||
if ( ! RocketBrowserCompatibilityChecker ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const options = {
|
||||
passive: true
|
||||
};
|
||||
const browser = new RocketBrowserCompatibilityChecker( options );
|
||||
const instance = new RocketLazyLoadScripts(
|
||||
[
|
||||
'keydown',
|
||||
'mouseover',
|
||||
'touchmove',
|
||||
'touchstart'
|
||||
],
|
||||
browser
|
||||
);
|
||||
instance.init();
|
||||
}
|
||||
}
|
||||
|
||||
RocketLazyLoadScripts.run();
|
3
wp-content/plugins/wp-rocket/assets/js/lazyload-scripts.min.js
vendored
Normal file
3
wp-content/plugins/wp-rocket/assets/js/lazyload-scripts.min.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
(function() {
|
||||
"use strict";var e=function(){function n(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(e,t,r){return t&&n(e.prototype,t),r&&n(e,r),e}}();function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=function(){function r(e,t){n(this,r),this.attrName="data-rocketlazyloadscript",this.browser=t,this.options=this.browser.options,this.triggerEvents=e,this.userEventListener=this.triggerListener.bind(this)}return e(r,[{key:"init",value:function(){this._addEventListener(this)}},{key:"reset",value:function(){this._removeEventListener(this)}},{key:"_addEventListener",value:function(t){this.triggerEvents.forEach(function(e){return window.addEventListener(e,t.userEventListener,t.options)})}},{key:"_removeEventListener",value:function(t){this.triggerEvents.forEach(function(e){return window.removeEventListener(e,t.userEventListener,t.options)})}},{key:"_loadScriptSrc",value:function(){var r=this,e=document.querySelectorAll("script["+this.attrName+"]");0!==e.length&&Array.prototype.slice.call(e).forEach(function(e){var t=e.getAttribute(r.attrName);e.setAttribute("src",t),e.removeAttribute(r.attrName)}),this.reset()}},{key:"triggerListener",value:function(){this._loadScriptSrc(),this._removeEventListener(this)}}],[{key:"run",value:function(){RocketBrowserCompatibilityChecker&&new r(["keydown","mouseover","touchmove","touchstart"],new RocketBrowserCompatibilityChecker({passive:!0})).init()}}]),r}();t.run();
|
||||
}());
|
@@ -0,0 +1,461 @@
|
||||
function _extends() { _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; }; return _extends.apply(this, arguments); }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
(function (global, factory) {
|
||||
(typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : global.LazyLoad = factory();
|
||||
})(this, function () {
|
||||
'use strict';
|
||||
|
||||
var runningOnBrowser = typeof window !== "undefined";
|
||||
var isBot = runningOnBrowser && !("onscroll" in window) || typeof navigator !== "undefined" && /(gle|ing|ro)bot|crawl|spider/i.test(navigator.userAgent);
|
||||
var supportsIntersectionObserver = runningOnBrowser && "IntersectionObserver" in window;
|
||||
var supportsClassList = runningOnBrowser && "classList" in document.createElement("p");
|
||||
var defaultSettings = {
|
||||
elements_selector: "img",
|
||||
container: isBot || runningOnBrowser ? document : null,
|
||||
threshold: 300,
|
||||
thresholds: null,
|
||||
data_src: "src",
|
||||
data_srcset: "srcset",
|
||||
data_sizes: "sizes",
|
||||
data_bg: "bg",
|
||||
class_loading: "loading",
|
||||
class_loaded: "loaded",
|
||||
class_error: "error",
|
||||
load_delay: 0,
|
||||
auto_unobserve: true,
|
||||
callback_enter: null,
|
||||
callback_exit: null,
|
||||
callback_reveal: null,
|
||||
callback_loaded: null,
|
||||
callback_error: null,
|
||||
callback_finish: null
|
||||
};
|
||||
|
||||
var getInstanceSettings = function getInstanceSettings(customSettings) {
|
||||
return _extends({}, defaultSettings, customSettings);
|
||||
};
|
||||
|
||||
var dataPrefix = "data-";
|
||||
var processedDataName = "was-processed";
|
||||
var timeoutDataName = "ll-timeout";
|
||||
var trueString = "true";
|
||||
|
||||
var getData = function getData(element, attribute) {
|
||||
return element.getAttribute(dataPrefix + attribute);
|
||||
};
|
||||
|
||||
var setData = function setData(element, attribute, value) {
|
||||
var attrName = dataPrefix + attribute;
|
||||
|
||||
if (value === null) {
|
||||
element.removeAttribute(attrName);
|
||||
return;
|
||||
}
|
||||
|
||||
element.setAttribute(attrName, value);
|
||||
};
|
||||
|
||||
var setWasProcessedData = function setWasProcessedData(element) {
|
||||
return setData(element, processedDataName, trueString);
|
||||
};
|
||||
|
||||
var getWasProcessedData = function getWasProcessedData(element) {
|
||||
return getData(element, processedDataName) === trueString;
|
||||
};
|
||||
|
||||
var setTimeoutData = function setTimeoutData(element, value) {
|
||||
return setData(element, timeoutDataName, value);
|
||||
};
|
||||
|
||||
var getTimeoutData = function getTimeoutData(element) {
|
||||
return getData(element, timeoutDataName);
|
||||
};
|
||||
|
||||
var purgeProcessedElements = function purgeProcessedElements(elements) {
|
||||
return elements.filter(function (element) {
|
||||
return !getWasProcessedData(element);
|
||||
});
|
||||
};
|
||||
|
||||
var purgeOneElement = function purgeOneElement(elements, elementToPurge) {
|
||||
return elements.filter(function (element) {
|
||||
return element !== elementToPurge;
|
||||
});
|
||||
};
|
||||
/* Creates instance and notifies it through the window element */
|
||||
|
||||
|
||||
var createInstance = function createInstance(classObj, options) {
|
||||
var event;
|
||||
var eventString = "LazyLoad::Initialized";
|
||||
var instance = new classObj(options);
|
||||
|
||||
try {
|
||||
// Works in modern browsers
|
||||
event = new CustomEvent(eventString, {
|
||||
detail: {
|
||||
instance: instance
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
// Works in Internet Explorer (all versions)
|
||||
event = document.createEvent("CustomEvent");
|
||||
event.initCustomEvent(eventString, false, false, {
|
||||
instance: instance
|
||||
});
|
||||
}
|
||||
|
||||
window.dispatchEvent(event);
|
||||
};
|
||||
/* Auto initialization of one or more instances of lazyload, depending on the
|
||||
options passed in (plain object or an array) */
|
||||
|
||||
|
||||
function autoInitialize(classObj, options) {
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!options.length) {
|
||||
// Plain object
|
||||
createInstance(classObj, options);
|
||||
} else {
|
||||
// Array of objects
|
||||
for (var i = 0, optionsItem; optionsItem = options[i]; i += 1) {
|
||||
createInstance(classObj, optionsItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var callbackIfSet = function callbackIfSet(callback, argument) {
|
||||
if (callback) {
|
||||
callback(argument);
|
||||
}
|
||||
};
|
||||
|
||||
var updateLoadingCount = function updateLoadingCount(instance, plusMinus) {
|
||||
instance._loadingCount += plusMinus;
|
||||
|
||||
if (instance._elements.length === 0 && instance._loadingCount === 0) {
|
||||
callbackIfSet(instance._settings.callback_finish);
|
||||
}
|
||||
};
|
||||
|
||||
var getSourceTags = function getSourceTags(parentTag) {
|
||||
var sourceTags = [];
|
||||
|
||||
for (var i = 0, childTag; childTag = parentTag.children[i]; i += 1) {
|
||||
if (childTag.tagName === "SOURCE") {
|
||||
sourceTags.push(childTag);
|
||||
}
|
||||
}
|
||||
|
||||
return sourceTags;
|
||||
};
|
||||
|
||||
var setAttributeIfValue = function setAttributeIfValue(element, attrName, value) {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
element.setAttribute(attrName, value);
|
||||
};
|
||||
|
||||
var setImageAttributes = function setImageAttributes(element, settings) {
|
||||
setAttributeIfValue(element, "sizes", getData(element, settings.data_sizes));
|
||||
setAttributeIfValue(element, "srcset", getData(element, settings.data_srcset));
|
||||
setAttributeIfValue(element, "src", getData(element, settings.data_src));
|
||||
};
|
||||
|
||||
var setSourcesImg = function setSourcesImg(element, settings) {
|
||||
var parent = element.parentNode;
|
||||
|
||||
if (parent && parent.tagName === "PICTURE") {
|
||||
var sourceTags = getSourceTags(parent);
|
||||
sourceTags.forEach(function (sourceTag) {
|
||||
setImageAttributes(sourceTag, settings);
|
||||
});
|
||||
}
|
||||
|
||||
setImageAttributes(element, settings);
|
||||
};
|
||||
|
||||
var setSourcesIframe = function setSourcesIframe(element, settings) {
|
||||
setAttributeIfValue(element, "src", getData(element, settings.data_src));
|
||||
};
|
||||
|
||||
var setSourcesVideo = function setSourcesVideo(element, settings) {
|
||||
var sourceTags = getSourceTags(element);
|
||||
sourceTags.forEach(function (sourceTag) {
|
||||
setAttributeIfValue(sourceTag, "src", getData(sourceTag, settings.data_src));
|
||||
});
|
||||
setAttributeIfValue(element, "src", getData(element, settings.data_src));
|
||||
element.load();
|
||||
};
|
||||
|
||||
var setSourcesBgImage = function setSourcesBgImage(element, settings) {
|
||||
var srcDataValue = getData(element, settings.data_src);
|
||||
var bgDataValue = getData(element, settings.data_bg);
|
||||
|
||||
if (srcDataValue) {
|
||||
element.style.backgroundImage = "url(\"".concat(srcDataValue, "\")");
|
||||
}
|
||||
|
||||
if (bgDataValue) {
|
||||
element.style.backgroundImage = bgDataValue;
|
||||
}
|
||||
};
|
||||
|
||||
var setSourcesFunctions = {
|
||||
IMG: setSourcesImg,
|
||||
IFRAME: setSourcesIframe,
|
||||
VIDEO: setSourcesVideo
|
||||
};
|
||||
|
||||
var setSources = function setSources(element, instance) {
|
||||
var settings = instance._settings;
|
||||
var tagName = element.tagName;
|
||||
var setSourcesFunction = setSourcesFunctions[tagName];
|
||||
|
||||
if (setSourcesFunction) {
|
||||
setSourcesFunction(element, settings);
|
||||
updateLoadingCount(instance, 1);
|
||||
instance._elements = purgeOneElement(instance._elements, element);
|
||||
return;
|
||||
}
|
||||
|
||||
setSourcesBgImage(element, settings);
|
||||
};
|
||||
|
||||
var addClass = function addClass(element, className) {
|
||||
if (supportsClassList) {
|
||||
element.classList.add(className);
|
||||
return;
|
||||
}
|
||||
|
||||
element.className += (element.className ? " " : "") + className;
|
||||
};
|
||||
|
||||
var removeClass = function removeClass(element, className) {
|
||||
if (supportsClassList) {
|
||||
element.classList.remove(className);
|
||||
return;
|
||||
}
|
||||
|
||||
element.className = element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), " ").replace(/^\s+/, "").replace(/\s+$/, "");
|
||||
};
|
||||
|
||||
var genericLoadEventName = "load";
|
||||
var mediaLoadEventName = "loadeddata";
|
||||
var errorEventName = "error";
|
||||
|
||||
var addEventListener = function addEventListener(element, eventName, handler) {
|
||||
element.addEventListener(eventName, handler);
|
||||
};
|
||||
|
||||
var removeEventListener = function removeEventListener(element, eventName, handler) {
|
||||
element.removeEventListener(eventName, handler);
|
||||
};
|
||||
|
||||
var addEventListeners = function addEventListeners(element, loadHandler, errorHandler) {
|
||||
addEventListener(element, genericLoadEventName, loadHandler);
|
||||
addEventListener(element, mediaLoadEventName, loadHandler);
|
||||
addEventListener(element, errorEventName, errorHandler);
|
||||
};
|
||||
|
||||
var removeEventListeners = function removeEventListeners(element, loadHandler, errorHandler) {
|
||||
removeEventListener(element, genericLoadEventName, loadHandler);
|
||||
removeEventListener(element, mediaLoadEventName, loadHandler);
|
||||
removeEventListener(element, errorEventName, errorHandler);
|
||||
};
|
||||
|
||||
var eventHandler = function eventHandler(event, success, instance) {
|
||||
var settings = instance._settings;
|
||||
var className = success ? settings.class_loaded : settings.class_error;
|
||||
var callback = success ? settings.callback_loaded : settings.callback_error;
|
||||
var element = event.target;
|
||||
removeClass(element, settings.class_loading);
|
||||
addClass(element, className);
|
||||
callbackIfSet(callback, element);
|
||||
updateLoadingCount(instance, -1);
|
||||
};
|
||||
|
||||
var addOneShotEventListeners = function addOneShotEventListeners(element, instance) {
|
||||
var loadHandler = function loadHandler(event) {
|
||||
eventHandler(event, true, instance);
|
||||
removeEventListeners(element, loadHandler, errorHandler);
|
||||
};
|
||||
|
||||
var errorHandler = function errorHandler(event) {
|
||||
eventHandler(event, false, instance);
|
||||
removeEventListeners(element, loadHandler, errorHandler);
|
||||
};
|
||||
|
||||
addEventListeners(element, loadHandler, errorHandler);
|
||||
};
|
||||
|
||||
var managedTags = ["IMG", "IFRAME", "VIDEO"];
|
||||
|
||||
var onEnter = function onEnter(element, instance) {
|
||||
var settings = instance._settings;
|
||||
callbackIfSet(settings.callback_enter, element);
|
||||
|
||||
if (!settings.load_delay) {
|
||||
revealAndUnobserve(element, instance);
|
||||
return;
|
||||
}
|
||||
|
||||
delayLoad(element, instance);
|
||||
};
|
||||
|
||||
var revealAndUnobserve = function revealAndUnobserve(element, instance) {
|
||||
var observer = instance._observer;
|
||||
revealElement(element, instance);
|
||||
|
||||
if (observer && instance._settings.auto_unobserve) {
|
||||
observer.unobserve(element);
|
||||
}
|
||||
};
|
||||
|
||||
var onExit = function onExit(element, instance) {
|
||||
var settings = instance._settings;
|
||||
callbackIfSet(settings.callback_exit, element);
|
||||
|
||||
if (!settings.load_delay) {
|
||||
return;
|
||||
}
|
||||
|
||||
cancelDelayLoad(element);
|
||||
};
|
||||
|
||||
var cancelDelayLoad = function cancelDelayLoad(element) {
|
||||
var timeoutId = getTimeoutData(element);
|
||||
|
||||
if (!timeoutId) {
|
||||
return; // do nothing if timeout doesn't exist
|
||||
}
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
setTimeoutData(element, null);
|
||||
};
|
||||
|
||||
var delayLoad = function delayLoad(element, instance) {
|
||||
var loadDelay = instance._settings.load_delay;
|
||||
var timeoutId = getTimeoutData(element);
|
||||
|
||||
if (timeoutId) {
|
||||
return; // do nothing if timeout already set
|
||||
}
|
||||
|
||||
timeoutId = setTimeout(function () {
|
||||
revealAndUnobserve(element, instance);
|
||||
cancelDelayLoad(element);
|
||||
}, loadDelay);
|
||||
setTimeoutData(element, timeoutId);
|
||||
};
|
||||
|
||||
var revealElement = function revealElement(element, instance, force) {
|
||||
var settings = instance._settings;
|
||||
|
||||
if (!force && getWasProcessedData(element)) {
|
||||
return; // element has already been processed and force wasn't true
|
||||
}
|
||||
|
||||
if (managedTags.indexOf(element.tagName) > -1) {
|
||||
addOneShotEventListeners(element, instance);
|
||||
addClass(element, settings.class_loading);
|
||||
}
|
||||
|
||||
setSources(element, instance);
|
||||
setWasProcessedData(element);
|
||||
callbackIfSet(settings.callback_reveal, element);
|
||||
callbackIfSet(settings.callback_set, element);
|
||||
};
|
||||
|
||||
var isIntersecting = function isIntersecting(entry) {
|
||||
return entry.isIntersecting || entry.intersectionRatio > 0;
|
||||
};
|
||||
|
||||
var getObserverSettings = function getObserverSettings(settings) {
|
||||
return {
|
||||
root: settings.container === document ? null : settings.container,
|
||||
rootMargin: settings.thresholds || settings.threshold + "px"
|
||||
};
|
||||
};
|
||||
|
||||
var setObserver = function setObserver(instance) {
|
||||
if (!supportsIntersectionObserver) {
|
||||
return false;
|
||||
}
|
||||
|
||||
instance._observer = new IntersectionObserver(function (entries) {
|
||||
entries.forEach(function (entry) {
|
||||
return isIntersecting(entry) ? onEnter(entry.target, instance) : onExit(entry.target, instance);
|
||||
});
|
||||
}, getObserverSettings(instance._settings));
|
||||
return true;
|
||||
};
|
||||
|
||||
var LazyLoad = function LazyLoad(customSettings, elements) {
|
||||
this._settings = getInstanceSettings(customSettings);
|
||||
this._loadingCount = 0;
|
||||
setObserver(this);
|
||||
this.update(elements);
|
||||
};
|
||||
|
||||
LazyLoad.prototype = {
|
||||
update: function update(elements) {
|
||||
var _this = this;
|
||||
|
||||
var settings = this._settings;
|
||||
|
||||
var _elements = elements || settings.container.querySelectorAll(settings.elements_selector);
|
||||
|
||||
this._elements = purgeProcessedElements(Array.prototype.slice.call(_elements) // NOTE: nodeset to array for IE compatibility
|
||||
);
|
||||
|
||||
if (isBot || !this._observer) {
|
||||
this.loadAll();
|
||||
return;
|
||||
}
|
||||
|
||||
this._elements.forEach(function (element) {
|
||||
_this._observer.observe(element);
|
||||
});
|
||||
},
|
||||
destroy: function destroy() {
|
||||
var _this2 = this;
|
||||
|
||||
if (this._observer) {
|
||||
this._elements.forEach(function (element) {
|
||||
_this2._observer.unobserve(element);
|
||||
});
|
||||
|
||||
this._observer = null;
|
||||
}
|
||||
|
||||
this._elements = null;
|
||||
this._settings = null;
|
||||
},
|
||||
load: function load(element, force) {
|
||||
revealElement(element, this, force);
|
||||
},
|
||||
loadAll: function loadAll() {
|
||||
var _this3 = this;
|
||||
|
||||
var elements = this._elements;
|
||||
elements.forEach(function (element) {
|
||||
revealAndUnobserve(element, _this3);
|
||||
});
|
||||
}
|
||||
};
|
||||
/* Automatic instances creation if required (useful for async script loading) */
|
||||
|
||||
if (runningOnBrowser) {
|
||||
autoInitialize(LazyLoad, window.lazyLoadOptions);
|
||||
}
|
||||
|
||||
return LazyLoad;
|
||||
});
|
2
wp-content/plugins/wp-rocket/assets/js/lazyload/11.0.6/lazyload.min.js
vendored
Normal file
2
wp-content/plugins/wp-rocket/assets/js/lazyload/11.0.6/lazyload.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
491
wp-content/plugins/wp-rocket/assets/js/lazyload/12.0/lazyload.js
Normal file
491
wp-content/plugins/wp-rocket/assets/js/lazyload/12.0/lazyload.js
Normal file
@@ -0,0 +1,491 @@
|
||||
function _extends() { _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; }; return _extends.apply(this, arguments); }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
(function (global, factory) {
|
||||
(typeof exports === "undefined" ? "undefined" : _typeof(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : global.LazyLoad = factory();
|
||||
})(this, function () {
|
||||
'use strict';
|
||||
|
||||
var runningOnBrowser = typeof window !== "undefined";
|
||||
var isBot = runningOnBrowser && !("onscroll" in window) || typeof navigator !== "undefined" && /(gle|ing|ro)bot|crawl|spider/i.test(navigator.userAgent);
|
||||
var supportsIntersectionObserver = runningOnBrowser && "IntersectionObserver" in window;
|
||||
var supportsClassList = runningOnBrowser && "classList" in document.createElement("p");
|
||||
var defaultSettings = {
|
||||
elements_selector: "img",
|
||||
container: isBot || runningOnBrowser ? document : null,
|
||||
threshold: 300,
|
||||
thresholds: null,
|
||||
data_src: "src",
|
||||
data_srcset: "srcset",
|
||||
data_sizes: "sizes",
|
||||
data_bg: "bg",
|
||||
class_loading: "loading",
|
||||
class_loaded: "loaded",
|
||||
class_error: "error",
|
||||
load_delay: 0,
|
||||
auto_unobserve: true,
|
||||
callback_enter: null,
|
||||
callback_exit: null,
|
||||
callback_reveal: null,
|
||||
callback_loaded: null,
|
||||
callback_error: null,
|
||||
callback_finish: null,
|
||||
use_native: false
|
||||
};
|
||||
|
||||
var getInstanceSettings = function getInstanceSettings(customSettings) {
|
||||
return _extends({}, defaultSettings, customSettings);
|
||||
};
|
||||
/* Creates instance and notifies it through the window element */
|
||||
|
||||
|
||||
var createInstance = function createInstance(classObj, options) {
|
||||
var event;
|
||||
var eventString = "LazyLoad::Initialized";
|
||||
var instance = new classObj(options);
|
||||
|
||||
try {
|
||||
// Works in modern browsers
|
||||
event = new CustomEvent(eventString, {
|
||||
detail: {
|
||||
instance: instance
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
// Works in Internet Explorer (all versions)
|
||||
event = document.createEvent("CustomEvent");
|
||||
event.initCustomEvent(eventString, false, false, {
|
||||
instance: instance
|
||||
});
|
||||
}
|
||||
|
||||
window.dispatchEvent(event);
|
||||
};
|
||||
/* Auto initialization of one or more instances of lazyload, depending on the
|
||||
options passed in (plain object or an array) */
|
||||
|
||||
|
||||
function autoInitialize(classObj, options) {
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!options.length) {
|
||||
// Plain object
|
||||
createInstance(classObj, options);
|
||||
} else {
|
||||
// Array of objects
|
||||
for (var i = 0, optionsItem; optionsItem = options[i]; i += 1) {
|
||||
createInstance(classObj, optionsItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var dataPrefix = "data-";
|
||||
var processedDataName = "was-processed";
|
||||
var timeoutDataName = "ll-timeout";
|
||||
var trueString = "true";
|
||||
|
||||
var getData = function getData(element, attribute) {
|
||||
return element.getAttribute(dataPrefix + attribute);
|
||||
};
|
||||
|
||||
var setData = function setData(element, attribute, value) {
|
||||
var attrName = dataPrefix + attribute;
|
||||
|
||||
if (value === null) {
|
||||
element.removeAttribute(attrName);
|
||||
return;
|
||||
}
|
||||
|
||||
element.setAttribute(attrName, value);
|
||||
};
|
||||
|
||||
var setWasProcessedData = function setWasProcessedData(element) {
|
||||
return setData(element, processedDataName, trueString);
|
||||
};
|
||||
|
||||
var getWasProcessedData = function getWasProcessedData(element) {
|
||||
return getData(element, processedDataName) === trueString;
|
||||
};
|
||||
|
||||
var setTimeoutData = function setTimeoutData(element, value) {
|
||||
return setData(element, timeoutDataName, value);
|
||||
};
|
||||
|
||||
var getTimeoutData = function getTimeoutData(element) {
|
||||
return getData(element, timeoutDataName);
|
||||
};
|
||||
|
||||
var purgeProcessedElements = function purgeProcessedElements(elements) {
|
||||
return elements.filter(function (element) {
|
||||
return !getWasProcessedData(element);
|
||||
});
|
||||
};
|
||||
|
||||
var purgeOneElement = function purgeOneElement(elements, elementToPurge) {
|
||||
return elements.filter(function (element) {
|
||||
return element !== elementToPurge;
|
||||
});
|
||||
};
|
||||
|
||||
var callbackIfSet = function callbackIfSet(callback, argument) {
|
||||
if (callback) {
|
||||
callback(argument);
|
||||
}
|
||||
};
|
||||
|
||||
var updateLoadingCount = function updateLoadingCount(instance, plusMinus) {
|
||||
instance._loadingCount += plusMinus;
|
||||
|
||||
if (instance._elements.length === 0 && instance._loadingCount === 0) {
|
||||
callbackIfSet(instance._settings.callback_finish);
|
||||
}
|
||||
};
|
||||
|
||||
var getSourceTags = function getSourceTags(parentTag) {
|
||||
var sourceTags = [];
|
||||
|
||||
for (var i = 0, childTag; childTag = parentTag.children[i]; i += 1) {
|
||||
if (childTag.tagName === "SOURCE") {
|
||||
sourceTags.push(childTag);
|
||||
}
|
||||
}
|
||||
|
||||
return sourceTags;
|
||||
};
|
||||
|
||||
var setAttributeIfValue = function setAttributeIfValue(element, attrName, value) {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
element.setAttribute(attrName, value);
|
||||
};
|
||||
|
||||
var setImageAttributes = function setImageAttributes(element, settings) {
|
||||
setAttributeIfValue(element, "sizes", getData(element, settings.data_sizes));
|
||||
setAttributeIfValue(element, "srcset", getData(element, settings.data_srcset));
|
||||
setAttributeIfValue(element, "src", getData(element, settings.data_src));
|
||||
};
|
||||
|
||||
var setSourcesImg = function setSourcesImg(element, settings) {
|
||||
var parent = element.parentNode;
|
||||
|
||||
if (parent && parent.tagName === "PICTURE") {
|
||||
var sourceTags = getSourceTags(parent);
|
||||
sourceTags.forEach(function (sourceTag) {
|
||||
setImageAttributes(sourceTag, settings);
|
||||
});
|
||||
}
|
||||
|
||||
setImageAttributes(element, settings);
|
||||
};
|
||||
|
||||
var setSourcesIframe = function setSourcesIframe(element, settings) {
|
||||
setAttributeIfValue(element, "src", getData(element, settings.data_src));
|
||||
};
|
||||
|
||||
var setSourcesVideo = function setSourcesVideo(element, settings) {
|
||||
var sourceTags = getSourceTags(element);
|
||||
sourceTags.forEach(function (sourceTag) {
|
||||
setAttributeIfValue(sourceTag, "src", getData(sourceTag, settings.data_src));
|
||||
});
|
||||
setAttributeIfValue(element, "src", getData(element, settings.data_src));
|
||||
element.load();
|
||||
};
|
||||
|
||||
var setSourcesBgImage = function setSourcesBgImage(element, settings) {
|
||||
var srcDataValue = getData(element, settings.data_src);
|
||||
var bgDataValue = getData(element, settings.data_bg);
|
||||
|
||||
if (srcDataValue) {
|
||||
element.style.backgroundImage = "url(\"".concat(srcDataValue, "\")");
|
||||
}
|
||||
|
||||
if (bgDataValue) {
|
||||
element.style.backgroundImage = bgDataValue;
|
||||
}
|
||||
};
|
||||
|
||||
var setSourcesFunctions = {
|
||||
IMG: setSourcesImg,
|
||||
IFRAME: setSourcesIframe,
|
||||
VIDEO: setSourcesVideo
|
||||
};
|
||||
|
||||
var setSources = function setSources(element, instance) {
|
||||
var settings = instance._settings;
|
||||
var tagName = element.tagName;
|
||||
var setSourcesFunction = setSourcesFunctions[tagName];
|
||||
|
||||
if (setSourcesFunction) {
|
||||
setSourcesFunction(element, settings);
|
||||
updateLoadingCount(instance, 1);
|
||||
instance._elements = purgeOneElement(instance._elements, element);
|
||||
return;
|
||||
}
|
||||
|
||||
setSourcesBgImage(element, settings);
|
||||
};
|
||||
|
||||
var addClass = function addClass(element, className) {
|
||||
if (supportsClassList) {
|
||||
element.classList.add(className);
|
||||
return;
|
||||
}
|
||||
|
||||
element.className += (element.className ? " " : "") + className;
|
||||
};
|
||||
|
||||
var removeClass = function removeClass(element, className) {
|
||||
if (supportsClassList) {
|
||||
element.classList.remove(className);
|
||||
return;
|
||||
}
|
||||
|
||||
element.className = element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), " ").replace(/^\s+/, "").replace(/\s+$/, "");
|
||||
};
|
||||
|
||||
var genericLoadEventName = "load";
|
||||
var mediaLoadEventName = "loadeddata";
|
||||
var errorEventName = "error";
|
||||
|
||||
var addEventListener = function addEventListener(element, eventName, handler) {
|
||||
element.addEventListener(eventName, handler);
|
||||
};
|
||||
|
||||
var removeEventListener = function removeEventListener(element, eventName, handler) {
|
||||
element.removeEventListener(eventName, handler);
|
||||
};
|
||||
|
||||
var addEventListeners = function addEventListeners(element, loadHandler, errorHandler) {
|
||||
addEventListener(element, genericLoadEventName, loadHandler);
|
||||
addEventListener(element, mediaLoadEventName, loadHandler);
|
||||
addEventListener(element, errorEventName, errorHandler);
|
||||
};
|
||||
|
||||
var removeEventListeners = function removeEventListeners(element, loadHandler, errorHandler) {
|
||||
removeEventListener(element, genericLoadEventName, loadHandler);
|
||||
removeEventListener(element, mediaLoadEventName, loadHandler);
|
||||
removeEventListener(element, errorEventName, errorHandler);
|
||||
};
|
||||
|
||||
var eventHandler = function eventHandler(event, success, instance) {
|
||||
var settings = instance._settings;
|
||||
var className = success ? settings.class_loaded : settings.class_error;
|
||||
var callback = success ? settings.callback_loaded : settings.callback_error;
|
||||
var element = event.target;
|
||||
removeClass(element, settings.class_loading);
|
||||
addClass(element, className);
|
||||
callbackIfSet(callback, element);
|
||||
updateLoadingCount(instance, -1);
|
||||
};
|
||||
|
||||
var addOneShotEventListeners = function addOneShotEventListeners(element, instance) {
|
||||
var loadHandler = function loadHandler(event) {
|
||||
eventHandler(event, true, instance);
|
||||
removeEventListeners(element, loadHandler, errorHandler);
|
||||
};
|
||||
|
||||
var errorHandler = function errorHandler(event) {
|
||||
eventHandler(event, false, instance);
|
||||
removeEventListeners(element, loadHandler, errorHandler);
|
||||
};
|
||||
|
||||
addEventListeners(element, loadHandler, errorHandler);
|
||||
};
|
||||
|
||||
var managedTags = ["IMG", "IFRAME", "VIDEO"];
|
||||
|
||||
var onEnter = function onEnter(element, instance) {
|
||||
var settings = instance._settings;
|
||||
callbackIfSet(settings.callback_enter, element);
|
||||
|
||||
if (!settings.load_delay) {
|
||||
revealAndUnobserve(element, instance);
|
||||
return;
|
||||
}
|
||||
|
||||
delayLoad(element, instance);
|
||||
};
|
||||
|
||||
var revealAndUnobserve = function revealAndUnobserve(element, instance) {
|
||||
var observer = instance._observer;
|
||||
revealElement(element, instance);
|
||||
|
||||
if (observer && instance._settings.auto_unobserve) {
|
||||
observer.unobserve(element);
|
||||
}
|
||||
};
|
||||
|
||||
var onExit = function onExit(element, instance) {
|
||||
var settings = instance._settings;
|
||||
callbackIfSet(settings.callback_exit, element);
|
||||
|
||||
if (!settings.load_delay) {
|
||||
return;
|
||||
}
|
||||
|
||||
cancelDelayLoad(element);
|
||||
};
|
||||
|
||||
var cancelDelayLoad = function cancelDelayLoad(element) {
|
||||
var timeoutId = getTimeoutData(element);
|
||||
|
||||
if (!timeoutId) {
|
||||
return; // do nothing if timeout doesn't exist
|
||||
}
|
||||
|
||||
clearTimeout(timeoutId);
|
||||
setTimeoutData(element, null);
|
||||
};
|
||||
|
||||
var delayLoad = function delayLoad(element, instance) {
|
||||
var loadDelay = instance._settings.load_delay;
|
||||
var timeoutId = getTimeoutData(element);
|
||||
|
||||
if (timeoutId) {
|
||||
return; // do nothing if timeout already set
|
||||
}
|
||||
|
||||
timeoutId = setTimeout(function () {
|
||||
revealAndUnobserve(element, instance);
|
||||
cancelDelayLoad(element);
|
||||
}, loadDelay);
|
||||
setTimeoutData(element, timeoutId);
|
||||
};
|
||||
|
||||
var revealElement = function revealElement(element, instance, force) {
|
||||
var settings = instance._settings;
|
||||
|
||||
if (!force && getWasProcessedData(element)) {
|
||||
return; // element has already been processed and force wasn't true
|
||||
}
|
||||
|
||||
if (managedTags.indexOf(element.tagName) > -1) {
|
||||
addOneShotEventListeners(element, instance);
|
||||
addClass(element, settings.class_loading);
|
||||
}
|
||||
|
||||
setSources(element, instance);
|
||||
setWasProcessedData(element);
|
||||
callbackIfSet(settings.callback_reveal, element);
|
||||
callbackIfSet(settings.callback_set, element);
|
||||
};
|
||||
|
||||
var isIntersecting = function isIntersecting(entry) {
|
||||
return entry.isIntersecting || entry.intersectionRatio > 0;
|
||||
};
|
||||
|
||||
var getObserverSettings = function getObserverSettings(settings) {
|
||||
return {
|
||||
root: settings.container === document ? null : settings.container,
|
||||
rootMargin: settings.thresholds || settings.threshold + "px"
|
||||
};
|
||||
};
|
||||
|
||||
var setObserver = function setObserver(instance) {
|
||||
if (!supportsIntersectionObserver) {
|
||||
return false;
|
||||
}
|
||||
|
||||
instance._observer = new IntersectionObserver(function (entries) {
|
||||
entries.forEach(function (entry) {
|
||||
return isIntersecting(entry) ? onEnter(entry.target, instance) : onExit(entry.target, instance);
|
||||
});
|
||||
}, getObserverSettings(instance._settings));
|
||||
return true;
|
||||
};
|
||||
|
||||
var nativeLazyTags = ["IMG", "IFRAME"];
|
||||
|
||||
var shouldUseNative = function shouldUseNative(settings) {
|
||||
return settings.use_native && "loading" in HTMLImageElement.prototype;
|
||||
};
|
||||
|
||||
var loadAllNative = function loadAllNative(instance) {
|
||||
instance._elements.forEach(function (element) {
|
||||
if (nativeLazyTags.indexOf(element.tagName) === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
element.setAttribute("loading", "lazy");
|
||||
revealElement(element, instance);
|
||||
});
|
||||
};
|
||||
|
||||
var nodeSetToArray = function nodeSetToArray(nodeSet) {
|
||||
return Array.prototype.slice.call(nodeSet);
|
||||
};
|
||||
|
||||
var queryElements = function queryElements(settings) {
|
||||
return settings.container.querySelectorAll(settings.elements_selector);
|
||||
};
|
||||
|
||||
var getElements = function getElements(elements, settings) {
|
||||
return purgeProcessedElements(nodeSetToArray(elements || queryElements(settings)));
|
||||
};
|
||||
|
||||
var LazyLoad = function LazyLoad(customSettings, elements) {
|
||||
this._settings = getInstanceSettings(customSettings);
|
||||
this._loadingCount = 0;
|
||||
setObserver(this);
|
||||
this.update(elements);
|
||||
};
|
||||
|
||||
LazyLoad.prototype = {
|
||||
update: function update(elements) {
|
||||
var _this = this;
|
||||
|
||||
var settings = this._settings;
|
||||
this._elements = getElements(elements, settings);
|
||||
|
||||
if (isBot || !this._observer) {
|
||||
this.loadAll();
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldUseNative(settings)) {
|
||||
loadAllNative(this);
|
||||
this._elements = getElements(elements, settings);
|
||||
}
|
||||
|
||||
this._elements.forEach(function (element) {
|
||||
_this._observer.observe(element);
|
||||
});
|
||||
},
|
||||
destroy: function destroy() {
|
||||
var _this2 = this;
|
||||
|
||||
if (this._observer) {
|
||||
this._elements.forEach(function (element) {
|
||||
_this2._observer.unobserve(element);
|
||||
});
|
||||
|
||||
this._observer = null;
|
||||
}
|
||||
|
||||
this._elements = null;
|
||||
this._settings = null;
|
||||
},
|
||||
load: function load(element, force) {
|
||||
revealElement(element, this, force);
|
||||
},
|
||||
loadAll: function loadAll() {
|
||||
var _this3 = this;
|
||||
|
||||
this._elements.forEach(function (element) {
|
||||
revealAndUnobserve(element, _this3);
|
||||
});
|
||||
}
|
||||
};
|
||||
/* Automatic instances creation if required (useful for async script loading) */
|
||||
|
||||
if (runningOnBrowser) {
|
||||
autoInitialize(LazyLoad, window.lazyLoadOptions);
|
||||
}
|
||||
|
||||
return LazyLoad;
|
||||
});
|
2
wp-content/plugins/wp-rocket/assets/js/lazyload/12.0/lazyload.min.js
vendored
Normal file
2
wp-content/plugins/wp-rocket/assets/js/lazyload/12.0/lazyload.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
733
wp-content/plugins/wp-rocket/assets/js/lazyload/16.1/lazyload.js
Normal file
733
wp-content/plugins/wp-rocket/assets/js/lazyload/16.1/lazyload.js
Normal file
@@ -0,0 +1,733 @@
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.LazyLoad = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
function _extends() {
|
||||
_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;
|
||||
};
|
||||
|
||||
return _extends.apply(this, arguments);
|
||||
}
|
||||
|
||||
var runningOnBrowser = typeof window !== "undefined";
|
||||
var isBot = runningOnBrowser && !("onscroll" in window) || typeof navigator !== "undefined" && /(gle|ing|ro)bot|crawl|spider/i.test(navigator.userAgent);
|
||||
var supportsIntersectionObserver = runningOnBrowser && "IntersectionObserver" in window;
|
||||
var supportsClassList = runningOnBrowser && "classList" in document.createElement("p");
|
||||
var isHiDpi = runningOnBrowser && window.devicePixelRatio > 1;
|
||||
|
||||
var defaultSettings = {
|
||||
elements_selector: "IMG",
|
||||
container: isBot || runningOnBrowser ? document : null,
|
||||
threshold: 300,
|
||||
thresholds: null,
|
||||
data_src: "src",
|
||||
data_srcset: "srcset",
|
||||
data_sizes: "sizes",
|
||||
data_bg: "bg",
|
||||
data_bg_hidpi: "bg-hidpi",
|
||||
data_bg_multi: "bg-multi",
|
||||
data_bg_multi_hidpi: "bg-multi-hidpi",
|
||||
data_poster: "poster",
|
||||
class_applied: "applied",
|
||||
class_loading: "loading",
|
||||
class_loaded: "loaded",
|
||||
class_error: "error",
|
||||
unobserve_completed: true,
|
||||
unobserve_entered: false,
|
||||
cancel_on_exit: false,
|
||||
callback_enter: null,
|
||||
callback_exit: null,
|
||||
callback_applied: null,
|
||||
callback_loading: null,
|
||||
callback_loaded: null,
|
||||
callback_error: null,
|
||||
callback_finish: null,
|
||||
callback_cancel: null,
|
||||
use_native: false
|
||||
};
|
||||
var getExtendedSettings = function getExtendedSettings(customSettings) {
|
||||
return _extends({}, defaultSettings, customSettings);
|
||||
};
|
||||
|
||||
/* Creates instance and notifies it through the window element */
|
||||
var createInstance = function createInstance(classObj, options) {
|
||||
var event;
|
||||
var eventString = "LazyLoad::Initialized";
|
||||
var instance = new classObj(options);
|
||||
|
||||
try {
|
||||
// Works in modern browsers
|
||||
event = new CustomEvent(eventString, {
|
||||
detail: {
|
||||
instance: instance
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
// Works in Internet Explorer (all versions)
|
||||
event = document.createEvent("CustomEvent");
|
||||
event.initCustomEvent(eventString, false, false, {
|
||||
instance: instance
|
||||
});
|
||||
}
|
||||
|
||||
window.dispatchEvent(event);
|
||||
};
|
||||
/* Auto initialization of one or more instances of lazyload, depending on the
|
||||
options passed in (plain object or an array) */
|
||||
|
||||
|
||||
var autoInitialize = function autoInitialize(classObj, options) {
|
||||
if (!options) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!options.length) {
|
||||
// Plain object
|
||||
createInstance(classObj, options);
|
||||
} else {
|
||||
// Array of objects
|
||||
for (var i = 0, optionsItem; optionsItem = options[i]; i += 1) {
|
||||
createInstance(classObj, optionsItem);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var statusLoading = "loading";
|
||||
var statusLoaded = "loaded";
|
||||
var statusApplied = "applied";
|
||||
var statusError = "error";
|
||||
var statusNative = "native";
|
||||
|
||||
var dataPrefix = "data-";
|
||||
var statusDataName = "ll-status";
|
||||
var getData = function getData(element, attribute) {
|
||||
return element.getAttribute(dataPrefix + attribute);
|
||||
};
|
||||
var setData = function setData(element, attribute, value) {
|
||||
var attrName = dataPrefix + attribute;
|
||||
|
||||
if (value === null) {
|
||||
element.removeAttribute(attrName);
|
||||
return;
|
||||
}
|
||||
|
||||
element.setAttribute(attrName, value);
|
||||
};
|
||||
var getStatus = function getStatus(element) {
|
||||
return getData(element, statusDataName);
|
||||
};
|
||||
var setStatus = function setStatus(element, status) {
|
||||
return setData(element, statusDataName, status);
|
||||
};
|
||||
var resetStatus = function resetStatus(element) {
|
||||
return setStatus(element, null);
|
||||
};
|
||||
var hasEmptyStatus = function hasEmptyStatus(element) {
|
||||
return getStatus(element) === null;
|
||||
};
|
||||
var hasStatusLoading = function hasStatusLoading(element) {
|
||||
return getStatus(element) === statusLoading;
|
||||
};
|
||||
var hasStatusError = function hasStatusError(element) {
|
||||
return getStatus(element) === statusError;
|
||||
};
|
||||
var hasStatusNative = function hasStatusNative(element) {
|
||||
return getStatus(element) === statusNative;
|
||||
};
|
||||
var hadStartedLoading = function hadStartedLoading(element) {
|
||||
return !hasEmptyStatus(element);
|
||||
};
|
||||
|
||||
var safeCallback = function safeCallback(callback, arg1, arg2, arg3) {
|
||||
if (!callback) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg3 !== undefined) {
|
||||
callback(arg1, arg2, arg3);
|
||||
return;
|
||||
}
|
||||
|
||||
if (arg2 !== undefined) {
|
||||
callback(arg1, arg2);
|
||||
return;
|
||||
}
|
||||
|
||||
callback(arg1);
|
||||
};
|
||||
|
||||
var addClass = function addClass(element, className) {
|
||||
if (supportsClassList) {
|
||||
element.classList.add(className);
|
||||
return;
|
||||
}
|
||||
|
||||
element.className += (element.className ? " " : "") + className;
|
||||
};
|
||||
var removeClass = function removeClass(element, className) {
|
||||
if (supportsClassList) {
|
||||
element.classList.remove(className);
|
||||
return;
|
||||
}
|
||||
|
||||
element.className = element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), " ").replace(/^\s+/, "").replace(/\s+$/, "");
|
||||
};
|
||||
|
||||
var addTempImage = function addTempImage(element) {
|
||||
element.llTempImage = document.createElement("IMG");
|
||||
};
|
||||
var deleteTempImage = function deleteTempImage(element) {
|
||||
delete element.llTempImage;
|
||||
};
|
||||
var getTempImage = function getTempImage(element) {
|
||||
return element.llTempImage;
|
||||
};
|
||||
|
||||
var unobserve = function unobserve(element, instance) {
|
||||
if (!instance) return;
|
||||
var observer = instance._observer;
|
||||
if (!observer) return;
|
||||
observer.unobserve(element);
|
||||
};
|
||||
var resetObserver = function resetObserver(observer) {
|
||||
observer.disconnect();
|
||||
};
|
||||
var unobserveIfRequired = function unobserveIfRequired(element, settings, instance) {
|
||||
if (settings.unobserve_entered) unobserve(element, instance);
|
||||
};
|
||||
|
||||
var updateLoadingCount = function updateLoadingCount(instance, delta) {
|
||||
if (!instance) return;
|
||||
instance.loadingCount += delta;
|
||||
};
|
||||
var decreaseToLoadCount = function decreaseToLoadCount(instance) {
|
||||
if (!instance) return;
|
||||
instance.toLoadCount -= 1;
|
||||
};
|
||||
var setToLoadCount = function setToLoadCount(instance, value) {
|
||||
if (!instance) return;
|
||||
instance.toLoadCount = value;
|
||||
};
|
||||
var isSomethingLoading = function isSomethingLoading(instance) {
|
||||
return instance.loadingCount > 0;
|
||||
};
|
||||
var haveElementsToLoad = function haveElementsToLoad(instance) {
|
||||
return instance.toLoadCount > 0;
|
||||
};
|
||||
|
||||
var getSourceTags = function getSourceTags(parentTag) {
|
||||
var sourceTags = [];
|
||||
|
||||
for (var i = 0, childTag; childTag = parentTag.children[i]; i += 1) {
|
||||
if (childTag.tagName === "SOURCE") {
|
||||
sourceTags.push(childTag);
|
||||
}
|
||||
}
|
||||
|
||||
return sourceTags;
|
||||
};
|
||||
var setAttributeIfValue = function setAttributeIfValue(element, attrName, value) {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
|
||||
element.setAttribute(attrName, value);
|
||||
};
|
||||
var resetAttribute = function resetAttribute(element, attrName) {
|
||||
element.removeAttribute(attrName);
|
||||
};
|
||||
var hasOriginalAttributes = function hasOriginalAttributes(element) {
|
||||
return !!element.llOriginalAttrs;
|
||||
};
|
||||
var saveOriginalImageAttributes = function saveOriginalImageAttributes(element) {
|
||||
if (hasOriginalAttributes(element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var originalAttributes = {};
|
||||
originalAttributes["src"] = element.getAttribute("src");
|
||||
originalAttributes["srcset"] = element.getAttribute("srcset");
|
||||
originalAttributes["sizes"] = element.getAttribute("sizes");
|
||||
element.llOriginalAttrs = originalAttributes;
|
||||
};
|
||||
var restoreOriginalImageAttributes = function restoreOriginalImageAttributes(element) {
|
||||
if (!hasOriginalAttributes(element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var originalAttributes = element.llOriginalAttrs;
|
||||
setAttributeIfValue(element, "src", originalAttributes["src"]);
|
||||
setAttributeIfValue(element, "srcset", originalAttributes["srcset"]);
|
||||
setAttributeIfValue(element, "sizes", originalAttributes["sizes"]);
|
||||
};
|
||||
var setImageAttributes = function setImageAttributes(element, settings) {
|
||||
setAttributeIfValue(element, "sizes", getData(element, settings.data_sizes));
|
||||
setAttributeIfValue(element, "srcset", getData(element, settings.data_srcset));
|
||||
setAttributeIfValue(element, "src", getData(element, settings.data_src));
|
||||
};
|
||||
var resetImageAttributes = function resetImageAttributes(element) {
|
||||
resetAttribute(element, "src");
|
||||
resetAttribute(element, "srcset");
|
||||
resetAttribute(element, "sizes");
|
||||
};
|
||||
var forEachPictureSource = function forEachPictureSource(element, fn) {
|
||||
var parent = element.parentNode;
|
||||
|
||||
if (!parent || parent.tagName !== "PICTURE") {
|
||||
return;
|
||||
}
|
||||
|
||||
var sourceTags = getSourceTags(parent);
|
||||
sourceTags.forEach(fn);
|
||||
};
|
||||
var forEachVideoSource = function forEachVideoSource(element, fn) {
|
||||
var sourceTags = getSourceTags(element);
|
||||
sourceTags.forEach(fn);
|
||||
};
|
||||
var restoreOriginalAttributesImg = function restoreOriginalAttributesImg(element) {
|
||||
forEachPictureSource(element, function (sourceTag) {
|
||||
restoreOriginalImageAttributes(sourceTag);
|
||||
});
|
||||
restoreOriginalImageAttributes(element);
|
||||
};
|
||||
var setSourcesImg = function setSourcesImg(element, settings) {
|
||||
forEachPictureSource(element, function (sourceTag) {
|
||||
saveOriginalImageAttributes(sourceTag);
|
||||
setImageAttributes(sourceTag, settings);
|
||||
});
|
||||
saveOriginalImageAttributes(element);
|
||||
setImageAttributes(element, settings);
|
||||
};
|
||||
var resetSourcesImg = function resetSourcesImg(element) {
|
||||
forEachPictureSource(element, function (sourceTag) {
|
||||
resetImageAttributes(sourceTag);
|
||||
});
|
||||
resetImageAttributes(element);
|
||||
};
|
||||
var setSourcesIframe = function setSourcesIframe(element, settings) {
|
||||
setAttributeIfValue(element, "src", getData(element, settings.data_src));
|
||||
};
|
||||
var setSourcesVideo = function setSourcesVideo(element, settings) {
|
||||
forEachVideoSource(element, function (sourceTag) {
|
||||
setAttributeIfValue(sourceTag, "src", getData(sourceTag, settings.data_src));
|
||||
});
|
||||
setAttributeIfValue(element, "poster", getData(element, settings.data_poster));
|
||||
setAttributeIfValue(element, "src", getData(element, settings.data_src));
|
||||
element.load();
|
||||
};
|
||||
var setSourcesFunctions = {
|
||||
IMG: setSourcesImg,
|
||||
IFRAME: setSourcesIframe,
|
||||
VIDEO: setSourcesVideo
|
||||
};
|
||||
var setBackground = function setBackground(element, settings, instance) {
|
||||
var bg1xValue = getData(element, settings.data_bg);
|
||||
var bgHiDpiValue = getData(element, settings.data_bg_hidpi);
|
||||
var bgDataValue = isHiDpi && bgHiDpiValue ? bgHiDpiValue : bg1xValue;
|
||||
if (!bgDataValue) return;
|
||||
element.style.backgroundImage = "url(\"".concat(bgDataValue, "\")");
|
||||
getTempImage(element).setAttribute("src", bgDataValue);
|
||||
manageLoading(element, settings, instance);
|
||||
}; // NOTE: THE TEMP IMAGE TRICK CANNOT BE DONE WITH data-multi-bg
|
||||
// BECAUSE INSIDE ITS VALUES MUST BE WRAPPED WITH URL() AND ONE OF THEM
|
||||
// COULD BE A GRADIENT BACKGROUND IMAGE
|
||||
|
||||
var setMultiBackground = function setMultiBackground(element, settings, instance) {
|
||||
var bg1xValue = getData(element, settings.data_bg_multi);
|
||||
var bgHiDpiValue = getData(element, settings.data_bg_multi_hidpi);
|
||||
var bgDataValue = isHiDpi && bgHiDpiValue ? bgHiDpiValue : bg1xValue;
|
||||
|
||||
if (!bgDataValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
element.style.backgroundImage = bgDataValue;
|
||||
manageApplied(element, settings, instance);
|
||||
};
|
||||
var setSources = function setSources(element, settings) {
|
||||
var setSourcesFunction = setSourcesFunctions[element.tagName];
|
||||
|
||||
if (!setSourcesFunction) {
|
||||
return;
|
||||
}
|
||||
|
||||
setSourcesFunction(element, settings);
|
||||
};
|
||||
var manageApplied = function manageApplied(element, settings, instance) {
|
||||
addClass(element, settings.class_applied);
|
||||
setStatus(element, statusApplied);
|
||||
removeDataMultiBackground(element, settings);
|
||||
|
||||
if (settings.unobserve_completed) {
|
||||
// Unobserve now because we can't do it on load
|
||||
unobserve(element, settings);
|
||||
}
|
||||
|
||||
safeCallback(settings.callback_applied, element, instance);
|
||||
};
|
||||
var manageLoading = function manageLoading(element, settings, instance) {
|
||||
updateLoadingCount(instance, +1);
|
||||
addClass(element, settings.class_loading);
|
||||
setStatus(element, statusLoading);
|
||||
safeCallback(settings.callback_loading, element, instance);
|
||||
}; // REMOVE DATA ATTRIBUTES --------------
|
||||
|
||||
var removeDataImg = function removeDataImg(element, settings) {
|
||||
setData(element, settings.data_src, null);
|
||||
setData(element, settings.data_srcset, null);
|
||||
setData(element, settings.data_sizes, null);
|
||||
forEachPictureSource(element, function (sourceTag) {
|
||||
setData(sourceTag, settings.data_srcset, null);
|
||||
setData(sourceTag, settings.data_sizes, null);
|
||||
});
|
||||
};
|
||||
var removeDataIframe = function removeDataIframe(element, settings) {
|
||||
setData(element, settings.data_src, null);
|
||||
};
|
||||
var removeDataVideo = function removeDataVideo(element, settings) {
|
||||
setData(element, settings.data_src, null);
|
||||
setData(element, settings.data_poster, null);
|
||||
forEachVideoSource(element, function (sourceTag) {
|
||||
setData(sourceTag, settings.data_src, null);
|
||||
});
|
||||
};
|
||||
var removeDataFunctions = {
|
||||
IMG: removeDataImg,
|
||||
IFRAME: removeDataIframe,
|
||||
VIDEO: removeDataVideo
|
||||
};
|
||||
var removeDataBackground = function removeDataBackground(element, settings) {
|
||||
setData(element, settings.data_bg, null);
|
||||
setData(element, settings.data_bg_hidpi, null);
|
||||
};
|
||||
var removeDataMultiBackground = function removeDataMultiBackground(element, settings) {
|
||||
setData(element, settings.data_bg_multi, null);
|
||||
setData(element, settings.data_bg_multi_hidpi, null);
|
||||
};
|
||||
var removeDataAttributes = function removeDataAttributes(element, settings) {
|
||||
var removeDataFunction = removeDataFunctions[element.tagName];
|
||||
|
||||
if (removeDataFunction) {
|
||||
removeDataFunction(element, settings);
|
||||
return;
|
||||
}
|
||||
|
||||
removeDataBackground(element, settings);
|
||||
};
|
||||
|
||||
var elementsWithLoadEvent = ["IMG", "IFRAME", "VIDEO"];
|
||||
var hasLoadEvent = function hasLoadEvent(element) {
|
||||
return elementsWithLoadEvent.indexOf(element.tagName) > -1;
|
||||
};
|
||||
var checkFinish = function checkFinish(settings, instance) {
|
||||
if (instance && !isSomethingLoading(instance) && !haveElementsToLoad(instance)) {
|
||||
safeCallback(settings.callback_finish, instance);
|
||||
}
|
||||
};
|
||||
var addEventListener = function addEventListener(element, eventName, handler) {
|
||||
element.addEventListener(eventName, handler);
|
||||
element.llEvLisnrs[eventName] = handler;
|
||||
};
|
||||
var removeEventListener = function removeEventListener(element, eventName, handler) {
|
||||
element.removeEventListener(eventName, handler);
|
||||
};
|
||||
var hasEventListeners = function hasEventListeners(element) {
|
||||
return !!element.llEvLisnrs;
|
||||
};
|
||||
var addEventListeners = function addEventListeners(element, loadHandler, errorHandler) {
|
||||
if (!hasEventListeners(element)) element.llEvLisnrs = {};
|
||||
var loadEventName = element.tagName === "VIDEO" ? "loadeddata" : "load";
|
||||
addEventListener(element, loadEventName, loadHandler);
|
||||
addEventListener(element, "error", errorHandler);
|
||||
};
|
||||
var removeEventListeners = function removeEventListeners(element) {
|
||||
if (!hasEventListeners(element)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var eventListeners = element.llEvLisnrs;
|
||||
|
||||
for (var eventName in eventListeners) {
|
||||
var handler = eventListeners[eventName];
|
||||
removeEventListener(element, eventName, handler);
|
||||
}
|
||||
|
||||
delete element.llEvLisnrs;
|
||||
};
|
||||
var doneHandler = function doneHandler(element, settings, instance) {
|
||||
deleteTempImage(element);
|
||||
updateLoadingCount(instance, -1);
|
||||
decreaseToLoadCount(instance);
|
||||
removeClass(element, settings.class_loading);
|
||||
|
||||
if (settings.unobserve_completed) {
|
||||
unobserve(element, instance);
|
||||
}
|
||||
};
|
||||
var loadHandler = function loadHandler(event, element, settings, instance) {
|
||||
var goingNative = hasStatusNative(element);
|
||||
doneHandler(element, settings, instance);
|
||||
addClass(element, settings.class_loaded);
|
||||
setStatus(element, statusLoaded);
|
||||
removeDataAttributes(element, settings);
|
||||
safeCallback(settings.callback_loaded, element, instance);
|
||||
if (!goingNative) checkFinish(settings, instance);
|
||||
};
|
||||
var errorHandler = function errorHandler(event, element, settings, instance) {
|
||||
var goingNative = hasStatusNative(element);
|
||||
doneHandler(element, settings, instance);
|
||||
addClass(element, settings.class_error);
|
||||
setStatus(element, statusError);
|
||||
safeCallback(settings.callback_error, element, instance);
|
||||
if (!goingNative) checkFinish(settings, instance);
|
||||
};
|
||||
var addOneShotEventListeners = function addOneShotEventListeners(element, settings, instance) {
|
||||
var elementToListenTo = getTempImage(element) || element;
|
||||
|
||||
if (hasEventListeners(elementToListenTo)) {
|
||||
// This happens when loading is retried twice
|
||||
return;
|
||||
}
|
||||
|
||||
var _loadHandler = function _loadHandler(event) {
|
||||
loadHandler(event, element, settings, instance);
|
||||
removeEventListeners(elementToListenTo);
|
||||
};
|
||||
|
||||
var _errorHandler = function _errorHandler(event) {
|
||||
errorHandler(event, element, settings, instance);
|
||||
removeEventListeners(elementToListenTo);
|
||||
};
|
||||
|
||||
addEventListeners(elementToListenTo, _loadHandler, _errorHandler);
|
||||
};
|
||||
|
||||
var loadBackground = function loadBackground(element, settings, instance) {
|
||||
addTempImage(element);
|
||||
addOneShotEventListeners(element, settings, instance);
|
||||
setBackground(element, settings, instance);
|
||||
setMultiBackground(element, settings, instance);
|
||||
};
|
||||
|
||||
var loadRegular = function loadRegular(element, settings, instance) {
|
||||
addOneShotEventListeners(element, settings, instance);
|
||||
setSources(element, settings);
|
||||
manageLoading(element, settings, instance);
|
||||
};
|
||||
|
||||
var load = function load(element, settings, instance) {
|
||||
if (hasLoadEvent(element)) {
|
||||
loadRegular(element, settings, instance);
|
||||
} else {
|
||||
loadBackground(element, settings, instance);
|
||||
}
|
||||
};
|
||||
var loadNative = function loadNative(element, settings, instance) {
|
||||
addOneShotEventListeners(element, settings, instance);
|
||||
setSources(element, settings);
|
||||
removeDataAttributes(element, settings);
|
||||
setStatus(element, statusNative);
|
||||
};
|
||||
|
||||
var cancelLoadingIfRequired = function cancelLoadingIfRequired(element, entry, settings, instance) {
|
||||
if (!settings.cancel_on_exit) return;
|
||||
if (!hasStatusLoading(element)) return;
|
||||
if (element.tagName !== "IMG") return; //Works only on images
|
||||
|
||||
removeEventListeners(element);
|
||||
resetSourcesImg(element);
|
||||
restoreOriginalAttributesImg(element);
|
||||
removeClass(element, settings.class_loading);
|
||||
updateLoadingCount(instance, -1);
|
||||
resetStatus(element);
|
||||
safeCallback(settings.callback_cancel, element, entry, instance);
|
||||
};
|
||||
|
||||
var onEnter = function onEnter(element, entry, settings, instance) {
|
||||
safeCallback(settings.callback_enter, element, entry, instance);
|
||||
unobserveIfRequired(element, settings, instance);
|
||||
if (hadStartedLoading(element)) return; //Prevent loading it again
|
||||
|
||||
load(element, settings, instance);
|
||||
};
|
||||
var onExit = function onExit(element, entry, settings, instance) {
|
||||
if (hasEmptyStatus(element)) return; //Ignore the first pass, at landing
|
||||
|
||||
cancelLoadingIfRequired(element, entry, settings, instance);
|
||||
safeCallback(settings.callback_exit, element, entry, instance);
|
||||
};
|
||||
|
||||
var tagsWithNativeLazy = ["IMG", "IFRAME"];
|
||||
var shouldUseNative = function shouldUseNative(settings) {
|
||||
return settings.use_native && "loading" in HTMLImageElement.prototype;
|
||||
};
|
||||
var loadAllNative = function loadAllNative(elements, settings, instance) {
|
||||
elements.forEach(function (element) {
|
||||
if (tagsWithNativeLazy.indexOf(element.tagName) === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
element.setAttribute("loading", "lazy"); //TODO: Move inside the loadNative method
|
||||
|
||||
loadNative(element, settings, instance);
|
||||
});
|
||||
setToLoadCount(instance, 0);
|
||||
};
|
||||
|
||||
var isIntersecting = function isIntersecting(entry) {
|
||||
return entry.isIntersecting || entry.intersectionRatio > 0;
|
||||
};
|
||||
|
||||
var getObserverSettings = function getObserverSettings(settings) {
|
||||
return {
|
||||
root: settings.container === document ? null : settings.container,
|
||||
rootMargin: settings.thresholds || settings.threshold + "px"
|
||||
};
|
||||
};
|
||||
|
||||
var intersectionHandler = function intersectionHandler(entries, settings, instance) {
|
||||
entries.forEach(function (entry) {
|
||||
return isIntersecting(entry) ? onEnter(entry.target, entry, settings, instance) : onExit(entry.target, entry, settings, instance);
|
||||
});
|
||||
};
|
||||
|
||||
var observeElements = function observeElements(observer, elements) {
|
||||
elements.forEach(function (element) {
|
||||
observer.observe(element);
|
||||
});
|
||||
};
|
||||
var updateObserver = function updateObserver(observer, elementsToObserve) {
|
||||
resetObserver(observer);
|
||||
observeElements(observer, elementsToObserve);
|
||||
};
|
||||
var setObserver = function setObserver(settings, instance) {
|
||||
if (!supportsIntersectionObserver || shouldUseNative(settings)) {
|
||||
return;
|
||||
}
|
||||
|
||||
instance._observer = new IntersectionObserver(function (entries) {
|
||||
intersectionHandler(entries, settings, instance);
|
||||
}, getObserverSettings(settings));
|
||||
};
|
||||
|
||||
var toArray = function toArray(nodeSet) {
|
||||
return Array.prototype.slice.call(nodeSet);
|
||||
};
|
||||
var queryElements = function queryElements(settings) {
|
||||
return settings.container.querySelectorAll(settings.elements_selector);
|
||||
};
|
||||
var excludeManagedElements = function excludeManagedElements(elements) {
|
||||
return toArray(elements).filter(hasEmptyStatus);
|
||||
};
|
||||
var hasError = function hasError(element) {
|
||||
return hasStatusError(element);
|
||||
};
|
||||
var filterErrorElements = function filterErrorElements(elements) {
|
||||
return toArray(elements).filter(hasError);
|
||||
};
|
||||
var getElementsToLoad = function getElementsToLoad(elements, settings) {
|
||||
return excludeManagedElements(elements || queryElements(settings));
|
||||
};
|
||||
|
||||
var retryLazyLoad = function retryLazyLoad(settings, instance) {
|
||||
var errorElements = filterErrorElements(queryElements(settings));
|
||||
errorElements.forEach(function (element) {
|
||||
removeClass(element, settings.class_error);
|
||||
resetStatus(element);
|
||||
});
|
||||
instance.update();
|
||||
};
|
||||
var setOnlineCheck = function setOnlineCheck(settings, instance) {
|
||||
if (!runningOnBrowser) {
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener("online", function () {
|
||||
retryLazyLoad(settings, instance);
|
||||
});
|
||||
};
|
||||
|
||||
var LazyLoad = function LazyLoad(customSettings, elements) {
|
||||
var settings = getExtendedSettings(customSettings);
|
||||
this._settings = settings;
|
||||
this.loadingCount = 0;
|
||||
setObserver(settings, this);
|
||||
setOnlineCheck(settings, this);
|
||||
this.update(elements);
|
||||
};
|
||||
|
||||
LazyLoad.prototype = {
|
||||
update: function update(givenNodeset) {
|
||||
var settings = this._settings;
|
||||
var elementsToLoad = getElementsToLoad(givenNodeset, settings);
|
||||
setToLoadCount(this, elementsToLoad.length);
|
||||
|
||||
if (isBot || !supportsIntersectionObserver) {
|
||||
this.loadAll(elementsToLoad);
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldUseNative(settings)) {
|
||||
loadAllNative(elementsToLoad, settings, this);
|
||||
return;
|
||||
}
|
||||
|
||||
updateObserver(this._observer, elementsToLoad);
|
||||
},
|
||||
destroy: function destroy() {
|
||||
// Observer
|
||||
if (this._observer) {
|
||||
this._observer.disconnect();
|
||||
} // Clean custom attributes on elements
|
||||
|
||||
|
||||
queryElements(this._settings).forEach(function (element) {
|
||||
delete element.llOriginalAttrs;
|
||||
}); // Delete all internal props
|
||||
|
||||
delete this._observer;
|
||||
delete this._settings;
|
||||
delete this.loadingCount;
|
||||
delete this.toLoadCount;
|
||||
},
|
||||
loadAll: function loadAll(elements) {
|
||||
var _this = this;
|
||||
|
||||
var settings = this._settings;
|
||||
var elementsToLoad = getElementsToLoad(elements, settings);
|
||||
elementsToLoad.forEach(function (element) {
|
||||
load(element, settings, _this);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
LazyLoad.load = function (element, customSettings) {
|
||||
var settings = getExtendedSettings(customSettings);
|
||||
load(element, settings);
|
||||
};
|
||||
|
||||
LazyLoad.resetStatus = function (element) {
|
||||
resetStatus(element);
|
||||
}; // Automatic instances creation if required (useful for async script loading)
|
||||
|
||||
|
||||
if (runningOnBrowser) {
|
||||
autoInitialize(LazyLoad, window.lazyLoadOptions);
|
||||
}
|
||||
|
||||
return LazyLoad;
|
||||
|
||||
})));
|
1
wp-content/plugins/wp-rocket/assets/js/lazyload/16.1/lazyload.min.js
vendored
Normal file
1
wp-content/plugins/wp-rocket/assets/js/lazyload/16.1/lazyload.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
wp-content/plugins/wp-rocket/assets/js/micromodal.min.js
vendored
Normal file
1
wp-content/plugins/wp-rocket/assets/js/micromodal.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).MicroModal=t()}(this,function(){"use strict";return(()=>{const e=["a[href]","area[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',"select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","iframe","object","embed","[contenteditable]",'[tabindex]:not([tabindex^="-"])'];class t{constructor({targetModal:e,triggers:t=[],onShow:o=(()=>{}),onClose:i=(()=>{}),openTrigger:n="data-micromodal-trigger",closeTrigger:s="data-micromodal-close",disableScroll:a=!1,disableFocus:l=!1,awaitCloseAnimation:d=!1,awaitOpenAnimation:r=!1,debugMode:c=!1}){this.modal=document.getElementById(e),this.config={debugMode:c,disableScroll:a,openTrigger:n,closeTrigger:s,onShow:o,onClose:i,awaitCloseAnimation:d,awaitOpenAnimation:r,disableFocus:l},t.length>0&&this.registerTriggers(...t),this.onClick=this.onClick.bind(this),this.onKeydown=this.onKeydown.bind(this)}registerTriggers(...e){e.filter(Boolean).forEach(e=>{e.addEventListener("click",e=>this.showModal(e))})}showModal(){if(this.activeElement=document.activeElement,this.modal.setAttribute("aria-hidden","false"),this.modal.classList.add("is-open"),this.scrollBehaviour("disable"),this.addEventListeners(),this.config.awaitOpenAnimation){const e=()=>{this.modal.removeEventListener("animationend",e,!1),this.setFocusToFirstNode()};this.modal.addEventListener("animationend",e,!1)}else this.setFocusToFirstNode();this.config.onShow(this.modal,this.activeElement)}closeModal(){const e=this.modal;this.modal.setAttribute("aria-hidden","true"),this.removeEventListeners(),this.scrollBehaviour("enable"),this.activeElement&&this.activeElement.focus(),this.config.onClose(this.modal),this.config.awaitCloseAnimation?this.modal.addEventListener("animationend",function t(){e.classList.remove("is-open"),e.removeEventListener("animationend",t,!1)},!1):e.classList.remove("is-open")}closeModalById(e){this.modal=document.getElementById(e),this.modal&&this.closeModal()}scrollBehaviour(e){if(!this.config.disableScroll)return;const t=document.querySelector("body");switch(e){case"enable":Object.assign(t.style,{overflow:"",height:""});break;case"disable":Object.assign(t.style,{overflow:"hidden",height:"100vh"})}}addEventListeners(){this.modal.addEventListener("touchstart",this.onClick),this.modal.addEventListener("click",this.onClick),document.addEventListener("keydown",this.onKeydown)}removeEventListeners(){this.modal.removeEventListener("touchstart",this.onClick),this.modal.removeEventListener("click",this.onClick),document.removeEventListener("keydown",this.onKeydown)}onClick(e){e.target.hasAttribute(this.config.closeTrigger)&&(this.closeModal(),e.preventDefault())}onKeydown(e){27===e.keyCode&&this.closeModal(e),9===e.keyCode&&this.maintainFocus(e)}getFocusableNodes(){const t=this.modal.querySelectorAll(e);return Array(...t)}setFocusToFirstNode(){if(this.config.disableFocus)return;const e=this.getFocusableNodes();e.length&&e[0].focus()}maintainFocus(e){const t=this.getFocusableNodes();if(this.modal.contains(document.activeElement)){const o=t.indexOf(document.activeElement);e.shiftKey&&0===o&&(t[t.length-1].focus(),e.preventDefault()),e.shiftKey||o!==t.length-1||(t[0].focus(),e.preventDefault())}else t[0].focus()}}let o=null;const i=e=>{if(!document.getElementById(e))return console.warn(`MicroModal: ❗Seems like you have missed %c'${e}'`,"background-color: #f8f9fa;color: #50596c;font-weight: bold;","ID somewhere in your code. Refer example below to resolve it."),console.warn("%cExample:","background-color: #f8f9fa;color: #50596c;font-weight: bold;",`<div class="modal" id="${e}"></div>`),!1},n=(e,t)=>{if((e=>{if(e.length<=0)console.warn("MicroModal: ❗Please specify at least one %c'micromodal-trigger'","background-color: #f8f9fa;color: #50596c;font-weight: bold;","data attribute."),console.warn("%cExample:","background-color: #f8f9fa;color: #50596c;font-weight: bold;",'<a href="#" data-micromodal-trigger="my-modal"></a>')})(e),!t)return!0;for(var o in t)i(o);return!0};return{init:e=>{const i=Object.assign({},{openTrigger:"data-micromodal-trigger"},e),s=[...document.querySelectorAll(`[${i.openTrigger}]`)],a=((e,t)=>{const o=[];return e.forEach(e=>{const i=e.attributes[t].value;void 0===o[i]&&(o[i]=[]),o[i].push(e)}),o})(s,i.openTrigger);if(!0!==i.debugMode||!1!==n(s,a))for(var l in a){let e=a[l];i.targetModal=l,i.triggers=[...e],o=new t(i)}},show:(e,n)=>{const s=n||{};s.targetModal=e,!0===s.debugMode&&!1===i(e)||(o=new t(s)).showModal()},close:e=>{e?o.closeModalById(e):o.closeModal()}}})()});
|
255
wp-content/plugins/wp-rocket/assets/js/preload-links.js
Normal file
255
wp-content/plugins/wp-rocket/assets/js/preload-links.js
Normal file
@@ -0,0 +1,255 @@
|
||||
class RocketPreloadLinks {
|
||||
|
||||
constructor( browser, config ) {
|
||||
this.browser = browser;
|
||||
this.config = config;
|
||||
this.options = this.browser.options;
|
||||
|
||||
this.prefetched = new Set;
|
||||
this.eventTime = null;
|
||||
this.threshold = 1111;
|
||||
this.numOnHover = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the handler.
|
||||
*/
|
||||
init() {
|
||||
if (
|
||||
! this.browser.supportsLinkPrefetch()
|
||||
||
|
||||
this.browser.isDataSaverModeOn()
|
||||
||
|
||||
this.browser.isSlowConnection()
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.regex = {
|
||||
excludeUris: RegExp( this.config.excludeUris, 'i' ),
|
||||
images: RegExp( '.(' + this.config.imageExt + ')$', 'i' ),
|
||||
fileExt: RegExp( '.(' + this.config.fileExt + ')$', 'i' )
|
||||
};
|
||||
|
||||
this._initListeners( this );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the event listeners.
|
||||
*
|
||||
* @private
|
||||
*
|
||||
* @param self instance of this object, used for binding "this" to the listeners.
|
||||
*/
|
||||
_initListeners( self ) {
|
||||
// Setting onHoverDelay to -1 disables the "on-hover" feature.
|
||||
if ( this.config.onHoverDelay > -1 ) {
|
||||
document.addEventListener( 'mouseover', self.listener.bind( self ), self.listenerOptions );
|
||||
}
|
||||
|
||||
document.addEventListener( 'mousedown', self.listener.bind( self ), self.listenerOptions );
|
||||
document.addEventListener( 'touchstart', self.listener.bind( self ), self.listenerOptions );
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener. Processes when near or on a valid <a> hyperlink.
|
||||
*
|
||||
* @param Event event Event instance.
|
||||
*/
|
||||
listener( event ) {
|
||||
const linkElem = event.target.closest( 'a' );
|
||||
const url = this._prepareUrl( linkElem );
|
||||
if ( null === url ) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch ( event.type ) {
|
||||
case 'mousedown':
|
||||
case 'touchstart':
|
||||
this._addPrefetchLink( url );
|
||||
break;
|
||||
case 'mouseover':
|
||||
this._earlyPrefetch( linkElem, url, 'mouseout' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @private
|
||||
*
|
||||
* @param Element|null linkElem
|
||||
* @param object url
|
||||
* @param string resetEvent
|
||||
*/
|
||||
_earlyPrefetch( linkElem, url, resetEvent ) {
|
||||
const doPrefetch = () => {
|
||||
falseTrigger = null;
|
||||
|
||||
// Start the rate throttle: 1 sec timeout.
|
||||
if ( 0 === this.numOnHover ) {
|
||||
setTimeout( () => this.numOnHover = 0, 1000 );
|
||||
}
|
||||
// Bail out when exceeding the rate throttle.
|
||||
else if ( this.numOnHover > this.config.rateThrottle ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.numOnHover++;
|
||||
this._addPrefetchLink( url );
|
||||
};
|
||||
|
||||
// Delay to avoid false triggers for hover/touch/tap.
|
||||
let falseTrigger = setTimeout( doPrefetch, this.config.onHoverDelay );
|
||||
|
||||
// On reset event, reset the false trigger timer.
|
||||
const reset = () => {
|
||||
linkElem.removeEventListener( resetEvent, reset, { passive: true } );
|
||||
if ( null === falseTrigger ) {
|
||||
return;
|
||||
}
|
||||
|
||||
clearTimeout( falseTrigger );
|
||||
falseTrigger = null;
|
||||
};
|
||||
linkElem.addEventListener( resetEvent, reset, { passive: true } );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a <link rel="prefetch" href="<url>"> for the given URL.
|
||||
*
|
||||
* @param string url The Given URL to prefetch.
|
||||
*/
|
||||
_addPrefetchLink( url ) {
|
||||
this.prefetched.add( url.href );
|
||||
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
const elem = document.createElement( 'link' );
|
||||
elem.rel = 'prefetch';
|
||||
elem.href = url.href;
|
||||
elem.onload = resolve;
|
||||
elem.onerror = reject;
|
||||
|
||||
document.head.appendChild( elem );
|
||||
} ).catch(() => {
|
||||
// ignore and continue.
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares the target link's URL.
|
||||
*
|
||||
* @private
|
||||
*
|
||||
* @param Element|null linkElem Instance of the link element.
|
||||
* @returns {null|*}
|
||||
*/
|
||||
_prepareUrl( linkElem ) {
|
||||
if (
|
||||
null === linkElem
|
||||
||
|
||||
typeof linkElem !== 'object'
|
||||
||
|
||||
! 'href' in linkElem
|
||||
||
|
||||
// Link prefetching only works on http/https protocol.
|
||||
[ 'http:', 'https:' ].indexOf( linkElem.protocol ) === -1
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const origin = linkElem.href.substring( 0, this.config.siteUrl.length );
|
||||
const pathname = this._getPathname( linkElem.href, origin );
|
||||
const url = {
|
||||
original: linkElem.href,
|
||||
protocol: linkElem.protocol,
|
||||
origin: origin,
|
||||
pathname: pathname,
|
||||
href: origin + pathname
|
||||
};
|
||||
|
||||
return this._isLinkOk( url ) ? url : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the URL's pathname. Note: ensures the pathname matches the permalink structure.
|
||||
*
|
||||
* @private
|
||||
*
|
||||
* @param object url Instance of the URL.
|
||||
* @param string origin The target link href's origin.
|
||||
* @returns {string}
|
||||
*/
|
||||
_getPathname( url, origin ) {
|
||||
let pathname = origin
|
||||
? url.substring( this.config.siteUrl.length )
|
||||
: url;
|
||||
|
||||
if ( ! pathname.startsWith( '/' ) ) {
|
||||
pathname = '/' + pathname;
|
||||
}
|
||||
|
||||
if ( this._shouldAddTrailingSlash( pathname ) ) {
|
||||
return pathname + '/';
|
||||
}
|
||||
|
||||
return pathname;
|
||||
}
|
||||
|
||||
_shouldAddTrailingSlash( pathname ) {
|
||||
return (
|
||||
this.config.usesTrailingSlash
|
||||
&&
|
||||
! pathname.endsWith( '/' )
|
||||
&&
|
||||
! this.regex.fileExt.test( pathname )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given link element is okay to process.
|
||||
*
|
||||
* @private
|
||||
*
|
||||
* @param object url URL parts object.
|
||||
*
|
||||
* @returns {boolean}
|
||||
*/
|
||||
_isLinkOk( url ) {
|
||||
if ( null === url || typeof url !== 'object' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
! this.prefetched.has( url.href )
|
||||
&&
|
||||
url.origin === this.config.siteUrl // is an internal document.
|
||||
&&
|
||||
url.href.indexOf( '?' ) === -1 // not a query string.
|
||||
&&
|
||||
url.href.indexOf( '#' ) === -1 // not an anchor.
|
||||
&&
|
||||
! this.regex.excludeUris.test( url.href ) // not excluded.
|
||||
&&
|
||||
! this.regex.images.test( url.href ) // not an image.
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Named static constructor to encapsulate how to create the object.
|
||||
*/
|
||||
static run() {
|
||||
// Bail out if the configuration not passed from the server.
|
||||
if ( typeof RocketPreloadLinksConfig === 'undefined' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const browser = new RocketBrowserCompatibilityChecker( {
|
||||
capture: true,
|
||||
passive: true
|
||||
} );
|
||||
const instance = new RocketPreloadLinks( browser, RocketPreloadLinksConfig );
|
||||
instance.init();
|
||||
}
|
||||
}
|
||||
|
||||
RocketPreloadLinks.run();
|
3
wp-content/plugins/wp-rocket/assets/js/preload-links.min.js
vendored
Normal file
3
wp-content/plugins/wp-rocket/assets/js/preload-links.min.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
(function() {
|
||||
"use strict";var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e=function(){function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}return function(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}}();function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var t=function(){function n(e,t){i(this,n),this.browser=e,this.config=t,this.options=this.browser.options,this.prefetched=new Set,this.eventTime=null,this.threshold=1111,this.numOnHover=0}return e(n,[{key:"init",value:function(){!this.browser.supportsLinkPrefetch()||this.browser.isDataSaverModeOn()||this.browser.isSlowConnection()||(this.regex={excludeUris:RegExp(this.config.excludeUris,"i"),images:RegExp(".("+this.config.imageExt+")$","i"),fileExt:RegExp(".("+this.config.fileExt+")$","i")},this._initListeners(this))}},{key:"_initListeners",value:function(e){-1<this.config.onHoverDelay&&document.addEventListener("mouseover",e.listener.bind(e),e.listenerOptions),document.addEventListener("mousedown",e.listener.bind(e),e.listenerOptions),document.addEventListener("touchstart",e.listener.bind(e),e.listenerOptions)}},{key:"listener",value:function(e){var t=e.target.closest("a"),n=this._prepareUrl(t);if(null!==n)switch(e.type){case"mousedown":case"touchstart":this._addPrefetchLink(n);break;case"mouseover":this._earlyPrefetch(t,n,"mouseout")}}},{key:"_earlyPrefetch",value:function(t,e,n){var i=this,r=setTimeout(function(){if(r=null,0===i.numOnHover)setTimeout(function(){return i.numOnHover=0},1e3);else if(i.numOnHover>i.config.rateThrottle)return;i.numOnHover++,i._addPrefetchLink(e)},this.config.onHoverDelay);t.addEventListener(n,function e(){t.removeEventListener(n,e,{passive:!0}),null!==r&&(clearTimeout(r),r=null)},{passive:!0})}},{key:"_addPrefetchLink",value:function(i){return this.prefetched.add(i.href),new Promise(function(e,t){var n=document.createElement("link");n.rel="prefetch",n.href=i.href,n.onload=e,n.onerror=t,document.head.appendChild(n)}).catch(function(){})}},{key:"_prepareUrl",value:function(e){if(null===e||"object"!==(void 0===e?"undefined":r(e))||!1 in e||-1===["http:","https:"].indexOf(e.protocol))return null;var t=e.href.substring(0,this.config.siteUrl.length),n=this._getPathname(e.href,t),i={original:e.href,protocol:e.protocol,origin:t,pathname:n,href:t+n};return this._isLinkOk(i)?i:null}},{key:"_getPathname",value:function(e,t){var n=t?e.substring(this.config.siteUrl.length):e;return n.startsWith("/")||(n="/"+n),this._shouldAddTrailingSlash(n)?n+"/":n}},{key:"_shouldAddTrailingSlash",value:function(e){return this.config.usesTrailingSlash&&!e.endsWith("/")&&!this.regex.fileExt.test(e)}},{key:"_isLinkOk",value:function(e){return null!==e&&"object"===(void 0===e?"undefined":r(e))&&(!this.prefetched.has(e.href)&&e.origin===this.config.siteUrl&&-1===e.href.indexOf("?")&&-1===e.href.indexOf("#")&&!this.regex.excludeUris.test(e.href)&&!this.regex.images.test(e.href))}}],[{key:"run",value:function(){"undefined"!=typeof RocketPreloadLinksConfig&&new n(new RocketBrowserCompatibilityChecker({capture:!0,passive:!0}),RocketPreloadLinksConfig).init()}}]),n}();t.run();
|
||||
}());
|
@@ -0,0 +1,7 @@
|
||||
jQuery( document ).ready( function( $ ){
|
||||
$( '.rocket-dismiss' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
var url = $( this ).attr( 'href' ).replace( 'admin-post', 'admin-ajax' );
|
||||
$.get( url ).done( $( this ).closest( '.notice' ).hide( 'slow' ) );
|
||||
});
|
||||
} );
|
2
wp-content/plugins/wp-rocket/assets/js/wpr-admin.js
Normal file
2
wp-content/plugins/wp-rocket/assets/js/wpr-admin.js
Normal file
File diff suppressed because one or more lines are too long
1
wp-content/plugins/wp-rocket/assets/js/wpr-admin.js.map
Normal file
1
wp-content/plugins/wp-rocket/assets/js/wpr-admin.js.map
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,36 @@
|
||||
let cpcssHeartbeatCall;
|
||||
const cpcssHeartbeat = () => {
|
||||
const xhttp = new XMLHttpRequest();
|
||||
xhttp.onload = () => {
|
||||
if ( 200 !== xhttp.status ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cpcs_heartbeat_response = JSON.parse( xhttp.response );
|
||||
if ( false === cpcs_heartbeat_response.success ) {
|
||||
stopCPCSSHeartbeat();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( cpcs_heartbeat_response.success &&
|
||||
'cpcss_complete' === cpcs_heartbeat_response.data.status ) {
|
||||
stopCPCSSHeartbeat();
|
||||
return;
|
||||
}
|
||||
|
||||
cpcssHeartbeatCall = setTimeout( () => {
|
||||
cpcssHeartbeat();
|
||||
}, 3000 );
|
||||
};
|
||||
|
||||
xhttp.open( 'POST', ajaxurl, true );
|
||||
xhttp.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8' );
|
||||
xhttp.send( "action=rocket_cpcss_heartbeat&_nonce=" + rocket_cpcss_heartbeat.nonce );
|
||||
}
|
||||
|
||||
|
||||
const stopCPCSSHeartbeat = () => {
|
||||
clearTimeout( cpcssHeartbeatCall );
|
||||
}
|
||||
|
||||
cpcssHeartbeat();
|
146
wp-content/plugins/wp-rocket/assets/js/wpr-cpcss.js
Normal file
146
wp-content/plugins/wp-rocket/assets/js/wpr-cpcss.js
Normal file
@@ -0,0 +1,146 @@
|
||||
let checkCPCSSGenerationCall;
|
||||
let checkCPCSSMobileGenerationCall;
|
||||
let cpcsssGenerationPending = 0;
|
||||
let cpcsssMobileGenerationPending = 0;
|
||||
const rocketDeleteCPCSSbtn = document.getElementById( 'rocket-delete-post-cpss' );
|
||||
const rocketGenerateCPCSSbtn = document.getElementById( 'rocket-generate-post-cpss' );
|
||||
const rocketCPCSSGenerate = document.querySelectorAll( '.cpcss_generate' );
|
||||
const rocketCPCSSReGenerate = document.querySelectorAll( '.cpcss_regenerate' );
|
||||
|
||||
rocketDeleteCPCSSbtn.addEventListener( 'click', e => {
|
||||
e.preventDefault();
|
||||
deleteCPCSS();
|
||||
} );
|
||||
|
||||
rocketGenerateCPCSSbtn.addEventListener( 'click', e => {
|
||||
e.preventDefault();
|
||||
rocketGenerateCPCSSbtn.disabled = true;
|
||||
checkCPCSSGeneration( null, false );
|
||||
if ( rocket_cpcss.wprMobileCpcssEnabled ) {
|
||||
checkCPCSSGeneration( null, true );
|
||||
}
|
||||
} );
|
||||
|
||||
const checkCPCSSGeneration = ( timeout = null, is_mobile = false ) => {
|
||||
const spinner = rocketGenerateCPCSSbtn.querySelector( '.spinner' );
|
||||
spinner.style.display = 'block';
|
||||
spinner.style.visibility = 'visible';
|
||||
|
||||
const xhttp = new XMLHttpRequest();
|
||||
xhttp.onload = () => {
|
||||
if ( 200 !== xhttp.status ) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cpcss_response = JSON.parse( xhttp.response );
|
||||
if ( 200 !== cpcss_response.data.status ) {
|
||||
stopCPCSSGeneration( spinner );
|
||||
if ( ! is_mobile ) {
|
||||
cpcssNotice( cpcss_response.message, 'error' );
|
||||
}
|
||||
rocketGenerateCPCSSbtn.disabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 200 === cpcss_response.data.status &&
|
||||
'cpcss_generation_pending' !== cpcss_response.code ) {
|
||||
stopCPCSSGeneration( spinner, is_mobile );
|
||||
if ( ! is_mobile ) {
|
||||
cpcssNotice( cpcss_response.message, 'success' );
|
||||
}
|
||||
|
||||
// Revert view to Regenerate.
|
||||
rocketGenerateCPCSSbtn.querySelector( '.rocket-generate-post-cpss-btn-txt' ).innerHTML = rocket_cpcss.regenerate_btn;
|
||||
rocketDeleteCPCSSbtn.style.display = 'block';
|
||||
rocketGenerateCPCSSbtn.disabled = false;
|
||||
rocketCPCSSGenerate.forEach( item => item.style.display = 'none' );
|
||||
rocketCPCSSReGenerate.forEach( item => item.style.display = 'block' );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( is_mobile ) {
|
||||
cpcsssMobileGenerationPending++;
|
||||
if ( cpcsssMobileGenerationPending > 10 ) {
|
||||
stopCPCSSGeneration( spinner, is_mobile );
|
||||
cpcsssMobileGenerationPending = 0;
|
||||
checkCPCSSGeneration( true, true );
|
||||
return;
|
||||
}
|
||||
checkCPCSSMobileGenerationCall = setTimeout( () => {
|
||||
checkCPCSSGeneration( null, true );
|
||||
}, 3000 );
|
||||
} else {
|
||||
cpcsssGenerationPending++;
|
||||
if ( cpcsssGenerationPending > 10 ) {
|
||||
stopCPCSSGeneration( spinner, is_mobile );
|
||||
cpcsssGenerationPending = 0;
|
||||
checkCPCSSGeneration( true, false );
|
||||
return;
|
||||
}
|
||||
|
||||
checkCPCSSGenerationCall = setTimeout( () => {
|
||||
checkCPCSSGeneration( null, false );
|
||||
}, 3000 );
|
||||
}
|
||||
};
|
||||
|
||||
xhttp.open( 'POST', rocket_cpcss.rest_url, true );
|
||||
xhttp.setRequestHeader( 'Content-Type', 'application/json;charset=UTF-8' );
|
||||
xhttp.setRequestHeader( 'X-WP-Nonce', rocket_cpcss.rest_nonce );
|
||||
xhttp.send( JSON.stringify( { timeout: timeout, is_mobile: is_mobile } ) );
|
||||
}
|
||||
|
||||
const stopCPCSSGeneration = ( spinner, is_mobile ) => {
|
||||
spinner.style.display = 'none';
|
||||
if ( is_mobile ) {
|
||||
clearTimeout( checkCPCSSMobileGenerationCall );
|
||||
} else {
|
||||
clearTimeout( checkCPCSSGenerationCall );
|
||||
}
|
||||
}
|
||||
|
||||
const deleteCPCSS = () => {
|
||||
rocketDeleteCPCSSbtn.disabled = true;
|
||||
|
||||
const xhttp = new XMLHttpRequest();
|
||||
xhttp.onload = () => {
|
||||
if ( 200 !== xhttp.status ) {
|
||||
return;
|
||||
}
|
||||
|
||||
rocketDeleteCPCSSbtn.disabled = false;
|
||||
const cpcss_response = JSON.parse( xhttp.response );
|
||||
|
||||
if ( 200 !== cpcss_response.data.status ) {
|
||||
cpcssNotice( cpcss_response.message, 'error' );
|
||||
return;
|
||||
}
|
||||
cpcssNotice( cpcss_response.message, 'success' );
|
||||
|
||||
// Revert view to Generate.
|
||||
rocketGenerateCPCSSbtn.querySelector( '.rocket-generate-post-cpss-btn-txt' ).innerHTML = rocket_cpcss.generate_btn;
|
||||
rocketDeleteCPCSSbtn.style.display = 'none';
|
||||
rocketCPCSSReGenerate.forEach( item => item.style.display = 'none' );
|
||||
rocketCPCSSGenerate.forEach( item => item.style.display = 'block' );
|
||||
};
|
||||
|
||||
xhttp.open( 'DELETE', rocket_cpcss.rest_url, true );
|
||||
xhttp.setRequestHeader( 'Content-Type', 'application/json;charset=UTF-8' );
|
||||
xhttp.setRequestHeader( 'X-WP-Nonce', rocket_cpcss.rest_nonce );
|
||||
xhttp.send();
|
||||
}
|
||||
|
||||
const cpcssNotice = ( msg, type ) => {
|
||||
/* Add notice class */
|
||||
const cpcssNotice = document.getElementById( 'cpcss_response_notice' );
|
||||
cpcssNotice.innerHTML = '';
|
||||
cpcssNotice.classList.remove( 'hidden', 'notice', 'is-warning', 'notice-error', 'notice-success', 'is-error', 'is-success' );
|
||||
cpcssNotice.classList.add( 'notice', 'notice-' + type, 'is-' + type );
|
||||
|
||||
/* create paragraph element to hold message */
|
||||
const p = document.createElement( 'p' );
|
||||
p.appendChild( document.createTextNode( msg ) );
|
||||
|
||||
/* Add the whole message to notice div */
|
||||
cpcssNotice.appendChild( p );
|
||||
}
|
202
wp-content/plugins/wp-rocket/assets/js/wpr-modal.js
Normal file
202
wp-content/plugins/wp-rocket/assets/js/wpr-modal.js
Normal file
@@ -0,0 +1,202 @@
|
||||
var $ = jQuery;
|
||||
$(document).ready(function(){
|
||||
|
||||
var $wprModal = $(".wpr-Modal");
|
||||
if($wprModal){
|
||||
new ModalWpr($wprModal);
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX Safe mode action button
|
||||
*/
|
||||
$('#wpr-action-safe_mode').on('click', function(e) {
|
||||
var button = $(this);
|
||||
e.preventDefault();
|
||||
|
||||
$.post(
|
||||
ajaxurl,
|
||||
{
|
||||
action: 'rocket_safe_mode',
|
||||
nonce: rocket_ajax_data.nonce,
|
||||
},
|
||||
function(response) {
|
||||
if ( true === response.success ) {
|
||||
button.hide();
|
||||
$('.show-if-safe-mode').show();
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/*-----------------------------------------------*\
|
||||
CLASS ModalWpr
|
||||
\*-----------------------------------------------*/
|
||||
/**
|
||||
* Manages the display of deactivation modal box
|
||||
*
|
||||
* Public method :
|
||||
open - Open the modal
|
||||
close - Close the modal
|
||||
change - Test if modal state change
|
||||
*
|
||||
*/
|
||||
|
||||
function ModalWpr(aElem) {
|
||||
|
||||
var refThis = this;
|
||||
|
||||
this.elem = aElem;
|
||||
this.overlay = $('.wpr-Modal-overlay');
|
||||
this.radio = $('input[name=reason]', aElem);
|
||||
this.closer = $('.wpr-Modal-close, .wpr-Modal-cancel', aElem);
|
||||
this.return = $('.wpr-Modal-return', aElem);
|
||||
this.opener = $('.plugins [data-slug="wp-rocket"] .deactivate');
|
||||
this.question = $('.wpr-Modal-question', aElem);
|
||||
this.button = $('.button-primary', aElem);
|
||||
this.title = $('.wpr-Modal-header h2', aElem);
|
||||
this.textFields = $('input[type=text], textarea',aElem);
|
||||
this.hiddenReason = $('#wpr-reason', aElem);
|
||||
this.hiddenDetails = $('#wpr-details', aElem);
|
||||
this.titleText = this.title.text();
|
||||
|
||||
// Open
|
||||
this.opener.click(function() {
|
||||
refThis.open();
|
||||
return false;
|
||||
});
|
||||
|
||||
// Close
|
||||
this.closer.click(function() {
|
||||
refThis.close();
|
||||
return false;
|
||||
});
|
||||
|
||||
aElem.bind('keyup', function(){
|
||||
if(event.keyCode == 27){ // ECHAP
|
||||
refThis.close();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Back
|
||||
this.return.click(function() {
|
||||
refThis.returnToQuestion();
|
||||
return false;
|
||||
});
|
||||
|
||||
// Click on radio
|
||||
this.radio.change(function(){
|
||||
refThis.change($(this));
|
||||
});
|
||||
|
||||
// Write text
|
||||
this.textFields.keyup(function() {
|
||||
refThis.hiddenDetails.val($(this).val());
|
||||
if(refThis.hiddenDetails.val() != ''){
|
||||
refThis.button.removeClass('wpr-isDisabled');
|
||||
refThis.button.removeAttr("disabled");
|
||||
}
|
||||
else{
|
||||
refThis.button.addClass('wpr-isDisabled');
|
||||
refThis.button.attr("disabled", true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Change modal state
|
||||
*/
|
||||
ModalWpr.prototype.change = function(aElem) {
|
||||
|
||||
var id = aElem.attr('id');
|
||||
var refThis = this;
|
||||
|
||||
// Reset values
|
||||
this.hiddenReason.val(aElem.val());
|
||||
this.hiddenDetails.val('');
|
||||
this.textFields.val('');
|
||||
|
||||
$('.wpr-Modal-fieldHidden').removeClass('wpr-isOpen');
|
||||
$('.wpr-Modal-hidden').removeClass('wpr-isOpen');
|
||||
this.button.removeClass('wpr-isDisabled');
|
||||
this.button.removeAttr("disabled");
|
||||
|
||||
switch(id){
|
||||
case 'reason-temporary':
|
||||
// Nothing to do
|
||||
break;
|
||||
|
||||
case 'reason-broke':
|
||||
case 'reason-score':
|
||||
case 'reason-loading':
|
||||
case 'reason-complicated':
|
||||
var $panel = $('#' + id + '-panel');
|
||||
refThis.question.removeClass('wpr-isOpen');
|
||||
refThis.return.addClass('wpr-isOpen');
|
||||
$panel.addClass('wpr-isOpen');
|
||||
|
||||
var titleText = $panel.find('h3').text();
|
||||
this.title.text(titleText);
|
||||
break;
|
||||
|
||||
case 'reason-host':
|
||||
case 'reason-other':
|
||||
var field = aElem.siblings('.wpr-Modal-fieldHidden');
|
||||
field.addClass('wpr-isOpen');
|
||||
field.find('input, textarea').focus();
|
||||
refThis.button.addClass('wpr-isDisabled');
|
||||
refThis.button.attr("disabled", true);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Return to the question
|
||||
*/
|
||||
ModalWpr.prototype.returnToQuestion = function() {
|
||||
|
||||
$('.wpr-Modal-fieldHidden').removeClass('wpr-isOpen');
|
||||
$('.wpr-Modal-hidden').removeClass('wpr-isOpen');
|
||||
this.question.addClass('wpr-isOpen');
|
||||
this.return.removeClass('wpr-isOpen');
|
||||
this.title.text(this.titleText);
|
||||
|
||||
// Reset values
|
||||
this.hiddenReason.val('');
|
||||
this.hiddenDetails.val('');
|
||||
|
||||
this.radio.attr('checked', false);
|
||||
this.button.addClass('wpr-isDisabled');
|
||||
this.button.attr("disabled", true);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Open modal
|
||||
*/
|
||||
ModalWpr.prototype.open = function() {
|
||||
|
||||
this.elem.css('display','block');
|
||||
this.overlay.css('display','block');
|
||||
|
||||
// Reset current tab wp-rocket
|
||||
localStorage.setItem('wpr-hash', '');
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Close modal
|
||||
*/
|
||||
ModalWpr.prototype.close = function() {
|
||||
|
||||
this.returnToQuestion();
|
||||
this.elem.css('display','none');
|
||||
this.overlay.css('display','none');
|
||||
|
||||
};
|
Reference in New Issue
Block a user