Skip to content

Commit

Permalink
Fix some options not working bug
Browse files Browse the repository at this point in the history
  • Loading branch information
blueswen committed Jul 16, 2022
1 parent 87f3905 commit f0420bd
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
mkdocs-glightbox-0.1.6 (2022-07-16)

* Fix some options not working bug

mkdocs-glightbox-0.1.5 (2022-07-16)

* Fix mkdocs-material header + sidebar vanishing issue when open lightbox (Inspired from https://github.com/biati-digital/glightbox/issues/22)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

A MkDocs plugin supports image lightbox with [GLightbox](https://github.com/biati-digital/glightbox).

GLightbox is pure Javascript lightbox library with mobile support.
GLightbox is a pure javascript lightbox library with mobile support.

[Live demo](https://blueswen.github.io/mkdocs-glightbox/) with [mkdocs-material](https://squidfunk.github.io/mkdocs-material/) theme.

Expand Down Expand Up @@ -36,7 +36,7 @@ GLightbox is pure Javascript lightbox library with mobile support.
```yaml
plugins:
- glightbox:
touchNavigation: false
touchNavigation: true
loop: false
effect: zoom
width: 100%
Expand All @@ -48,12 +48,12 @@ GLightbox is pure Javascript lightbox library with mobile support.
| Option | Default | Description |
|-----------------|---------|--------------------------------------------------------------------------------------------------------------|
| touchNavigation | true | Enable or disable the touch navigation (swipe). |
| loop | true | Loop slides on end. |
| loop | false | Loop slides on end. |
| effect | zoom | Name of the effect on lightbox open. (zoom, fade, none) |
| width | 100% | Default width for inline elements and iframes. You can use any unit for example 90% or 100vw for full width. |
| height | auto | Default height for inline elements and iframes. You can use any unit for example 90%, 100vh or auto. |
| zoomable | True | Enable or disable zoomable images. |
| draggable | True | Enable or disable mouse drag to go prev and next slide. |
| zoomable | true | Enable or disable zoomable images. |
| draggable | true | Enable or disable mouse drag to go prev and next slide. |

Check more options information on [GLightbox Docs](https://github.com/biati-digital/glightbox#lightbox-options).

Expand Down
16 changes: 6 additions & 10 deletions mkdocs_glightbox/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class LightboxPlugin(BasePlugin):
""" Add lightbox to MkDocs """

config_scheme = (
("touchNavigation", config_options.Type(bool, default=False)),
("touchNavigation", config_options.Type(bool, default=True)),
("loop", config_options.Type(bool, default=False)),
("effect", config_options.Type(str, default="zoom")),
("effect", config_options.Choice(("zoom", "fade", "none"), default="zoom")),
("width", config_options.Type(str, default="100%")),
("height", config_options.Type(str, default="auto")),
("zoomable", config_options.Type(bool, default=True)),
Expand Down Expand Up @@ -50,8 +50,10 @@ def on_post_page(self, output, page, config, **kwargs):
soup.head.append(js_script)

js_code = soup.new_tag("script")
lb_config = dict(self.config)
lb_config = {k: lb_config[k] for k in ["touchNavigation", "loop"]}
plugin_config = dict(self.config)
lb_config = {k: plugin_config[k] for k in ["touchNavigation", "loop", "width", "height", "zoomable", "draggable"]}
lb_config['openEffect'] = plugin_config.get('effect', 'zoom')
lb_config['closeEffect'] = plugin_config.get('effect', 'zoom')
js_code.string = f"const lightbox = GLightbox({json.dumps(lb_config)});"
if config["theme"].name == "material" or "navigation.instant" in config["theme"]._vars.get("features", []):
# support compatible with mkdocs-material Instant loading feature
Expand All @@ -62,18 +64,12 @@ def on_post_page(self, output, page, config, **kwargs):

def on_page_content(self, html, page, config, **kwargs):
""" Wrap img tag with archive tag with glightbox class and attributes from config """

lb_data_config = dict(self.config)
lb_data_config = {k: lb_data_config[k] for k in [
"effect", "width", "height", "zoomable", "draggable"]}
soup = BeautifulSoup(html, "html.parser")
imgs = soup.find_all("img")
for img in imgs:
a = soup.new_tag("a")
a["class"] = "glightbox"
a["href"] = img.get("src", "")
for key, val in lb_data_config.items():
a[f"data-{key}"] = val
img.wrap(a)
return str(soup)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="mkdocs-glightbox",
version="0.1.5",
version="0.1.6",
author="Blueswen",
author_email="blueswen.tw@gmail.com",
url = "https://blueswen.github.io/mkdocs-glightbox",
Expand Down

0 comments on commit f0420bd

Please sign in to comment.