Slider and cookies

11 views
Skip to first unread message

Matt Flower

unread,
Sep 8, 2010, 5:02:41 AM9/8/10
to TiddlyWikiDev
I have a problem with the <slider> macro in TiddlyWiki 2.6.0. I could
probably fix it by overriding the macro, but as it is in the Core code
I don't really want to touch it so I am raising it here.

I use sliders to hide sections of content, and in my early prototypes
gave each slider a unique identity, which was a pain with over 1000
tiddlers and something like 3000 sliders.

The required behaviour is that the sliders always default to closed
and it all appeared to be working fine

I then realised that this was creating a very large number of cookie
entries and that on some tiddlers sliders were appearing in the open
position. So I modified the generation so that the identity was ""
thinking that without a name the state wouldn't be saved.

But I was wrong - what now happens is that if you open a single
slider, then all sliders on any tiddlers opened afterwards are
automatically opened, until you close one, then all sliders will be
closed. Basically all of my sliders are now sharing the same stored
value even though the name is a zero length string. The state is only
looked up when a tiddler is opened it is not that they all open and
close together.

Would it be possible to alter the TiddlyWiki code such that if the
identity for a slider (or anything else) is a zero length string, then
the value is not stored and recalled? If makes more sense to me as if
I wanted it to be saved I would name it.

Thanks

Matt

PMario

unread,
Sep 9, 2010, 4:08:00 AM9/9/10
to TiddlyWikiDev
copy this into a tiddler eg: SliderCookieHack and tag it systemConfig

//{{{
config.macros.slider.onClickSlider = function(ev)
{
var e = ev || window.event;
var n = this.nextSibling;
var cookie = n.getAttribute("cookie");
var isOpen = n.style.display != "none";
if(config.options.chkAnimate && anim && typeof Slider == "function")
anim.startAnimating(new Slider(n,!isOpen,null,"none"));
else
n.style.display = isOpen ? "none" : "block";
if (cookie != "") { //!!
config.options[cookie] = !isOpen;
saveOptionCookie(cookie);
} //!!
return false;
};
//}}}

If the list breaks the lines, you can load from TeamWork [1]
I did a short test. Please report if there are some side effects!!

[1] http://hoster.peermore.com/recipes/TeamWork/tiddlers.wiki#SliderCookieHack

PMario

unread,
Sep 9, 2010, 4:13:03 AM9/9/10
to TiddlyWikiDev
Since you have an empty cookie allready, it will be needed to delete
it.

On 9 Sep., 10:08, PMario <pmari...@gmail.com> wrote:
> copy this into a tiddler eg: SliderCookieHack and tag it systemConfig
>
> //{{{
> config.macros.slider.onClickSlider = function(ev)
> {
>   var e = ev || window.event;
>   var n = this.nextSibling;
>   var cookie = n.getAttribute("cookie");
>   var isOpen = n.style.display != "none";
>   if(config.options.chkAnimate && anim && typeof Slider == "function")
>     anim.startAnimating(new Slider(n,!isOpen,null,"none"));
>   else
>     n.style.display = isOpen ? "none" : "block";
>     if (cookie != "") {                                               //!!
>       config.options[cookie] = !isOpen;
>       saveOptionCookie(cookie);
>     }                                                           //!!
>     return false;};
>
> //}}}
>
> If the list breaks the lines, you can load from TeamWork [1]
> I did a short test. Please report if there are some side effects!!
>
> [1]http://hoster.peermore.com/recipes/TeamWork/tiddlers.wiki#SliderCooki...

Matt Flower

unread,
Sep 9, 2010, 5:01:50 AM9/9/10
to TiddlyWikiDev
That works great from my limited testing - if a slider is named then
the state is remembered, if it is not named, then the state is not
remembered and it always starts closed, which is exactly what is
needed.

You are also correct that copying from here loses all line breaks
while the TeamWork version saves as a pretty version.

Thanks very much.

Jeremy - is this little modification a candidate for TW core?

Matt

Jeremy Ruston

unread,
Sep 9, 2010, 6:01:50 AM9/9/10
to tiddly...@googlegroups.com
> Jeremy - is this little modification a candidate for TW core?

Yes, I think it is. I'd like to hear what Eric Shulman thinks, though,
as I believe he has looked at problems in this area below,

Best wishes

Jeremy


--
Jeremy Ruston
mailto:jer...@osmosoft.com
http://www.tiddlywiki.com

Reply all
Reply to author
Forward
0 new messages