How to create a viewtoolbar button to hide image links in a tiddler and replace it with a pop-up type of reveal widget wrapped around the image link

Here is an idea that I want to implement.
There are many images in each of my notes tiddlers in the format [img[]]. Some long text tiddlers with many images are difficult to read because of the space occupied by the images. I want to hide these images and show a button in its place which when pressed, the same image will be shown in a pop up. All these should happen on pressing a viewtoolbar button

How to approach this ? - search and replace the image links using regexp and in its place, a popu-up type of reveal widget to be inserted wrapped around the image link.

Anyone has got some ideas regarding how to set it up ?

I don’t have a ready solution, but I suspect you’d probably want to use an alternate view template that can be toggled by the toolbar button, which would either add a field to the current tiddler (to modify the template cascade on a per-tiddler level, as the Section Editor plugin does) or toggle a $:/config/ tiddler (to switch view templates on a global basis). In either case, you’d be able to switch views without substantially altering the tiddler content.

I think it should also be easier to construct this kind of alternate view template in 5.3.0, where—if I’ve followed the discussion correctly—it will be possible to overwrite the image widget on a per-tiddler basis. This would let you redefine $image to render a button/popup instead of an inline image only for tiddlers currently using your custom view template. Wikitext (like [img[]]) gets transformed to widgets (like <$image>) during the parsing/rendering process (more technical details here, if you’re interested), so you could alter the way in which images get rendered without changing your current Wikitext format.

2 Likes

I think you could start with a transclusion macro to display your images and within put the logic to handle the display or popup. A simple solution would be a css display: none; toggle.

2 Likes

@arunnbabu81 If you’re willing to replace all your instances of [img[...]] with a macrocall or a template transclusion, @TW_Tones’s approach would definitely be quickest, and you don’t need 5.3.0 functionality to do it. Here’s a super-quick mockup you can test at tiddlywiki.com:

\define img(source)
<$list filter="[[$:/config/image-mode]text[popup]]"
    emptyMessage="""<$image source=<<__source__>> />""">
<$button popup=<<qualify "$:/state/$source$">>>
Pop me up
</$button>
<$reveal type="popup" state=<<qualify "$:/state/$source$">>>
<div class="tc-drop-down">
<$image source=<<__source__>> />
</div>
</$reveal>
</$list>
\end

\define mode()
<$action-listops $tiddler="$:/config/image-mode" $field="text" $subfilter="+[toggle[popup]]" />
\end

<<img "Motovun Jack.jpg">>

<$button actions=<<mode>>>image mode</$button>

I used a macro mostly for the single-tiddler demonstration, but you could just as easily make the img macro a template tiddler and call it with {{Motovun Jack.jpg||img}}. I didn’t do any particular styling on the popup, but you could style it to your liking (or use a modal instead) and add additional macro parameters for other $image attributes.

You’d want to move the “image mode” button and the mode macro definition to a separate tiddler for your view toolbar button. The sample button is currently toggling a global config tiddler, but you could alter it to modify <<currentTiddler>> instead, if you want per-tiddler control.

If you do want to go this route, I’d recommend using the Commander plugin to search-and-replace the wikitext in all the tiddlers where you want this alternate behavior.

2 Likes

Give this a spin at TiddlyWiki.com

Put the following in a new tiddler:

\define ViewImageButton(p_img)
<$button>
<$action-setfield $tiddler="Image Viewer" text="[img width=100% [$p_img$]]"/>
<$action-sendmessage 
  $message="tm-open-window" 
  $param="Image Viewer"
/>
$p_img$
</$button>
\end

<<ViewImageButton "Motovun Jack.jpg">>

Because I usually do not like the parts of the content I’m viewing to shift positions, I’ll often have details pop up in a separate window, and then I can position all windows however suits me best at that moment.

2 Likes

Thank you @etardiff @TW_Tones @Charlie_Veniot for your replies and suggestions.

I will give a example of how I want this to look like.
This is how my note tiddlers usually look like - https://sidetabs-wiki.tiddlyhost.com/#Tweet-drmankad-WMLs-Original
I want it to look like this on pressing a viewtoolbar button -https://sidetabs-wiki.tiddlyhost.com/#Tweet-drmankad-WMLs

I have been using view template body cascade for sometime to show different templates for the tiddler body - Press on buttons as shown in the below images in my demo wiki tiddlers image image First button was adapted based on section editor and some of Charlie’s works. Second button was adapted from TW_Tones button he had shared before in this forum.

Can the solutions suggested above be adapted to work like those. I am going to experiment with all the solutions shared above today and tomorrow. Hope to get this done.

I was not understanding how to implement the above suggestions. So I tired an idea which came to my mind inspired by this discussion.

I created a viewtoolbar button to search and replace the images in the tiddler with a pop up reveal widget wrapped around the images.

\whitespace trim
\define imagepopup()
<$vars
    sp=""" """
	img1="\[img\["
	img2=".jpg\]\]"
    stateID={{{ [[$:/state/abc/]addsuffix{!!title}] }}}
    imgpop-prefix="""<$button popup=<<stateID>>>Images</$button><$reveal type="popup" state=<<stateID>> position="above">
<div class="tc-drop-down">"""
  imgpop-suffix="""</div></$reveal>"""
>
<$action-setfield $tiddler=<<currentTiddler>> text="{{{ [<myCur>get[text]search-replace:gi:regexp[\n],<sp>search-replace:gi:regexp<img1>,addprefix<imgpop-prefix><img1>search-replace:gi:regexp<img2>,<img2>addsuffix<imgpop-suffix>]] }}}">
</$vars>
\end
<$list filter="[all[current]has:field[note]]">
<$button actions=<<imagepopup>> tooltip="imagepopup" aria-label="image-popup"class=<<tv-config-toolbar-class>>>
{{$:/images/svg-icon/popup}}
</$button>
</$list>


But this doesn’t seem to work. What can be the issue ?. I haven’t created such a button before. So there must be many mistakes in the code I am using.
If this button can be made working, can it be extended to create a alternate view template cascade to hide the images in the tiddler and show only the reveal buttons to popup.

The basic anatomy of my notes tiddler is like shown below

text

text

[img[imagename.jpg]]

text

[img[imagename.jpg]]
[img[imagename.jpg]]

text

Images can be png or jpg format. I am showing only .jpg format here for demo purpose.

You can display the image links but not the images by placing \rules except image at the top of a tiddler. If this suits you could construct a method to toggle this on and off. Have a look to see if this would suit you.

\rules except image
[img[$:/favicon.ico]]