Skip to content

Commit ab4740a

Browse files
committed
Implemented lazy-lazy iframes
1 parent b171c85 commit ab4740a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

scholia/app/templates/base.html

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,24 @@
3434

3535
{% macro sparql_to_iframe(panel) -%}
3636
// {{ panel }} iframe
37-
sparqlToIframe2("{{ sparql_endpoint }}", "{{ sparql_editURL }}",
38-
"{{ sparql_embedURL }}", `# tool: scholia
39-
{% include aspect + '_' + panel + '.sparql' %}`,
40-
"#{{ panel }}-iframe", "{{ aspect }}_{{ panel }}.sparql");
37+
console.log('adding an observer to: #{{ panel }}-iframe');
38+
const {{ panel | replace("-", "") }}Observer = new IntersectionObserver({{ panel | replace("-", "") }}HandleIntersection);
39+
{{ panel | replace("-", "") }}Observer.observe(document.querySelector('#{{ panel }}-iframe'));
40+
function {{ panel | replace("-", "") }}HandleIntersection(entries, observer){
41+
entries.forEach(entry => {
42+
if (entry.intersectionRatio > 0) {
43+
console.log('Element is in the viewport! #{{ panel }}-iframe');
44+
sparqlToIframe2("{{ sparql_endpoint }}", "{{ sparql_editURL }}",
45+
"{{ sparql_embedURL }}", `# tool: scholia
46+
{% include aspect + '_' + panel + '.sparql' %}`,
47+
"#{{ panel }}-iframe", "{{ aspect }}_{{ panel }}.sparql"
48+
);
49+
{{ panel | replace("-", "") }}Observer.unobserve(entry.target);
50+
}
51+
});
52+
}
53+
54+
4155
{%- endmacro %}
4256

4357
{% macro sparql_to_matrix(panel) -%}

0 commit comments

Comments
 (0)