Skip to content

Commit

Permalink
Release 3.15 (PR #6131)
Browse files Browse the repository at this point in the history
Release 3.15
  • Loading branch information
engahmeds3ed authored Aug 31, 2023
2 parents a38a540 + b520071 commit 6417d8f
Show file tree
Hide file tree
Showing 247 changed files with 24,717 additions and 14,433 deletions.
80 changes: 80 additions & 0 deletions assets/js/lazyload-css.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
function rocket_css_lazyload_launch() {

const usable_pairs = typeof rocket_pairs === 'undefined' ? [] : rocket_pairs;


const styleElement = document.querySelector('#wpr-lazyload-bg');

const threshold = rocket_lazyload_css_data.threshold || 300;

const observer = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const pairs = usable_pairs.filter(s => entry.target.matches(s.selector));
pairs.map(pair => {
if (pair) {
styleElement.innerHTML += pair.style;
pair.elements.forEach(el => {
el.setAttribute('data-rocket-lazy-bg', 'loaded');
// Stop observing the target element
observer.unobserve(el);
});
}
})
}
});
}, {
rootMargin: threshold + 'px'
});

function lazyload(e = []) {

const pass = e.length === 0 || e.find(e => e.type !== 'attributes' || e.attributeName === 'class');

if(! pass ) {
return;
}

usable_pairs.forEach(pair => {
try {

const elements = document.querySelectorAll(pair.selector);
elements.forEach(el => {
if(el.getAttribute('data-rocket-lazy-bg') === 'loaded') {
return;
}
observer.observe(el);
// Save el in the pair object (create a new empty array if it doesn't exist)
(pair.elements ||= []).push(el);
});
} catch (error) {
console.error(error);
}
});
}

lazyload();

const observe_DOM = (function(){
const MutationObserver = window.MutationObserver;

return function( obj, callback ){
if( !obj || obj.nodeType !== 1 ) return;

// define a new observer
const mutationObserver = new MutationObserver(callback);

// have the observer observe for changes in children
mutationObserver.observe( obj, { attributes: true, childList:true, subtree:true })
return mutationObserver

}

})()

const body = document.querySelector('body');

observe_DOM(body, lazyload)
}

rocket_css_lazyload_launch();
1 change: 1 addition & 0 deletions assets/js/lazyload-css.js.min.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/js/lazyload-css.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/js/lazyload-css.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6417d8f

Please sign in to comment.