Is there a solution for triggering scrolling to to Top ( when you are not using the storyriver. )

205 views
Skip to first unread message

Jan

unread,
Apr 24, 2020, 4:32:38 PM4/24/20
to tiddlyWiki
Hi,
I made a Landing-Page which uses its own Pagetemplate and hides the
storyriver: https://szen.io/Grid/
The grid can be restructured by setting a tag to filter content.
When a user triggers this action, it would be great to scroll to the top
of the Webpage automatically.
How can I do this?

Best wishes Jan

Jan

unread,
Apr 25, 2020, 2:40:56 PM4/25/20
to TiddlyWiki
Hi,

I tried to build a widget, but so far it wont work.


/*\
title: $:/core/modules/macros/totop.js
type: application/javascript
module-type: macro
Macro that scrolls to the top
\*/

(function(){
   /*jslint node: true, browser: true */
   /*global $tw: false */
   "use strict";

/*
Information about this macro
*/
   exports.name = "totop";
   exports.params = [
   ];
/*
Run the macro
*/
   exports.run = function() {
   var totopp = window.scrollTo({ top: 0, behavior: 'smooth' });
   totopp;
}
})();

Birthe C

unread,
Apr 25, 2020, 2:55:37 PM4/25/20
to TiddlyWiki
Thomas Elmigers Linktotop

Mat

unread,
Apr 25, 2020, 2:57:20 PM4/25/20
to TiddlyWiki
Maybe

trigger
...
<$set name=top filter="""[list[$:/StoryList]first[]]""" >
<$action-navigate $to=<<top>>/>
</
$set>

<:-)

Saq Imtiaz

unread,
Apr 25, 2020, 7:31:04 PM4/25/20
to TiddlyWiki
You have written a macro, not a widget.

Look at one of the action widgets and write an action-totop widget, e.g:

The invokeAction method is where the logic goes for what happens when the widget is triggered.

Jan

