OK,
I found the solution!! Muahahahaha! I got my inspiration from the add tag
component of the editTemplate. I used a normal reveal with a drop down div
inside it.
I think I will stick myself with the capture message thing. Here is the
code that is not working as a widget but working inside the navigator
widget.
/*\
title: $:/plugins/danielo/encrypttiddler.js
type: application/javascript
module-type: widget
encrypttiddler widget
```
```
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
var Widget = require("$:/core/modules/widgets/widget.js").widget;
var encryptTiddlerWidget = function(parseTreeNode,options) {
this.initialise(parseTreeNode,options);
this.addEventListeners([
{type: "tw-encrypt-tiddler", handler: "handleEncryptevent"},
{type: "tw-decrypt-tiddler", handler: "handleDecryptevent"},
]);
};
/*
Inherit from the base widget class
*/
encryptTiddlerWidget.prototype = new Widget();
/*
Render this widget into the DOM
*/
encryptTiddlerWidget.prototype.render = function(parent,nextSibling) {
console.log("Render");
this.parentDomNode = parent;
this.computeAttributes();
this.execute();
this.renderChildren(parent,nextSibling);
};
/*
Compute the internal state of the widget
*/
encryptTiddlerWidget.prototype.execute = function() {
// Get attributes
// Construct the child widgets
console.log("Execute");
this.makeChildWidgets();
};
/*
Selectively refreshes the widget if needed. Returns true if the widget or
any of its children needed re-rendering
*/
encryptTiddlerWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes();
return this.refreshChildren(changedTiddlers);
};
encryptTiddlerWidget.prototype.handleEncryptevent = function(event){
var password = event.param || this.getStoredPassword();
var tiddler = this.wiki.getTiddler(event.tiddlerTitle);
this.wiki.addTiddler( new
$tw.Tiddler({title:"EncriptedDataaa",text:password }) )
if(tiddler && password){
var encryptedData=this.encryptFields(tiddler,password);
var fields={text:"!This is an encrypted Tiddler",
encrypted:encryptedData};
this.saveTiddler(tiddler,fields);
}
};
encryptTiddlerWidget.prototype.handleDecryptevent = function(event){
var password = event.param || this.getStoredPassword();
var tiddler = this.wiki.getTiddler(event.tiddlerTitle);
if(tiddler && password){
var fields=this.decryptFields(tiddler,password);
this.saveTiddler(tiddler,fields);
}
};
encryptTiddlerWidget.prototype.saveTiddler=function(tiddler,fields){
this.wiki.addTiddler( new
$tw.Tiddler(tiddler,this.clearNonStandardFields(tiddler), fields ) )
}
encryptTiddlerWidget.prototype.encryptFields = function (tiddler,password){
var jsonData=JSON.stringify(tiddler.fields);
return $tw.crypto.encrypt(jsonData,password);
};
encryptTiddlerWidget.prototype.decryptFields = function(tiddler,password){
var JSONfields =$tw.crypto.decrypt(tiddler.fields.encrypted,password);
return JSON.parse(JSONfields);
};
encryptTiddlerWidget.prototype.getStoredPassword = function(){
//not implemented
return false;
};
encryptTiddlerWidget.prototype.clearNonStandardFields =function(tiddler) {
var standardFieldNames = "title tags modified modifier created
creator".split(" ");
var clearFields = {};
for(var fieldName in tiddler.fields) {
if(standardFieldNames.indexOf(fieldName) === -1) {
clearFields[fieldName] = undefined;
}
}
return clearFields;
};
exports.encryptTiddler = encryptTiddlerWidget;
})();
Thank you very much.
El domingo, 6 de abril de 2014 11:44:41 UTC+2, Danielo Rodríguez escribió:
>
> Hello Stephan and Jeremy
>
> Thank you for your answers.
> I promise you that I defined a complete widget code with two different
> handlers.
>
> The evidence that my code is working is that I moved the code into the
> navigator widget. Obviously with changes and not the functions that are
> already defined in that widget. And it is working as expected.
>
> Or it was working despite of the detail that I can't use it on a pop-up
> correctly.
>
> I don't have Internet connection on my computer so I have to type from my
> phone. I will post more code as soon as possible. I wanted it to be a
> surprise :(
>
>
--
You received this message because you are subscribed to the Google Groups
"TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/tiddlywikidev.
For more options, visit https://groups.google.com/d/optout.