2015-04-26 11:33:56 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/widgets/vars.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: widget
|
|
|
|
|
2015-05-07 18:44:08 +00:00
|
|
|
This widget allows multiple variables to be set in one go:
|
2015-04-26 11:33:56 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
\define helloworld() Hello world!
|
|
|
|
<$vars greeting="Hi" me={{!!title}} sentence=<<helloworld>>>
|
|
|
|
<<greeting>>! I am <<me>> and I say: <<sentence>>
|
|
|
|
</$vars>
|
|
|
|
```
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var Widget = require("$:/core/modules/widgets/widget.js").widget;
|
|
|
|
|
|
|
|
var VarsWidget = function(parseTreeNode,options) {
|
2021-05-30 18:20:17 +00:00
|
|
|
// Initialise
|
2015-04-26 11:33:56 +00:00
|
|
|
this.initialise(parseTreeNode,options);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Inherit from the base widget class
|
|
|
|
*/
|
2021-10-30 10:42:22 +00:00
|
|
|
VarsWidget.prototype = new Widget();
|
2015-04-26 11:33:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Render this widget into the DOM
|
|
|
|
*/
|
|
|
|
VarsWidget.prototype.render = function(parent,nextSibling) {
|
|
|
|
this.parentDomNode = parent;
|
|
|
|
this.computeAttributes();
|
|
|
|
this.execute();
|
|
|
|
this.renderChildren(parent,nextSibling);
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Compute the internal state of the widget
|
|
|
|
*/
|
|
|
|
VarsWidget.prototype.execute = function() {
|
|
|
|
// Parse variables
|
|
|
|
var self = this;
|
|
|
|
$tw.utils.each(this.attributes,function(val,key) {
|
|
|
|
if(key.charAt(0) !== "$") {
|
|
|
|
self.setVariable(key,val);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Construct the child widgets
|
|
|
|
this.makeChildWidgets();
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Refresh the widget by ensuring our attributes are up to date
|
|
|
|
*/
|
|
|
|
VarsWidget.prototype.refresh = function(changedTiddlers) {
|
|
|
|
var changedAttributes = this.computeAttributes();
|
2021-10-30 10:42:22 +00:00
|
|
|
if($tw.utils.count(changedAttributes) > 0) {
|
2015-04-26 11:33:56 +00:00
|
|
|
this.refreshSelf();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this.refreshChildren(changedTiddlers);
|
|
|
|
};
|
|
|
|
|
|
|
|
exports["vars"] = VarsWidget;
|
|
|
|
|
|
|
|
})();
|