Improve the format of widget message parameters

In 5.1.3 we introduced the idea that the `event.param` variable could
optionally be a hashmap, allowing multiple values to be passed with the
message.

This change moves the hashmap to a separate `event.paramObject`
variable, allowing us to pass both a hashmap and a param string.
print-window-tiddler
Jermolene 2014-11-07 14:52:32 +00:00
rodzic b851fe1800
commit d93c19daaa
2 zmienionych plików z 41 dodań i 16 usunięć

Wyświetl plik

@ -55,25 +55,19 @@ SendMessageWidget.prototype.refresh = function(changedTiddlers) {
Invoke the action associated with this widget
*/
SendMessageWidget.prototype.invokeAction = function(triggeringWidget,event) {
// Get the parameter
// Get the string parameter
var param = this.actionParam;
// If the parameter is missing then we'll assemble the attributes as a hashmap
if(!param) {
param = Object.create(null);
var count = 0;
$tw.utils.each(this.attributes,function(attribute,name) {
if(name.charAt(0) !== "$") {
param[name] = attribute;
count++;
}
});
// Revert to an empty parameter if no values were found
if(!count) {
param = undefined;
// Assemble the attributes as a hashmap
var paramObject = Object.create(null);
var count = 0;
$tw.utils.each(this.attributes,function(attribute,name) {
if(name.charAt(0) !== "$") {
paramObject[name] = attribute;
count++;
}
}
});
// Dispatch the message
this.dispatchEvent({type: this.actionMessage, param: param, tiddlerTitle: this.getVariable("currentTiddler")});
this.dispatchEvent({type: this.actionMessage, param: param, paramObject: paramObject, tiddlerTitle: this.getVariable("currentTiddler")});
return true; // Action was invoked
};

Wyświetl plik

@ -0,0 +1,31 @@
caption: action-sendmessage
created: 20141008134309742
modified: 20141107132122081
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 |
|//{any attributes not starting with $}// |Multiple additional 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>'/>