@@ -15,9 +15,9 @@ class LightboxPlugin(BasePlugin):
1515 """ Add lightbox to MkDocs """
1616
1717 config_scheme = (
18- ("touchNavigation" , config_options .Type (bool , default = False )),
18+ ("touchNavigation" , config_options .Type (bool , default = True )),
1919 ("loop" , config_options .Type (bool , default = False )),
20- ("effect" , config_options .Type ( str , default = "zoom" )),
20+ ("effect" , config_options .Choice (( "zoom" , "fade" , "none" ) , default = "zoom" )),
2121 ("width" , config_options .Type (str , default = "100%" )),
2222 ("height" , config_options .Type (str , default = "auto" )),
2323 ("zoomable" , config_options .Type (bool , default = True )),
@@ -50,8 +50,10 @@ def on_post_page(self, output, page, config, **kwargs):
5050 soup .head .append (js_script )
5151
5252 js_code = soup .new_tag ("script" )
53- lb_config = dict (self .config )
54- lb_config = {k : lb_config [k ] for k in ["touchNavigation" , "loop" ]}
53+ plugin_config = dict (self .config )
54+ lb_config = {k : plugin_config [k ] for k in ["touchNavigation" , "loop" , "width" , "height" , "zoomable" , "draggable" ]}
55+ lb_config ['openEffect' ] = plugin_config .get ('effect' , 'zoom' )
56+ lb_config ['closeEffect' ] = plugin_config .get ('effect' , 'zoom' )
5557 js_code .string = f"const lightbox = GLightbox({ json .dumps (lb_config )} );"
5658 if config ["theme" ].name == "material" or "navigation.instant" in config ["theme" ]._vars .get ("features" , []):
5759 # support compatible with mkdocs-material Instant loading feature
@@ -62,18 +64,12 @@ def on_post_page(self, output, page, config, **kwargs):
6264
6365 def on_page_content (self , html , page , config , ** kwargs ):
6466 """ Wrap img tag with archive tag with glightbox class and attributes from config """
65-
66- lb_data_config = dict (self .config )
67- lb_data_config = {k : lb_data_config [k ] for k in [
68- "effect" , "width" , "height" , "zoomable" , "draggable" ]}
6967 soup = BeautifulSoup (html , "html.parser" )
7068 imgs = soup .find_all ("img" )
7169 for img in imgs :
7270 a = soup .new_tag ("a" )
7371 a ["class" ] = "glightbox"
7472 a ["href" ] = img .get ("src" , "" )
75- for key , val in lb_data_config .items ():
76- a [f"data-{ key } " ] = val
7773 img .wrap (a )
7874 return str (soup )
7975
0 commit comments