From 9b4b9d4d8878b8646112de7b5a7b282f50a4d1cb Mon Sep 17 00:00:00 2001 From: Jermolene Date: Mon, 18 May 2015 22:15:23 +0100 Subject: [PATCH] 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. --- core/modules/widgets/action-sendmessage.js | 8 ++++- .../tiddlers/ActionSendMessageWidget.tid | 33 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 editions/prerelease/tiddlers/ActionSendMessageWidget.tid diff --git a/core/modules/widgets/action-sendmessage.js b/core/modules/widgets/action-sendmessage.js index cae061bb7..2f1b9cae4 100644 --- a/core/modules/widgets/action-sendmessage.js +++ b/core/modules/widgets/action-sendmessage.js @@ -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, diff --git a/editions/prerelease/tiddlers/ActionSendMessageWidget.tid b/editions/prerelease/tiddlers/ActionSendMessageWidget.tid new file mode 100644 index 000000000..cd08292e1 --- /dev/null +++ b/editions/prerelease/tiddlers/ActionSendMessageWidget.tid @@ -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=<>/> +Click me! +'/>