1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-09 11:29:58 +00:00
TiddlyWiki5/core/modules/widgets/action-setfield.js

69 lines
1.5 KiB
JavaScript
Raw Normal View History

2014-10-25 13:02:34 +00:00
/*\
title: $:/core/modules/widgets/action-setfield.js
type: application/javascript
module-type: widget
2014-10-30 12:47:58 +00:00
Action widget to set fields on a tiddler.
2014-10-25 13:02:34 +00:00
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var Widget = require("$:/core/modules/widgets/widget.js").widget;
var SetFieldWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};
/*
Inherit from the base widget class
*/
SetFieldWidget.prototype = new Widget();
/*
Render this widget into the DOM
*/
SetFieldWidget.prototype.render = function(parent,nextSibling) {
this.computeAttributes();
this.execute();
};
/*
Compute the internal state of the widget
*/
SetFieldWidget.prototype.execute = function() {
this.actionTiddler = this.getAttribute("$tiddler",this.getVariable("currentTiddler"));
};
/*
Refresh the widget by ensuring our attributes are up to date
*/
SetFieldWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
if(changedAttributes["$tiddler"]) {
this.refreshSelf();
return true;
}
return this.refreshChildren(changedTiddlers);
};
/*
Invoke the action associated with this widget
*/
SetFieldWidget.prototype.invokeAction = function(triggeringWidget,event) {
var self = this;
$tw.utils.each(this.attributes,function(attribute,name) {
if(name.charAt(0) !== "$") {
self.wiki.setText(self.actionTiddler,name,undefined,attribute);
}
});
return true; // Action was invoked
};
exports["action-setfield"] = SetFieldWidget;
})();