Skip to content

Commit

Permalink
Merge pull request #34 from AndBondStyle/main
Browse files Browse the repository at this point in the history
Allow calling lightbox methods from other places
  • Loading branch information
blueswen authored May 2, 2024
2 parents 585944c + 8e65265 commit b0b63f8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions mkdocs_glightbox/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ def on_post_page(self, output, page, config, **kwargs):
element.setAttribute('href', imgSrc);
});
"""
js_code += f"const lightbox = GLightbox({json.dumps(lb_config)});"
js_code += f"const lightbox = GLightbox({json.dumps(lb_config)});\n"
if self.using_material or "navigation.instant" in config["theme"]._vars.get(
"features", []
):
# support compatible with mkdocs-material Instant loading feature
js_code = "document$.subscribe(() => {" + js_code + "})"
js_code += "document$.subscribe(() => { lightbox.reload() });\n"
output = body_regex.sub(f'<body\\1<script id="init-glightbox">{js_code}</script></body>', output)

return output
Expand Down
4 changes: 2 additions & 2 deletions tests/test_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_material(tmp_path):
validate_static(contents)
validate_script(contents)
assert re.search(
r"document\$\.subscribe\(\(\) => {const lightbox = GLightbox\((.*)\);}\)",
r"document\$\.subscribe\(\(\) => { lightbox.reload\(\) }\);",
contents,
)
assert re.search(
Expand Down Expand Up @@ -518,7 +518,7 @@ def test_material_template(tmp_path):
validate_static(contents)
validate_script(contents)
assert re.search(
r"document\$\.subscribe\(\(\) => {const lightbox = GLightbox\((.*)\);}\)",
r"document\$\.subscribe\(\(\) => { lightbox.reload\(\) }\);",
contents,
)
assert re.search(
Expand Down

0 comments on commit b0b63f8

Please sign in to comment.