1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-01 07:36:18 +00:00
TiddlyWiki5/core/modules/widgets/encrypt.js

70 lines
1.7 KiB
JavaScript
Raw Normal View History

2013-10-24 12:10:32 +00:00
/*\
title: $:/core/modules/widgets/encrypt.js
2013-10-24 12:10:32 +00:00
type: application/javascript
module-type: widget
2013-10-24 12:10:32 +00:00
Encrypt widget
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var Widget = require("$:/core/modules/widgets/widget.js").widget;
2013-10-24 12:10:32 +00:00
var EncryptWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
};
/*
Inherit from the base widget class
*/
EncryptWidget.prototype = new Widget();
/*
Render this widget into the DOM
*/
EncryptWidget.prototype.render = function(parent,nextSibling) {
this.parentDomNode = parent;
this.computeAttributes();
this.execute();
var textNode = this.document.createTextNode(this.encryptedText);
parent.insertBefore(textNode,nextSibling);
this.domNodes.push(textNode);
};
/*
Compute the internal state of the widget
*/
EncryptWidget.prototype.execute = function() {
// Get parameters from our attributes
this.filter = this.getAttribute("filter","[!is[system]]");
// Encrypt the filtered tiddlers
var tiddlers = this.wiki.filterTiddlers(this.filter),
json = {},
self = this;
$tw.utils.each(tiddlers,function(title) {
var tiddler = self.wiki.getTiddler(title),
jsonTiddler = {};
for(var f in tiddler.fields) {
jsonTiddler[f] = tiddler.getFieldString(f);
}
json[title] = jsonTiddler;
});
this.encryptedText = $tw.utils.htmlEncode($tw.crypto.encrypt(JSON.stringify(json)));
};
/*
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
*/
EncryptWidget.prototype.refresh = function(changedTiddlers) {
// We don't need to worry about refreshing because the encrypt widget isn't for interactive use
return false;
2013-10-24 12:10:32 +00:00
};
exports.encrypt = EncryptWidget;
})();