-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make lazy-loadable a global feature #1308
Comments
the following snippet is a proof of concept function triggerLazyLoad(el) {
el.find(".lazy-loadable").each(function (idx, ele) {
ele.dispatchEvent(new Event("lazyloaded"), { once: true });
});
}
$(".ss-tabset, .cms-tabset").entwine({
onadd: function () {
this.on(
"tabsactivate",
function (event, { newPanel }) {
triggerLazyLoad(newPanel);
}.bind(this)
);
this.on(
"tabscreate",
function (event, { panel }) {
triggerLazyLoad(panel);
}.bind(this)
);
this._super();
},
}); |
Sounds like a great idea. Would you be open to raising a PR implementing this feature? |
@GuySartorelli i can certainly give it a try, the basic idea is quite simple and yet has many advantages :) |
@GuySartorelli so, i'm working on it and i've discovered that lazy loading is only delayed if there is a parent ss-tabset.. But the cms-tabset doesn't have that class (and that seems to be a deliberate choice).
That means that for a GridFieldDetailForm, lazy loading of the GridField is always triggered right away. Is that the desired outcome ? |
@GuySartorelli so I gave it a try this is a fairly conservative PR, since i keep both ways of doing things. |
According to the docs the
I'll take a look at the PR today and let you know if it needs any changes. |
@GuySartorelli fyi, because I gave it a bit more thought and you might be interested (eg: maybe replace entwine some day? :-) who knows!), I came up with a creative solution that allows lazy loading without any need for this feature. The solution is simply to rely on the intersection observer, that will trigger when the tab is activated (which is nice, because the tab doesn't have the responsibility to init things itself). In order to make this convenient, I created a custom element that can wrap anything and basically allow lazy loading and field init automatically. |
Awesome! I don't have time to look in depth into that code right now but having stuff work the same on the front and backends is definitely a worthwhile goal. |
Currently, if you have lazy content inside tabs, you need to implement custom js code to handle this
Which is a bit of a shame, because there is already some code related to this for the gridfield
silverstripe-admin/client/src/legacy/TabSet.js
Lines 105 to 113 in d3fc48c
Would the ss dev consider making looking for any ".lazy-loadable" node and trigger a lazy-load event on it ? Actually, it could also be applied to the gridfield. The current implementation feels like a missed opportunity to open this feature for other fields.
The text was updated successfully, but these errors were encountered: