1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-07-05 03:33:27 +00:00
TiddlyWiki5/core/modules/widgets/parameters.js
jeremy@jermolene.com 21b10a225f Initial commit
Everything is draft.
2022-04-24 21:24:38 +01:00

75 lines
1.8 KiB
JavaScript

/*\
title: $:/core/modules/widgets/parameters.js
type: application/javascript
module-type: widget
Widget for definition of transclusion parameters
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var Widget = require("$:/core/modules/widgets/widget.js").widget,
UberTranscludeWidget = require("$:/core/modules/widgets/ubertransclude.js").ubertransclude;
var ParametersWidget = function(parseTreeNode,options) {
// Initialise
this.initialise(parseTreeNode,options);
};
/*
Inherit from the base widget class
*/
ParametersWidget.prototype = Object.create(Widget.prototype);
/*
Render this widget into the DOM
*/
ParametersWidget.prototype.render = function(parent,nextSibling) {
// Call the constructor
Widget.call(this);
this.parentDomNode = parent;
this.computeAttributes();
this.execute();
this.renderChildren(parent,nextSibling);
};
/*
Compute the internal state of the widget
*/
ParametersWidget.prototype.execute = function() {
var self = this;
// Find the parent transclusion
var transclusionWidget = this.parentWidget;
while(transclusionWidget && !(transclusionWidget instanceof UberTranscludeWidget)) {
transclusionWidget = transclusionWidget.parentWidget;
}
// Process each parameter
if(transclusionWidget) {
$tw.utils.each(this.attributes,function(value,name) {
self.setVariable(name,transclusionWidget.getTransclusionParameter(name,value));
});
}
// Construct the child widgets
this.makeChildWidgets();
};
/*
Refresh the widget by ensuring our attributes are up to date
*/
ParametersWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(Object.keys(changedAttributes).length) {
this.refreshSelf();
return true;
}
return this.refreshChildren(changedTiddlers);
};
exports.parameters = ParametersWidget;
})();