<style>
@media (max-width: 55em) {
.tc-modal-body img {
display: block;
margin-left: auto;
margin-right: auto;
}
}
@media (min-width: 55em) {
.tc-modal {
width: -webkit-min-content;
width: -moz-min-content;
width: min-content;
max-width: 95%;
}
}
.tc-modal-body {
padding: 1px 15px;
min-width: 750px;
}
.tc-modal-body img {
max-width: 100%;
}
</style>
<$list filter="[is[image]has[_canonical_uri]]" variable="currentImage">
<$button class="tc-btn-invisible tc-thumbnail-image">
<$action-sendmessage $message="tm-modal" $param=<<currentImage>>/>
<$image source=<<currentImage>> width={{!!imagewidth}}/>
</$button>
</$list>template/picture), with this content:<$image source=<<url>>/><$button class="tc-btn-invisible tc-thumbnail-image">
<$action-sendmessage $message="tm-modal" $param="template/picture" url="./images/Blurry%2520Lawn.jpg"/>
<$image source="./images/Blurry%2520Lawn.jpg" width={{!!imagewidth}}/>
</$button><$button class="tc-btn-invisible tc-thumbnail-image">
...
</$button>The WidgetButton creates a button.
The "class" attribute defines how it looks like: "tc-btn-invisible" removes the grey box of classic buttons, and "tc-thumbnail-image" is a facility to style the image (this class is used for the Thumbnail macro that you can see in action in the HelloThere tiddler of tiddlywiki.com).
<$action-sendmessage $message="tm-modal" $param="template/picture" url="./images/Blurry%2520Lawn.jpg"/>The SendMessage action widget allows the button to trigger an action by sending a message (and this is why we used a button widget: it's currently the only element taht can trigger an action widget), here "tm-modal" to open a modal window. This message can take parameters:
- "$param" is the title of the displayed tiddler. As we don't have tiddlers for our images, I use a template tiddler: "template/picture". It acts as a skeleton for the content of the modal.
- "url" is a variable (or parameter) for the template
The template contains:<$image source=<<url>>/>So the modal will display an image, whose url is the variable set previously in the message "tm-modal". The ImageWidget is used because the source is not already defined, the [img[]] syntax doesn't work with variables.
Finally
<$image source="./images/Blurry%2520Lawn.jpg" width={{!!imagewidth}}/>displays the "label" of the button, here an image. It is exactly what you had at the beginong, but with an ImageWidget instead of [img[]] (which could work here).
If you want to create a macro, you would have to replace the name of the image with a parameter:
\define macro-image(url)
<$button class="tc-btn-invisible tc-thumbnail-image">
<$action-sendmessage $message="tm-modal" $param="template/picture" url="$url$"/>
<$image source="$url$" width={{!!imagewidth}}/>
</$button>
And then use it with
<<macro-image "./images/Blurry%2520Lawn.jpg">>
Still one click to open and another one to close, but at the same place.\define image-popup(url)
<$button popup=<<qualify "$:/state/popup/$url$">>>
[img width={{!!imagewidth}} [$url$]]
</$button>
<$reveal type="popup" state=<<qualify "$:/state/popup/$url$">>>
[img[$url$]]
</$reveal>
\endThe qualify macro ensure all your image popup don't pop at the same time when you click on one.