Hi. I was wondering if there was a plugin that will collapse the sidebar by default only if the screen’s under a certain width. I have a plugin that collapses the sidebar by default, but it doesn’t discriminate based on screen size. I’d like a plugin that does. Does anyone know of one like that? Thank you!
I assume your current plugin is using a tiddler tagged with $:/tags/StartupAction/Browser
containing something like this:
<$action-setfield $tiddler="$:/state/sidebar" text="no"/>
To make that startup code sensitive to screen size, you can use the value contained in $:/info/browser/screen/width
, like this:
<$let show={{{ [{$:/info/browser/screen/width}compare:integer:lt[...]then[no]else[yes]] }}}>
<$action-setfield $tiddler="$:/state/sidebar" text=<<show>>/>
where you enter the desired “certain width” (in pixels) in place of the “…”
enjoy,
-e
Ok, thank you. Here’s the URL of my startup module.
https://gardenstroll.tiddlyhost.com/#%24%3A%2F.tb%2Fmodules%2Fstartup%2Fhide-sidebar.js
Where exactly within that code would I place the code you gave me?
Wow… that code is 10 years old! At the time, using a javascript startup module was the only way to do what you want. However, there’s now a much easier way to do this without using any javascript code at all.
Delete your existing “hide-sidebar.js” tiddler, as it is no longer needed. Then, as described in my previous post, just create a tiddler (e.g., “HideSidebarStartupActions”), tagged with $:/tags/StartupAction/Browser
, containing:
<$let show={{{ [{$:/info/browser/screen/width}compare:integer:lt[...]then[no]else[yes]] }}}>
<$action-setfield $tiddler="$:/state/sidebar" text=<<show>>/>
Notes:
- The
$let
widget uses a “filtered transclusion” to check the screen width and set a variable (show
) to “yes” or “no”. - The
$action-setfield
widget sets the contents of the$:/state/sidebar
tiddler to the value of theshow
variable.
-e
Ah, ok. Well, thank you for helping me with that.