Skip to content

Commit

Permalink
fix: <script> without src is not delayed like <script src="..." defer>
Browse files Browse the repository at this point in the history
  • Loading branch information
shenlebantongying committed Nov 27, 2024
1 parent ad19263 commit 0bfa52f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/dict/mdx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,11 @@ void MdxDictionary::replaceLinks( QString & id, QString & article )
articleNewText += linkTxt;
match = RX::Mdx::closeScriptTagRe.match( article, linkPos );
if ( match.hasMatch() ) {
articleNewText += article.mid( linkPos, match.capturedEnd() - linkPos );
linkPos = match.capturedEnd();
articleNewText += "gdDeferOnReady(() => {";
articleNewText += article.mid( linkPos, match.capturedStart() - linkPos );
QString endtag = "});</script>";
articleNewText += endtag;
linkPos = match.capturedEnd() + endtag.size();
}
continue;
}
Expand Down
8 changes: 8 additions & 0 deletions src/scripts/gd-builtin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
function gdOnReady(func) {
if (document.readyState !== "loading") {
func();
} else {
document.addEventListener("DOMContentLoaded", func);
}
}

function gdMakeArticleActive(newId, noEvent) {
const gdCurrentArticle =
document.querySelector(".gdactivearticle").attributes.id;
Expand Down

0 comments on commit 0bfa52f

Please sign in to comment.