mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-11 18:00:26 +00:00
Update sendmessage widget to allow name/value parameters
Using `$name` and `$value` attributes allows more flexibility in how parameter names are specified, allowing parameter names that are not valid attribute names.
This commit is contained in:
parent
ccd0b30b5c
commit
9b4b9d4d88
@ -37,6 +37,8 @@ Compute the internal state of the widget
|
||||
SendMessageWidget.prototype.execute = function() {
|
||||
this.actionMessage = this.getAttribute("$message");
|
||||
this.actionParam = this.getAttribute("$param");
|
||||
this.actionName = this.getAttribute("$name");
|
||||
this.actionValue = this.getAttribute("$value","");
|
||||
};
|
||||
|
||||
/*
|
||||
@ -44,7 +46,7 @@ Refresh the widget by ensuring our attributes are up to date
|
||||
*/
|
||||
SendMessageWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(changedAttributes["$message"] || changedAttributes["$param"]) {
|
||||
if(Object.keys(changedAttributes).length) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
}
|
||||
@ -66,6 +68,10 @@ SendMessageWidget.prototype.invokeAction = function(triggeringWidget,event) {
|
||||
count++;
|
||||
}
|
||||
});
|
||||
// Add name/value pair if present
|
||||
if(this.actionName) {
|
||||
paramObject[this.actionName] = this.actionValue;
|
||||
}
|
||||
// Dispatch the message
|
||||
this.dispatchEvent({
|
||||
type: this.actionMessage,
|
||||
|
33
editions/prerelease/tiddlers/ActionSendMessageWidget.tid
Normal file
33
editions/prerelease/tiddlers/ActionSendMessageWidget.tid
Normal file
@ -0,0 +1,33 @@
|
||||
caption: action-sendmessage
|
||||
created: 20141008134309742
|
||||
modified: 20150518210909583
|
||||
tags: Widgets ActionWidgets
|
||||
title: ActionSendMessageWidget
|
||||
type: text/vnd.tiddlywiki
|
||||
|
||||
! Introduction
|
||||
|
||||
The ''action-sendmessage'' widget is an [[action widget|ActionWidgets]] that sends a [[message|WidgetMessages]] back up the widget tree. ActionWidgets are used within triggering widgets such as the ButtonWidget.
|
||||
|
||||
! Content and Attributes
|
||||
|
||||
The ''action-sendmessage'' widget is invisible. Any content within it is ignored.
|
||||
|
||||
|!Attribute |!Description |
|
||||
|$message |The message to send (eg, [[WidgetMessage: tm-new-tiddler]]) |
|
||||
|$param |Optional parameter string whose meaning is dependent on the message being sent |
|
||||
|$name |Optional name of additional parameter |
|
||||
|$value |Value for optional parameter whose name is specified in `$name` |
|
||||
|//{any attributes not starting with $}// |Multiple additional, optional named parameters that are attached to the message |
|
||||
|
||||
! Examples
|
||||
|
||||
Here is an example of button that displays both a notification and a wizard, and creates a new tiddler with tags and text:
|
||||
|
||||
<$macrocall $name='wikitext-example-without-html'
|
||||
src='<$button>
|
||||
<$action-sendmessage $message="tm-modal" $param="SampleWizard"/>
|
||||
<$action-sendmessage $message="tm-notify" $param="SampleNotification"/>
|
||||
<$action-sendmessage $message="tm-new-tiddler" title="This is newly created tiddler" tags="OneTag [[Another Tag]]" text=<<now "Today is DDth, MMM YYYY">>/>
|
||||
Click me!
|
||||
</$button>'/>
|
Loading…
Reference in New Issue
Block a user