mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-07-17 09:24:30 +00:00
![jeremy@jermolene.com](/assets/img/avatar_default.png)
There are two big changes here: Replace the previous "ts-wrapper" mechanism, which we had been using to redefine custom widgets inside their definitions to prevent recursive calls. Now we've got the genesis widget we can instead control recursion through a new "$remappable" attribute that allows the custom widget mechanism to be skipped. We also extend the slot widget to allow a depth to be specified; it then reaches up by the indicated number of transclusion widgets to find the one from which it should retrieve the slot value.
80 lines
2.0 KiB
JavaScript
80 lines
2.0 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,
|
|
TranscludeWidget = require("$:/core/modules/widgets/transclude.js").transclude;
|
|
|
|
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 TranscludeWidget)) {
|
|
transclusionWidget = transclusionWidget.parentWidget;
|
|
}
|
|
// Process each parameter
|
|
if(transclusionWidget) {
|
|
$tw.utils.each($tw.utils.getOrderedAttributesFromParseTreeNode(self.parseTreeNode),function(attr,index) {
|
|
var name = attr.name,
|
|
value = transclusionWidget.getTransclusionParameter(name,index,self.getAttribute(name));
|
|
self.setVariable(name,value);
|
|
});
|
|
$tw.utils.each(transclusionWidget.getTransclusionMetaVariables(),function(value,name) {
|
|
self.setVariable(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;
|
|
|
|
})();
|