From 7150718a515f5305e37e63c75def2811b53d83a7 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Wed, 9 Nov 2022 14:53:55 -0600 Subject: [PATCH] Lazy load iframe --- judge/jinja2/markdown/__init__.py | 5 +++++ resources/common.js | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/judge/jinja2/markdown/__init__.py b/judge/jinja2/markdown/__init__.py index cf5ab15..e34f74a 100644 --- a/judge/jinja2/markdown/__init__.py +++ b/judge/jinja2/markdown/__init__.py @@ -85,5 +85,10 @@ def markdown(value, lazy_load=False): if img.get("src"): img["data-src"] = img["src"] img["src"] = "" + for img in soup.findAll("iframe"): + if img.get("src"): + img["data-src"] = img["src"] + img["src"] = "" html = str(soup) + return '
%s
' % html diff --git a/resources/common.js b/resources/common.js index 4b13c32..6100cb5 100644 --- a/resources/common.js +++ b/resources/common.js @@ -179,7 +179,10 @@ $(function () { $("[data-src]img").each(function() { $(this).attr("src", $(this).attr("data-src")); }) - }, "500"); + $("[data-src]iframe").each(function() { + $(this).attr("src", $(this).attr("data-src")); + }) + }, "100"); }); if (!Date.now) {