1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-30 21:39:57 +00:00
TiddlyWiki5/core/modules/widgets/action-deletetiddler.js

74 lines
1.7 KiB
JavaScript
Raw Normal View History

2014-11-06 18:23:48 +00:00
/*\
title: $:/core/modules/widgets/action-deletetiddler.js
type: application/javascript
module-type: widget
Action widget to delete a tiddler.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var Widget = require("$:/core/modules/widgets/widget.js").widget;
var DeleteTiddlerWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};
/*
Inherit from the base widget class
*/
DeleteTiddlerWidget.prototype = new Widget();
/*
Render this widget into the DOM
*/
DeleteTiddlerWidget.prototype.render = function(parent,nextSibling) {
this.computeAttributes();
this.execute();
};
/*
Compute the internal state of the widget
*/
DeleteTiddlerWidget.prototype.execute = function() {
2014-11-09 16:45:14 +00:00
this.actionFilter = this.getAttribute("$filter");
this.actionTiddler = this.getAttribute("$tiddler");
2014-11-06 18:23:48 +00:00
};
/*
Refresh the widget by ensuring our attributes are up to date
*/
DeleteTiddlerWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
2014-11-09 16:45:14 +00:00
if(changedAttributes["$filter"] || changedAttributes["$tiddler"]) {
2014-11-06 18:23:48 +00:00
this.refreshSelf();
return true;
}
return this.refreshChildren(changedTiddlers);
};
/*
Invoke the action associated with this widget
*/
DeleteTiddlerWidget.prototype.invokeAction = function(triggeringWidget,event) {
2014-11-09 16:53:33 +00:00
var tiddlers = [];
2014-11-09 16:45:14 +00:00
if(this.actionFilter) {
tiddlers = this.wiki.filterTiddlers(this.actionFilter,this);
}
if(this.actionTiddler) {
tiddlers.push(this.actionTiddler);
}
for(var t=0; t<tiddlers.length; t++) {
this.wiki.deleteTiddler(tiddlers[t]);
}
2014-11-06 18:23:48 +00:00
return true; // Action was invoked
};
exports["action-deletetiddler"] = DeleteTiddlerWidget;
})();