How to make my javascript buttons in tiddlywiki?

134 views
Skip to first unread message

Siniy-Kit

unread,
Oct 25, 2019, 2:34:43 AM10/25/19
to TiddlyWiki
Hi! I don't understand how to make js buttons with parameter.
For example this button must put 2 values to local storage of my site

<$button>
<$action-sendmessage $message="tm-putdatatols"  param1={{!!modified}}  param2={{!!title}}/>
put data to LS
</$button>  

I understand, that I have to create  "putdatatols.js" tiddler and put my js script in it. Something like in $:/core/modules/utils/dom/notifier.js
but its code is very difficult for me.  If i have more simple example, I will be able to write my own script.
Help me please.

Siniy-Kit

unread,
Oct 25, 2019, 1:46:26 PM10/25/19
to TiddlyWiki
or may be somebody can write example of .js with
alert(param1+" "+param2);

TonyM

unread,
Oct 26, 2019, 6:58:06 AM10/26/19
to TiddlyWiki
I can't directly help you on this but the password widget does write to local storage as well as the local storage plugin.

Regards
Tony

Siniy-Kit

unread,
Oct 26, 2019, 12:59:42 PM10/26/19
to TiddlyWiki
Hi Tony! I want to understand how to write my own .js widgets and plugins. I need a simple example "Hello world" level.
It can be

<$button>
<$action-sendmessage $message="tm-alert"  param1={{!!modified}}  param2={{!!title}}/>
alert M+T
</$button>

........
alert(param1+" "+param2);
........

So, i want to make button with simple JavaScript alert  for two tiddler fields. This button will a good example for me and other beginners.



суббота, 26 октября 2019 г., 13:58:06 UTC+3 пользователь TonyM написал:

Mark S.

unread,
Oct 26, 2019, 2:26:44 PM10/26/19
to TiddlyWiki
I think what you want is a widget, which tends to be harder than a javascript macro.

Chris Hunt had a TW on this, but the page has disappeared. Fortunately, it's still
on the wayback machine:


HTH

Siniy-Kit

unread,
Oct 26, 2019, 4:25:33 PM10/26/19
to TiddlyWiki
Hi, Mark. Glad to see you! This theory is very very difficult for me. The is no easy examples in it. This manual is not for beginners. Long ago in this theme https://groups.google.com/d/msg/TiddlyWiki/bjludozbMqY/ja1YJa9g1k8J you write a very good example for me.  I write many simple scripts on it's base (but  still don't understand how it works:).

Now I need simple example, But it must work with "<$action-sendmessage $message= " when I click $button. I don't need to render the result in tiddler. I want to see alert of two fields values. 

суббота, 26 октября 2019 г., 21:26:44 UTC+3 пользователь Mark S. написал:

Mark S.

unread,
Oct 27, 2019, 12:27:32 AM10/27/19
to TiddlyWiki
Hi Siniy-Kit,

Well, this is the wrong way to do things, I'm sure. It over-rides a core tiddler, $:/core/modules/widgets/fieldmangler.js. So be
sure to have backups. I tried using the new sub-class technology, which could have avoided over-riding the core,
but the documentation didn't give any explanation of how to include eventListeners in the sub-class. So after more than an hour, this is the best I can do.

Drag and drop the attached into your TW, save and reload.  The sample tiddler "test alert system" has this text:

<$fieldmangler>

<$button>
<$action-sendmessage $message="tm-alert"  param1={{!!modified}}  param2={{!!title}}/>
alert M+T
</$button>
</$fieldmangler>

The fieldmangler has been modified to catch the new message, tm-alert. Just look for "tm-alert" and "handleAlertEvent" to
see what I did.

HTH
alert-message.json

Siniy-Kit

unread,
Oct 27, 2019, 2:58:37 AM10/27/19
to TiddlyWiki
Thank you Mark! This is exactly what I wanted. 


/* $:/core/modules/widgets/fieldmangler.js  */ 
/....../
{type: "tm-alert", handler: "handleAlertEvent"}
/....../
FieldManglerWidget.prototype.handleAlertEvent = function(event) {
       
var tiddler = this.wiki.getTiddler(this.mangleTitle),
                addition
= this.wiki.getModificationFields(),
                hadInvalidFieldName
= false ;
                addition
.title = this.mangleTitle;
       
if(typeof event.paramObject === "object") {
           
var myalerts = "" ;
               
for(var name in event.paramObject) {
                        myalerts
+= "" + name + ": " + event.paramObject[name] + ", " ;
               
}
           alert
(myalerts) ;
       
}
       
return true;
};
/....../


воскресенье, 27 октября 2019 г., 7:27:32 UTC+3 пользователь Mark S. написал:
Reply all
Reply to author
Forward
0 new messages