lazy-load-for-videos
lazy-load-for-videos copied to clipboard
Ajax Support
Hi, I am the developer of the Ajax Load More WordPress plugin.
I'm wondering if you have any public JavaScript methods I can hook into after successful Ajax requests to initiate the Lazy Load for Videos functionality on the new content?
I have several users looking for this functionality, I've spent a considerable amount of time inspecting the src JS of your plugin, but was not able to determine if this functionality is available.
Before I start working on a PR, I just wanted to know if this was already available.
Hi @dcooney, thank you for reaching out! Making Ajax Load More compatible with this video plugin would be fantastic. I don't think what you need is already available. I'm happy to give you some hints on how to make this work.
There's already the jQueryAjaxStop function. It's always being called on plugin initialization and on screen resizing. It was implemented many years back to support some jQuery use cases though my plugin does not depend on jQuery:
function jQueryAjaxStop(callback) {
const $ = window.jQuery || window.$;
if ($) {
$(document).ajaxStop(() => {
callback();
});
}
}
You could potentially modify that function to support your use case. Another potential way could be to hook into the lly_change_options filter that has a callback field. However, this callback is currently not called anywhere and would need extra changes in the JS: https://github.com/kevinweber/lazy-load-for-videos/blob/8baca630817f7cffc73b047b53706eea5f748141/src/frontend/lazyload-youtube/lazyloadYoutube.js#L30
You can refer to the contribution section to see how to run the code locally. In essence, run npm run watch while developing and run npm run production to wrap things up.
@kevinweber Thank you, this really helps. I have this working and will have a PR incoming for this. I'm not sure you'll love the solution but the way the plugin functionality is split into separate vimeo and youtube JS files makes it somewhat challenging.