unread,
Apr 26, 2020, 3:58:00 AM4/26/20
to tiddl...@googlegroups.com
Hi Birthe, hi  Mat,
my problem is, that the grid does not use storylist or storyriver, they are not even displayed. I could try the navigator widget...I am  not optimistic with that.
FIrst I will use Saq`s apporach.

Jan
--
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 tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/d9fff9ba-caca-4cc5-8819-b504a30a09c1%40googlegroups.com.

Jan

unread,
Apr 26, 2020, 4:05:13 AM4/26/20
to tiddl...@googlegroups.com
Hi Saq,
I think you got me...I do not really know what the difference is.
I think all the js I did so far was macros.
I finally should learn some of the basic concepts of programming js in TW ;-) Thanks for giving me a hint to start.

Do I need a widget or can I perform that action with a macro.

Jan
--
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 tiddlywiki+...@googlegroups.com.

Mat

unread,
Apr 26, 2020, 4:17:32 AM4/26/20
to TiddlyWiki
my problem is, that the grid does not use storylist or storyriver, they are not even displayed. I could try the navigator widget...I am  not optimistic with that.

But isn't it all in a tiddler, $:/Plugins/JJ/Grid/Gridlist  - ?
I think that this would work, which doesn't rely on a storylist:

<$action-navigate $to="$:/Plugins/JJ/Grid/Gridlist"/>


But, sure, since you know js then do that. I was just pointing to what I believe is a wikitext solution.

<:-)

Mat

unread,
Apr 26, 2020, 4:22:18 AM4/26/20
to TiddlyWiki
But isn't it all in a tiddler, $:/Plugins/JJ/Grid/Gridlist  - ?
I think that this would work, which doesn't rely on a storylist:

<$action-navigate $to="$:/Plugins/JJ/Grid/Gridlist"/>

OK, I just tried adding it in a button to one of your tiddlers and you're right it does NOT work.


<:-)

Saq Imtiaz

unread,
Apr 26, 2020, 4:32:11 AM4/26/20
to TiddlyWiki
In simple terms:

macros -> text substitution or defining a variable
widgets -> everything else

So you need a widget. And widgets that cause an action, rather than display something, need to be triggered, typically by a button, checkbox, select etc. These are called action widgets and the method that contains the logic for what happens when a widget is triggered is invokeAction.

Use this widget as a starting point:

/*\
type: application/javascript
module-type: widget


\*/

(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

var Widget = require("$:/core/modules/widgets/widget.js").widget;

var AddToHistoryWidget = function(parseTreeNode,options) {
   
this.initialise(parseTreeNode,options);
};

/*
Inherit from the base widget class
*/

AddToHistoryWidget.prototype = new Widget();

/*
Render this widget into the DOM
*/

AddToHistoryWidget.prototype.render = function(parent,nextSibling) {
   
this.computeAttributes();
   
this.execute();
};

/*
Compute the internal state of the widget
*/

AddToHistoryWidget.prototype.execute = function() {
   
this.historyTitle = this.getAttribute("$history",this.getVariable("tv-history-title"));
   
this.newTitle = this.getAttribute("$title");
};

/*
Refresh the widget by ensuring our attributes are up to date
*/

AddToHistoryWidget.prototype.refresh = function(changedTiddlers) {
   
var changedAttributes = this.computeAttributes();
   
if(changedAttributes["$historyTitle"] || changedAttributes["$title"]) {
       
this.refreshSelf();
       
return true;
   
}
   
return this.refreshChildren(changedTiddlers);
};

/*
Invoke the action associated with this widget
*/

AddToHistoryWidget.prototype.invokeAction = function(triggeringWidget,event) {
   
this.wiki.addToHistory(this.newTitle,{},this.historyTitle);
   
return true; // Action was invoked
};

exports
["action-addtohistory"] = AddToHistoryWidget;

})();

- execute() sets up the attributes via the parameters given to the widget, I suspect you don't need any.
- refresh() handles refreshing when the parameters have changed, probably also not needed. Jus call refreshSelf() and return true
- tweak invokeAction to perform the scroll.

Hope this helps.
Saq
To unsubscribe from this group and stop receiving emails from it, send an email to tiddl...@googlegroups.com.

Jeremy Ruston

unread,
Apr 26, 2020, 5:07:29 AM4/26/20
to TiddlyWiki
Hi Jan

Things like your grid view are intended to be implemented as custom storyviews. The storyview object is responsible for inserting and removing tiddlers from the story river, and for animating navigations to new tiddlers.

There are several examples of storyviews in the core repo:


In your case, you’d need some custom CSS to switch the story river to using your grid layout. You can scope that CSS by the way that the div.tc-page-container is given a class like tc-page-view-classic or tc-page-view-zoomin. Look at the classic storyview for an example of a navigation animation.

Best wishes

Jeremy.

To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/e8e9ec93-295d-48a1-931b-d92ec0e096ca%40googlegroups.com.

Jan

unread,
Apr 26, 2020, 6:28:19 AM4/26/20
to tiddl...@googlegroups.com
Hi Mat,
gridlist uses some functions of TW like the list- , reveal- and buttonwidget but inserts the content into its own pagetemplate.
That is why all the storyriver-related functions do not work.
It would be great to be able to navigate to ids or classes.

Jan
--
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 tiddlywiki+...@googlegroups.com.

Jan

unread,
Apr 26, 2020, 6:57:02 AM4/26/20
to tiddl...@googlegroups.com
Hi Saq, Hi Jeremy,
thank you two for this valuable help.
Saq, your explanationon the difference between macros and widgets is very helpfull. And Jeremy, I guess it is most usefull to turn the grid into a storyview. I realize that a lot of things I did in TW are workarounds for this because I did not understand that concept.
I guess I will have to do some learning.

best wishes Jan

PS: Sorry if this takes some time, my coding is squeezed between work and parental duties...

Julio Peña

unread,
Apr 26, 2020, 11:13:56 AM4/26/20
to TiddlyWiki
Hello Jan and all,

Maybe this can help or give you an idea? Take a look:


Regards,
Julio

Jan

unread,
Apr 26, 2020, 2:09:51 PM4/26/20
to tiddl...@googlegroups.com
Salut Julio,
nice site, but it is not so easy to find the key to your backstage-area to see how it is done...
As I said things are a little complicated because I do use another storyview.

Best wishes Jan
--
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 tiddlywiki+...@googlegroups.com.

Julio Peña

unread,
Apr 26, 2020, 2:54:23 PM4/26/20
to TiddlyWiki
Hello Jan

Oh yes your storyview is different...

Let me see...oh yes forgot about that one...
I believe if you use the alt+s it should open up the sidebar.
I found that out by accident...I don't even know if they are maintaining that site any longer,
but found it interesting relating to your dilemma.
I hope it helps some.

Hopefully you can get something out of it.


On Sunday, April 26, 2020 at 2:09:51 PM UTC-4, Jan wrote:
Salut Julio,
nice site, but it is not so easy to find the key to your backstage-area to see how it is done...
As I said things are a little complicated because I do use another storyview.

Best wishes Jan


Am 26.04.2020 um 17:13 schrieb Julio Peña:
Hello Jan and all,

Maybe this can help or give you an idea? Take a look:


Regards,
Julio
--
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 tiddl...@googlegroups.com.

Birthe C

unread,
Apr 26, 2020, 4:02:07 PM4/26/20
to TiddlyWiki
Det er Thomas Elmigers Linktotop-standalone. Desuden anvendes her et Font Awesome icon

Jan

unread,
Apr 26, 2020, 5:16:00 PM4/26/20
to tiddl...@googlegroups.com
Hi Jeremy,
 think it would be a good idea to turn the grid-plugin into a storyview to be compatible with the mechanisms of TW.
But I still do not really understand the storyview mechanism... My container is called .gridpage (off course I could easily switch it to tc-page-view-grid). I fear the whole way grid-items are constructed differs too much from the tiddler-display in the storyriver. In fact they are just buttons generated by a list of tiddlers. The idea is that they enable you to  choose different storylists and switch to the classic-view.

So I am still wondering whether I can adapt all this.
Best wishes Jan



Am 26.04.2020 um 11:07 schrieb Jeremy Ruston:

TonyM

unread,
Apr 26, 2020, 5:50:02 PM4/26/20
to TiddlyWiki
Jan

The original thread refers to top of page. If you simply want to move to the top of the page surely there exists a simple html method like hidden anchor at the topand a link to that.

If on the other hand you are referring to tiddler navigation it is different.

Have you looked throught the page and view template process in tiddlywiki. It should be quite simple to display the existing story in the part of the page you choose. If I am on track let me know and I will present some research notes on this.

Regards
Tony

Jan

unread,
Apr 26, 2020, 6:00:39 PM4/26/20
to tiddl...@googlegroups.com
Hi Saq,
many thanks for your gentle explanation.
Following your recipe I made what you can find below:
It does not crash the Wiki or show the red sign, which is already great for a first approach;-) , but so far the button says that the widget is not defined:
Can you give me another hint?

Best wishes
Jan

----------------------------------------------
Button:
<$button>scroll to top
<$action-scrolltotop/>
</$button>
----------------------------------------------
/*\
type: application/javascript
module-type: widget


\*/
(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

var Widget = require("$:/core/modules/widgets/widget.js").widget;

var ScrollToTopWidget = function(parseTreeNode,options) {
    this.initialise(parseTreeNode,options);
};

/*
Inherit from the base widget class
*/
ScrollToTopWidget.prototype = new Widget();

/*
Render this widget into the DOM
*/
ScrollToTopWidget.prototype.render = function(parent,nextSibling) {
    this.computeAttributes();
    this.execute();
};

/*
Compute the internal state of the widget
*/

/*
Refresh the widget by ensuring our attributes are up to date
*/
ScrollToTopWidget.prototype.refresh = refreshSelf() {
        return true;
    }
    return this.refreshChildren(changedTiddlers);
};

/*
Invoke the action associated with this widget
*/
ScrollToTopWidget.prototype.invokeAction = function(triggeringWidget,event) {
    window.scrollTo({ top: 0, behavior: 'smooth' });
    return true; // Action was invoked
};

exports["action-scrolltotop"] = ScrollToTopWidget;

})();

----------------------------------------------------------------------------------------
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/e8e9ec93-295d-48a1-931b-d92ec0e096ca%40googlegroups.com.

Jan

unread,
Apr 26, 2020, 6:08:52 PM4/26/20
to tiddl...@googlegroups.com
Hi Tony,
you are on track (and I would be willing to take a short cut...) my
problem is, the navigation shall be invoked together with other actions
when clicking a button.
It would be very practical to a widget scrolling to a desired id or
class that can be included into a button.

thanks for your help,
Jan

Saq Imtiaz

unread,
Apr 26, 2020, 6:19:38 PM4/26/20
to TiddlyWiki
Open the browser developer tools and the console. Do you see any error messages when loading your wiki? I would expect you to.

Your refresh method is not valid JavaScript. You can actually just remove it entirely. Remove the refresh method. It will inherit from the widget base class and that will be enough in this case. Make sure the tiddler has the correct type for JavaScript and module-type widget.

If it still doesn't work post your new code and the code for the button being used to trigger this. I'm currently not at a computer so that's the best I can do for now, hope that helps.

TonyM

unread,
Apr 26, 2020, 6:37:53 PM4/26/20
to TiddlyWiki
Jan,

I am not sure if I have your requirment clear but...

If you designed the page layout you can place an anchor at the top and use a html <a href tag that jumps to that anchor. No need to use widgets even macros. 

I just did test this on tiddlywiki.com

Try this in a tiddler tagged $:/tags/AboveStory
<h2 id="top">Top of page!</h2>

And this in a tiddler tagged $:/tags/BelowStory
<a href="#top">Go to top</a>
or
<a href="#top">{{$:/core/images/chevron-up}}</a>

Or place them somewhere on your own page layout

On tiddlywiki.com Open a pile of tiddlers and scroll to the bottom and click Top of page!
I believe their may be a way you can make the top of page anchor not visible.

Regards
Tony 

Jan

unread,
Apr 27, 2020, 6:09:55 AM4/27/20
to tiddl...@googlegroups.com
Hallo Saq,
heureka, it works.
For anyone who wants to use it, you can find it here:
https://szenio.de/Grid/#Scrolltotop

Thanks a lot Saq!

PS.:
Encouraged by this success it would be great generalize the function
enabeling the widget to scroll to an id that is given as a param.
Perhaps we manage that also.

Hubert

unread,
Apr 28, 2020, 4:15:47 AM4/28/20
to TiddlyWiki
Hello,

For anyone who wants to use it, you can find it here:

It works great, thanks for sharing Jan!

It would be nice to have this action implemented on opening a tiddler in the zoomin story view and as part of any other single tiddler mode(s) that could be introduced in the future. But that's a discussion for a different thread.

Thanks again!
Hubert

Peter Buyze

unread,
Apr 28, 2020, 5:47:48 AM4/28/20
to TiddlyWiki forum
Jan,

forgive my ignorance, but I dragged your plug-in to my wiki expecting to see that button somewhere, but I don't. What do I need to do?

--
Securely sent with Tutanota. Get your own encrypted, ad-free mailbox:


28 Apr 2020, 11:15 by hube...@gmail.com:
--
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 tiddlywiki+...@googlegroups.com.

Jan

unread,
Apr 28, 2020, 12:49:19 PM4/28/20
to tiddl...@googlegroups.com
Hi,
you need the $:/Plugins/JJ/Grid/scrolltotop.js,  a restart and a button invoking the widget like
<$button>scroll to top
<$action-scrolltotop/>
</$button>

Yours Jan

Jan

unread,
Apr 28, 2020, 12:52:43 PM4/28/20
to tiddl...@googlegroups.com
Hello,
for this behaviour, you can use the normal action-navigate widget and action-setfield setting the storyview to zooming in one button.

cheers Jan
--
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 tiddlywiki+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages