Skip to content

Instantly share code, notes, and snippets.

@saqimtiaz
Created March 11, 2021 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save saqimtiaz/4733d7a81784103d66610275a2160c93 to your computer and use it in GitHub Desktop.
Save saqimtiaz/4733d7a81784103d66610275a2160c93 to your computer and use it in GitHub Desktop.
Example action-widget for TW5
/*\
title: $:/core/modules/widgets/action-alert.js
type: application/javascript
module-type: widget
Action widget to log debug messages
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var Widget = require("$:/core/modules/widgets/widget.js").widget;
var AlertWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};
/*
Inherit from the base widget class
*/
AlertWidget.prototype = new Widget();
/*
Render this widget into the DOM
*/
AlertWidget.prototype.render = function(parent,nextSibling) {
this.computeAttributes();
this.execute();
};
AlertWidget.prototype.execute = function(){
this.message = this.getAttribute("message","");
}
/*
Refresh the widget by ensuring our attributes are up to date
*/
AlertWidget.prototype.refresh = function(changedTiddlers) {
this.refreshSelf();
return true;
};
/*
Invoke the action associated with this widget
*/
AlertWidget.prototype.invokeAction = function(triggeringWidget,event) {
alert(this.message);
return true; // Action was invoked
};
exports["action-alert"] = AlertWidget;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment