You could try putting in it's own tiddler:

tags: $:/tags/RawMarkup
type: application/javascript

<script>
.... code ...
</script>

Note that you have to save and reload before anything happens. I would not 
be surprised if something clashes with TW's rendering system, though.

On Saturday, April 17, 2021 at 7:38:41 AM UTC-7 Mohammad wrote:

> What is the simplest way to have the below JS code into a Tiddlywiki 
> plugin! It is not a macro, nor a widget!
>
> var ktooltips = document.querySelectorAll(".ktooltip");
> ktooltips.forEach(function(ktooltip, index){                // For each 
> ktooltip
>   ktooltip.addEventListener("mouseover", position_tooltip); // On hover, 
> launch the function below
> })
>
> function position_tooltip(){
>   // Get .ktooltiptext sibling
>   var tooltip = this.parentNode.querySelector(".ktooltiptext");
>   
>   // Get calculated ktooltip coordinates and size
>   var ktooltip_rect = this.getBoundingClientRect();
>
>   var tipX = ktooltip_rect.width + 5; // 5px on the right of the ktooltip
>   var tipY = -40;                     // 40px on the top of the ktooltip
>   // Position tooltip
>   tooltip.style.top = tipY + 'px';
>   tooltip.style.left = tipX + 'px';
>
>   // Get calculated tooltip coordinates and size
>   var tooltip_rect = tooltip.getBoundingClientRect();
>   // Corrections if out of window
>   if ((tooltip_rect.x + tooltip_rect.width) > window.innerWidth) // Out on 
> the right
>     tipX = -tooltip_rect.width - 5;  // Simulate a "right: tipX" position
>   if (tooltip_rect.y < 0)            // Out on the top
>     tipY = tipY - tooltip_rect.y;    // Align on the top
>
>   // Apply corrected position
>   tooltip.style.top = tipY + 'px';
>   tooltip.style.left = tipX + 'px';
> }
>
> This is a partial solution for repositioning the tooltips to prevent 
> screen overflow (off screen issue)!
>
>
> Best wishes
> Mohammad
>

-- 
You received this message because you are subscribed to the Google Groups 
"TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/15fb086c-650b-4f3e-affd-84067b7b0632n%40googlegroups.com.

Reply via email to