Skip to content

Commit

Permalink
add zoom-image modal for clicking on images
Browse files Browse the repository at this point in the history
  • Loading branch information
unverbuggt committed Jul 28, 2023
1 parent b3322f8 commit 17d2f0c
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Install the package from source with pip:
```bash
cd mkdocs-risonia-theme/
python setup.py sdist bdist_wheel
pip install dist/mkdocs_risonia_theme-0.1.8-py3-none-any.whl
pip install dist/mkdocs_risonia_theme-0.1.9-py3-none-any.whl
```

## Configuration
Expand All @@ -71,6 +71,7 @@ theme:
#extlink: true # mark external links with symbol
#extblank: true # send external links to new browser tab
#toc_sidebar: true # If display is wide enough, then display TOC on the right side
#zoom_img: true # click on images to view them bigger

plugins:
- search: {}
Expand Down
3 changes: 2 additions & 1 deletion docs/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Install the package from source with pip:
```bash
cd mkdocs-risonia-theme/
python setup.py sdist bdist_wheel
pip install dist/mkdocs_risonia_theme-0.1.8-py3-none-any.whl
pip install dist/mkdocs_risonia_theme-0.1.9-py3-none-any.whl
```

## Configuration
Expand All @@ -60,6 +60,7 @@ theme:
#extlink: true # mark external links with symbol
#extblank: true # send external links to new browser tab
#toc_sidebar: true # If display is wide enough, then display TOC on the right side
#zoom_img: true # click on images to view them bigger

plugins:
- search: {}
Expand Down
3 changes: 2 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Oder aus den Quellen bauen mit pip:
```bash
cd mkdocs-risonia-theme/
python setup.py sdist bdist_wheel
pip install dist/mkdocs_risonia_theme-0.1.8-py3-none-any.whl
pip install dist/mkdocs_risonia_theme-0.1.9-py3-none-any.whl
```

## Konfiguration
Expand All @@ -60,6 +60,7 @@ theme:
#extlink: true # externe Links markieren
#extblank: true # externe Links im neuen Browserfenster öffnen
#toc_sidebar: true # Wenn Anzeige breit genug, dann Inhaltsverzeichnis rechts anzeigen
#zoom_img: true # beim Klicken auf ein Bild wird es größer angezeigt

plugins:
- search: {}
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ theme:
extblank: true
manifest: manifest.json
serviceworker: service-worker.js
zoom_img: true

extra_javascript:
- 'assets/javascripts/highlight.min.js'
Expand Down
8 changes: 7 additions & 1 deletion risonia_theme/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,14 @@
</div>
</div>
{%- endif %}

</div>
{%- if config.theme.zoom_img %}
<div id="zoom_img_modal" class="w3-modal" onclick="this.style.display='none'">
<div class="w3-modal-content w3-animate-zoom">
<img id="img_modal" style="width:100%;">
</div>
</div>
{%- endif %}
{%- block footer %}
<footer class="w3-container w3-theme no-print">
<p class="w3-left w3-tiny">
Expand Down
4 changes: 4 additions & 0 deletions risonia_theme/js/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,7 @@ function closeSearch() {
document.getElementById('mkdocs_search_modal').style.display='none'
}

function zoomImg(element) {
document.getElementById('img_modal').src=element.src;
document.getElementById('zoom_img_modal').style.display='block';
}
2 changes: 2 additions & 0 deletions risonia_theme/mkdocs_theme.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ extlink: false
extblank: true

toc_sidebar: true

zoom_img: false
3 changes: 3 additions & 0 deletions risonia_theme/plugins/classes/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ def on_page_content(self, html, page, config, files):

for img_tag in soup.find_all('img'):
img_tag['class'] = img_tag.get('class', []) + ['w3-image'] #add class to <image>
if 'zoom_img' in config['theme']._vars and config['theme']._vars['zoom_img']:
img_tag['loading'] = "lazy"
img_tag['onclick'] = "zoomImg(this);";

#add extlink svg after external links if configured
if 'extlink' in config['theme']._vars and config['theme']._vars['extlink']:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from setuptools import setup, find_packages

VERSION = '0.1.8'
VERSION = '0.1.9'

def read(fname):
file_path = os.path.join(os.path.dirname(__file__), fname)
Expand Down

0 comments on commit 17d2f0c

Please sign in to comment.